React Native Paper Avatar Text Example

May 07, 2021 . Admin

Hi Guys,

In this post, I will learn you how to create paper Avatar text in react native. You can easily create paper Avatar text in react native. First i will import stylesheet namespace from react-native-paper, after I will make paper Avatar text using in react native.

Here, I will give you full example for simply display paper Avatar text using react native as bellow.

Step 1 - Create project

In the first step Run the following command for create project.

expo init text 
Step 2 - Install Package

In the step,I will install npm i react-native-paper package.

npm i react-native-paper
Step 3 - App.js

In this step, You will open App.js file and put the code.

import React, { useState } from "react";
import { FlatList, Text, View, RefreshControl,SafeAreaView, ScrollView,StyleSheet } from 'react-native';
import { Provider ,Appbar, Avatar } from 'react-native-paper';

const MyComponent = () => {

  const [isEnabled, setIsEnabled] = useState(false);
  const toggleSwitch = () => setIsEnabled(previousState => !previousState);

  const _goBack = () => console.log('Went back');

  const _handleSearch = () => console.log('Searching');

  const _handleMore = () => console.log('Shown more');

  return (
    <Provider>
    <Appbar.Header style={styles.header}>
      <Appbar.BackAction onPress={_goBack} />
      <Appbar.Content title="Mywebtuts" subtitle="Subtitle" />
      <Appbar.Action icon="magnify" onPress={_handleSearch} />
      <Appbar.Action icon="dots-vertical" onPress={_handleMore} />
    </Appbar.Header>
      <View style={styles.mainbox}>
          <Avatar.Text size={50} label="LD" style={styles.avstyle} />
          <Avatar.Text size={75} label="Xd" />
      </View>
    </Provider>
  );
};


const styles = StyleSheet.create({
  title:{
    margin: 10,
    fontSize: 15,
    fontSize: 35
  },
  mainbox:{
    textAlign:'center',
    flex: 0.8,
    alignItems: "center",
    justifyContent: "center",
  },
  textstyle:{
    fontSize: 18,
    marginBottom: 20,
  },
  avstyle:{
    marginBottom: 20,
    backgroundColor: '#00f0ff',
  }
});
export default MyComponent;
Step 4 - Run project

In the last step run your project using bellow command.

npm start
Output
It will help you...
#React Native