Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export individual components #4

Open
mrousavy opened this issue Oct 1, 2020 · 4 comments
Open

Export individual components #4

mrousavy opened this issue Oct 1, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@mrousavy
Copy link
Contributor

mrousavy commented Oct 1, 2020

Hi! I really like the library, looks very friendly!

I'd like to implement a "Create your Avatar" screen, similar to the one Snapchat (BitMoji) has. The user can scroll through available parts, and pick the ones that he wants. Unfortunately, the individual components (hairstyles, shirts, etc) are only exported in maps, and I'm not sure how I could render them in a FlatList/ScrollView.

I've tried the following:

const mouths = Object.keys(mouthsMap) as (keyof typeof mouthsMap)[];

function SomeComponentFromMyApp(props) {
    // ...
    const renderMouth = useCallback(({ item: mouthType }: ListRenderItemInfo<keyof typeof mouthsMap>): React.ReactElement | null => {
        const Comp = mouthsMap[mouthType];
        return <Comp />;
    }, []);
    // ...

    return <FlatList data={mouths} renderItem={renderMouth} />;
}

But that just renders nothing. I assume I have to wrap the <Comp/> inside some parent View, such as a <View> or <Svg>, since the Mouth renderer actually returns a Fragment of Svg components. Could you point me in the right direction on how I could render those correctly?

Thanks!

@mrousavy mrousavy closed this as completed Oct 1, 2020
@mrousavy mrousavy reopened this Oct 1, 2020
@felipecespedes felipecespedes added the enhancement New feature or request label Oct 1, 2020
@felipecespedes
Copy link
Owner

felipecespedes commented Oct 3, 2020

You need to wrap the component inside a <View> and a <Svg>
Something like this will work:

// imports
import { mouthsMap } from 'react-native-bigheads';
import { Svg } from 'react-native-svg';

// render
<View style={{ width: 500, height: 500 }}>
  <Svg viewBox="0 0 1000 990">
    <mouthsMap.lips lipColor="green" />
  </Svg>
</View>

Remember that some components receive their own properties, unfortunately that is not documented.

@felipecespedes
Copy link
Owner

I like the idea of exporting individual components in a better and friendly way, so I'm going to keep this issue open.

@felipecespedes felipecespedes pinned this issue Oct 3, 2020
@loangodard
Copy link

loangodard commented Jan 5, 2021

Hi, i'm also trying to get all components one by one to create an avatar customizer...

I'm in trouble because this is working

<View style={caracStyle}> <Svg viewBox="0 0 1000 990"> {React.createElement(accessoryMap[type], null)} </Svg> </View>

But for some other components like hairMap or bodyMap, it is not working
javascript <View style={caracStyle}> <Svg viewBox="0 0 1000 990"> <hairMap.bun hairColor={"blonde"}/> </Svg> </View>

Many thanks for this nice project !

@pierroo
Copy link

pierroo commented Apr 13, 2023

Here as well, I might be late to the party, but did anyone find a solution to have those separated components? @loangodard @felipecespedes ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants