React-native-router-flux: How to create Tabbar with icon&Text

Created on 29 Sep 2017  路  12Comments  路  Source: aksonov/react-native-router-flux

I search in doc, i don't know how to create tabbar with icon&Text use react-native-router-flux.
Please help me!!!!
Thank you very much!!!!

Version

Tell us which versions you are using:

  • react-native-router-flux v4.?.? (v3 is not supported)
  • react-native v0.4.8

Most helpful comment

It seems the icon prop uses the v3 callback as explained here. Except now, the selected prop is now focused. Here's how I got it working:

<Tabs
    showLabel={false}
    lazy={true}
    tabStyle={styles.tab}
    tabBarStyle={styles.tabs}
    labelStyle={styles.label}
    swipeEnabled={false}
>
    <Scene
        hideNavBar
        key={MY_WATER_KEY}
        component={MyWater}
        icon={({ focused }) => (
            <Icon
                size={iconSize}
                color={focused ? activeIconColor : iconColor}
                name={`drop2`}
                text={`My Water`}
                textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
            />
        )}
    />
    <Scene
        hideNavBar
        key={INBOX_KEY}
        component={Inbox}
        icon={({ focused }) => (
            <Icon
                size={iconSize}
                color={focused ? activeIconColor : iconColor}
                textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
                name={`envelope`}
                text={`Messages`}
            />
        )}
    />
    <Scene
        hideNavBar
        key={MY_ACCOUNT_KEY}
        component={MyAccount}
        icon={({ focused }) => (
            <Icon
                size={iconSize}
                color={focused ? activeIconColor : iconColor}
                textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
                name={`home3`}
                text={`My Account`}
            />
        )}
    />
</Tabs>

image

By the way, I wanted more control over the labels so I passed the text into my Icon component and render it there and use the showLabel={false} on the Tabs component.

All 12 comments

I also want to look at a clean example of just tabbed navigation.

this can be done using icon and tabBarLabel component on an individual Tabbed Scene.

<Tabs>
  <Scene
  tabBarLabel={'Something'}
  icon={IconComponent}
  />
</Tabs>

thank you very much!

Just a heads up. This seems really weird, and might be a bug, but you can't pass a rendered component to the icon prop:

<Scene
    hideNavBar
    key={MY_ACCOUNT_KEY}
    tabBarLabel={`My Account`}
    component={MyAccount}
    icon={<Icon
            size={iconSize}
            color={iconColor}
            name={`home3`}
        />}
/>

You get this error:
image

The way around it is to wrap the component in a function:

<Scene
    hideNavBar
    key={MY_ACCOUNT_KEY}
    tabBarLabel={`My Account`}
    component={MyAccount}
    icon={() => (
        <Icon
            size={iconSize}
            color={iconColor}
            name={`home3`}
        />
    )}
/>

It seems the icon prop uses the v3 callback as explained here. Except now, the selected prop is now focused. Here's how I got it working:

<Tabs
    showLabel={false}
    lazy={true}
    tabStyle={styles.tab}
    tabBarStyle={styles.tabs}
    labelStyle={styles.label}
    swipeEnabled={false}
>
    <Scene
        hideNavBar
        key={MY_WATER_KEY}
        component={MyWater}
        icon={({ focused }) => (
            <Icon
                size={iconSize}
                color={focused ? activeIconColor : iconColor}
                name={`drop2`}
                text={`My Water`}
                textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
            />
        )}
    />
    <Scene
        hideNavBar
        key={INBOX_KEY}
        component={Inbox}
        icon={({ focused }) => (
            <Icon
                size={iconSize}
                color={focused ? activeIconColor : iconColor}
                textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
                name={`envelope`}
                text={`Messages`}
            />
        )}
    />
    <Scene
        hideNavBar
        key={MY_ACCOUNT_KEY}
        component={MyAccount}
        icon={({ focused }) => (
            <Icon
                size={iconSize}
                color={focused ? activeIconColor : iconColor}
                textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
                name={`home3`}
                text={`My Account`}
            />
        )}
    />
</Tabs>

image

By the way, I wanted more control over the labels so I passed the text into my Icon component and render it there and use the showLabel={false} on the Tabs component.

@dwilt Thanks for the example. Just had a small question. How do I change the scene being rendered based on the tab click ? Just usual Action.sceneKey() ?

Thanks.

Sorry forgot we had access to the component prop! 馃 Thanks again!

@ghoshabhi yep

Does this still work? My text label is not showing...

icon={({ focused }) => (
size={iconSize}
color={focused ? activeIconColor : iconColor}
textStyle={focused ? [styles.label, styles.activeLabel] : styles.label}
name={home3}
text={My Account}
/>
)}

@wincod75 any luck after a day? I'm just running into this issue as well and cannot get anything to display

@uncvrd No luck, can't get anything to display either.

@wincod75 ugh well keep me posted if you do. I'll keep searching

@uncvrd @wincod75

const TabIcon = (props) => {
    console.log({...props});
    return (
        <View>
            <Text>{JSON.stringify(props.focused)}</Text>
        </View>
    )
};


<Scene icon={TabIcon} ... />
Was this page helpful?
0 / 5 - 0 ratings

Related issues

xnog picture xnog  路  3Comments

willmcclellan picture willmcclellan  路  3Comments

vinayr picture vinayr  路  3Comments

jgibbons picture jgibbons  路  3Comments

kirankalyan5 picture kirankalyan5  路  3Comments