react-native-router-flux icon indicating copy to clipboard operation
react-native-router-flux copied to clipboard

tabBarComponent No Documentation

Open baxri opened this issue 6 years ago • 3 comments

LACK OF DOCUMENTATION

tabBarComponent

Can anyone provide normal documentation how to use this tabBarComponent to display custom tabs, with active tab index.

I check documentation but there is no any kind of API to check what I am receiving in props, how to show active Tab abd stuff like this.

I am using react-native-router-flux v4

and checked this API docs

API Docs

baxri avatar Mar 24 '19 16:03 baxri

Just implemented a custom tab bar component myself. After going through the docs and issues, here's a snippet that I'm using:

<Tabs
      key="tabbar"
      tabBarComponent={CustomTabBar}
    >
    <Scene key="tab1" component={TabOne} title="Tab1"/>
    <Scene key="tab2" component={TabTwo} title="Tab2"/>
</Tabs>
import React from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Actions } from 'react-native-router-flux';

export default class CustomTabBar extends React.Component {
  render() {
    const { state } = this.props.navigation;
    const activeTabIndex = state.index;

    return (
      <View>
        {
          state.routes.map(element => (
            <TouchableOpacity key={element.key} onPress={() => Actions[element.key]()}>
              <Text>{element.key.toUpperCase()}</Text>
            </TouchableOpacity>
          ))
        }
      </View>
    );
  }
}

Hope this helps!

joshjeong avatar May 23 '19 22:05 joshjeong

This answer in StackOverflow really helped me with my custom tabbar through tabBarComponent: https://stackoverflow.com/questions/54872145/programatically-hiding-and-showing-individual-tabs-in-react-native-router-flux-t

I wanted to dynamically show/hide the tabs depending on the user, and with that example I was able to achieve it.

a-fortunato avatar Jul 10 '19 08:07 a-fortunato

state.routes.map(element => (
            <TouchableOpacity key={element.key} onPress={() => Actions[element.key]()}>
              <Text>{element.key.toUpperCase()}</Text>
            </TouchableOpacity>
          ))

This shows the activeTabIndex of the last active tab

roots-ai avatar Apr 11 '22 07:04 roots-ai