1.0.7 • Published 21 days ago

rn-customize-avatar v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
21 days ago

Installation

Since the library is a JS-based solution, to install the latest version of rn-customize-avatar:

npm install --save rn-customize-avatar @shopify/react-native-skia

Alert

You have to install any one of them npm according to your need.

npm i @dicebear/avataaars
npm i @dicebear/adventurer-neutral
npm i @dicebear/bigEars
npm i @dicebear/lorelei
npm i @dicebear/micah
npm i @dicebear/croodles
npm i @dicebear/Notionists

Rest Avatar Coming Soon... ♥️

Try it out

You can try out the DiceBear website to get a tease of the functionalities in this lib.

Basic Usage

The Basic use of Avataars container. That's Simple 😬

import React from 'react';
import { View } from 'react-native';
import { Avataars } from 'rn-customize-avatar/avataaars';

function App() {
  return (
    <View style={{ flex: 1 }}>
      <Avataars backgroundColor="grey" />
    </View>
  );
}

Common Props in all Avatars

PropertyDefaultOptionalDescription
backgroundColorredYesUse to Change the Color of Avatar Background Container
svgWidth280YessvgWidth increase the width of Avatar
svgHeight280YessvgHeight increase the height of Avatar
defaultAvatarCustomAvatarYesIf you want to change the look to default avatar use can use this props
listBgColorgreyYeslistBgColor Change the background color of list
cancelBtnStyleStyleYesChange the style of cancel Button cancelBtnStyle time
doneBtnStyleStyleYesdoneBtnStyle Change the style of done Button
chipStyleStyleYesUse to Change the container Style of slider option itemchipStyle
chipTextTextStyleYesUse this to change the style of text inside option chip container
onDone(base64) => {}YesThe onDone _prop is a callback it is used to get the final avatar in the form of base64
onCancel() => {}YesThe onCancel is a callback use to cancel go back
flatListPropsFlatListStyleYesApply a custom style object in Flatlist

Avataaars

These are some props that are related to Avataaars

PropsUsage
skinTonColorListAdd custom colors in the skinTonColorList
hairColorListAdd custom colors in the hairColorList
backgroundColorListAdd custom colors in the backgroundColorList
accessoriesColorListAdd custom colors in the accessoriesColorList
facialHairColorListAdd custom colors in the facialHairColorList
hatColorListAdd custom colors in the hatColorList
clothColorListAdd custom colors in the clothColorList

Example

color should be add without # otherwise it's not visible in the list

import React from 'react';
import { View } from 'react-native';
import { Avataars } from 'rn-customize-avatar/avataars';

function App() {
  return (
    <View style={{ flex: 1 }}>
      <Avataars backgroundColor="grey" hairColorList={['433333', '000000']} />
    </View>
  );
}

Adventurer Neutral

These are some props that are related to Adventurer Neutral

PropsUsage
backgroundColorListAdd custom colors in the backgroundColorList

Example

color should be add without # otherwise it's not visible in the list

import React from 'react';
import { View } from 'react-native';
import { AdventureNeutral } from 'rn-customize-avatar/adventureNeutral';

function App() {
  return (
    <View style={{ flex: 1 }}>
      <AdventureNeutral backgroundColor="grey" backgroundColorList={['433333', '000000']} />
    </View>
  );
}

Rest of the Avatars have a similar props used to pass the custom colors in the list (If you find any issue in it please comment)

Coming to Advance Options

If you want to make your own screen with different ui you can. 😎

Suppose you have to change the UI of Avataars Component. You can export the following functions to get the SVG's

These are some functions that are related to Avataar

FunctionsUsage
createOwnAvatarreturn the SkSVG, by props you can change the style of avatar
getListOfOptionsreturn the Array<string> list of category
getSkinTonreturn Array<string> list of default colors
getMouthSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of SVG's and value
getEyesSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of eyes
getClothingSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of clothes
getClothingGraphicsSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of clothing graphics
getAccessoriesSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of accessories
etc.Please check other props it's same as following pros with same return type just return different SVG's according with there name.♥️

These are some functions that are related to BigEars

FunctionsUsage
createOwnAvatarreturn the SkSVG, by props you can change the style of BigEars
getListOfOptionsreturn the Array<string> list of category
getSkinTonreturn Array<string> list of default colors
getMouthSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of SVG's and value
getEyesSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of eyes
getEarsSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of ears
getFaceSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of faces graphics
getSideBurnSvgreturn Array<Item> Item is basically object includes SkSVG and value use to get the list of side Burn
etc.Please check other props it's same as following pros with same return type just return different SVG's according with there name.♥️

Rest of the avatar's have a similar type of function you can check in the codebase. If you are facing any issue please contact me in my email mention in the contact section. ✌️

Example

import React from "react";
import { View } from "react-native";
import {getListOfOptions, getSkinTon,getEyesSvg } from 'rn-customize-avatar/bigEars';

useEffect(() => {
 const options =  getListOfOptions() // synchronous function ♥️
 const eyes =  getEyesSvg() // same synchronous function ♥️  return Array<Item>
 console.log("options",options)
 console.log("eyes",eyes)

},[])

function App() {
  return (
    <View style={{flex : 1}}>
      <SkSvgView  svg={createOwnAvatar({})}>
    </View>
  );
}

IMPORTANT

What is the use case of SKSVG ?

SkSVG is like a svg basically generated by Skia. To render the SKSVG you can use the following component. I have create a custom component by this you can render SkSVG.

Example

import React from "react";
import { View } from "react-native";
import {SkSvgView} from 'rn-customize-avatar';

function App() {
  return (
    <View style={{flex : 1}}>
      <SkSvgView  svg={createOwnAvatar({})}>
    </View>
  );
}

Donation

If this project helped you to reduce your developing time, you can give me a cup of coffee :) ♥️

paypal

Documentation

More details and use cases coming soon.

:e-mail: Contact

If you have any question, please email vishumadaan25@gmail.com.

License

MIT