React Native Paper Avatar Icon Example

May 06, 2021 . Admin

Hi Guys,

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

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

Step 1 - Create project

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

expo init PaperAvatarIcon 
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 { Text, StyleSheet,TextInput,View ,Switch } 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}>
        <Text style={styles.textstyle}>React Native Paper Avatar Icon Example</Text>
          <Avatar.Icon size={70} icon="calendar" style={styles.iconstyle} />
          <Avatar.Icon size={70} icon="folder" style={styles.iconstyle} />
      </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,
  },
  iconstyle:{
    marginBottom: 20,
    backgroundColor: '#ff0000',
  }
});
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