1.0.3 • Published 4 years ago

rn-avatar v1.0.3

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

React-Native Avatar

React Native Avatars can be used to represent people in a graphical way with support for falling back to using the user's initials on a colored background as the avatar if valid source is not present.

Installation


npm install --save rn-avatar
npm install --save react-native-vector-icons
react-native link react-native-vector-icons

Props

PropTypeDefaultDescription
activeOpacitynumber0.2opacity when pressed
avatarStyleobject (style)noneAvatar image style
containerStyleobject (style)noneOuter container style
editButton{ name: 'mode-edit', type: 'material', color: '#fff', underlayColor: '#000' }noneVector Icon props to be user for edit button
iconobject {name: string, color: string, size: number, type: string }(default is Material, or choose from supported icon setsDisplays an icon as the main content of the Avatar. Cannot be used alongside title. When used with the source prop it will be used as the placeholder.
iconStyleobject (style)nonestyling for icon component
imagePropsobjectnoneOptional properties to pass to the avatar e.g "resizeMode"
onEditPressfunctionnoneCallback function when pressing on the edit button
onLongPressfunctionnoneCallback function when long pressing component
onPressfunctionnoneCallback function when pressing the component
overlayContainerStyleobject (style)noneStyle for the view outside image or icon
placeholderStyleobject (style){ backgroundColor: '#BDBDBD' }Adds style to the placeholder wrapper
roundedbooleanfalseMakes the avatar circular
sizestring or numberSizes.SMALLSize of the avatar, choose from supported size sets or give any number
showEditButtonbooleanfalseShows an edit button over the avatar
sourceobject (style)noneImage source
titlestringnoneTo render initials of title inside placeholder
titleStyleobject (style)noneStyle for the title
renderPlaceholderContentfunctiondefault titleCustom placeholder element in place of title
ComponentfunctionTouchableHighlightComponent for enclosing element
ImageComponentReact component or elementImageCustom ImageComponent for Avatar

Avatar Size Set

import { Sizes } from 'rn-avatar';

SizeDescription
Sizes.EXTRA_SMALLextra small size avatar
Sizes.SMALLreturn small size avatar
Sizes.MEDIUMreturn medium size avatar
Sizes.LARGEreturn large size avatar
Sizes.EXTRA_LARGEreturn extra large size avatar

Icon Set

import { IconTypes } from 'rn-avatar';

  1. IconTypes.AntDesign
  2. IconTypes.Entypo
  3. IconTypes.EvilIcon
  4. IconTypes.Feather
  5. IconTypes.FontAwesome
  6. IconTypes.FontAwesome5
  7. IconTypes.Foundation
  8. IconTypes.Ionicon
  9. IconTypes.Material
  10. IconTypes.MaterialCommunity
  11. IconTypes.Octicon
  12. IconTypes.SimpleLineIcon
  13. IconTypes.Zocial

Example

import Avatar, { IconTypes, Sizes } from 'rn-avatar';

class Example extends PureComponent {
  render() {
    return (
      <View style={styles.container}>
        <Avatar
          size={Sizes.SMALL}
          title='Ava Andrew'
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          size={Sizes.MEDIUM}
          source={require('../assets/images/logo.png')}
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          size={Sizes.MEDIUM}
          title='Lucifer J'
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          icon={{
            name: 'home', type: IconTypes.Material,
          }}
          size={Sizes.LARGE}
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          icon={{
            name: 'user', type: IconTypes.FontAwesome,
          }}
          size={120}
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          rounded
          size={Sizes.EXTRA_LARGE}
          title='Lucy Watson'
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          size={Sizes.EXTRA_LARGE}
          source={{ uri: 'http://www.sarkarinaukrisearch.in/wp-content/uploads/2019/03/Beautiful-Wallpaper-1.jpg' }}
          title='Lucy Smith'
          containerStyle={{ margin: 10 }}
        />
        <Avatar
          rounded
          showEditButton
          size={Sizes.EXTRA_LARGE}
          source={{ uri: 'https://cdn.pixabay.com/photo/2018/10/30/16/06/water-lily-3784022__340.jpg' }}
          title='Grace'
          containerStyle={{ margin: 10 }}
          onEditPress={()=> console.log('edit button pressed')}
          onLongPress={()=> console.log('component long pressed')}
          onPress={()=> console.log('component pressed')}
          editButton={{
            name: 'edit', type: IconTypes.Entypo
          }}
        />
      </View>
    );
  }
}

License


Licensed under the MIT