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

How add button on tab bar to open #3041

Closed
adaerodriguez opened this issue May 18, 2018 · 4 comments
Closed

How add button on tab bar to open #3041

adaerodriguez opened this issue May 18, 2018 · 4 comments

Comments

@adaerodriguez
Copy link

adaerodriguez commented May 18, 2018

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.0-beta.27 (v3 is not supported)
  • react-native v0.55.3

Expected behaviour

I want to open drawer with a button on the right of my bottom tabbar

Actual behaviour

Currently this is my Router code:

<Drawer
          key="drawer"
          contentComponent={DrawerContainer}
          // drawerIcon={dr}
          drawerWidth={260}
          drawerPosition={'right'}
          drawer={true}
          hideNavBar
          drawerImage={ () => <Image source={require('./resources/icons/ic_add.png')} style={{ width: 60, height: 60, tintColor: 'red' }}/>}
        >
          <Tabs
            initial
            key="home"
            type={'reset'}
            headerMode='none'
            tabBarPosition='bottom'
            tabs
            showLabel
            swipeEnabled={true}
            lazy={true}
            wrap={false}
            tabBarStyle={styles.tabBarStyle}
            titleStyle={styles.titleStyle}
            navigationBarStyle={styles.navigationBarStyle}
            backButtonTintColor={'#FFF'}
          >
            <Scene key="tabProducts" tabBarLabel={strings('title.products')} icon={ ({focused}) => renderIconTab("tabProducts", focused) }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabMyAccount" tabBarLabel={strings('title.myAccount')} icon={ ({focused}) => renderIconTab("tabMyAccount", focused) }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabLists" tabBarLabel={strings('title.lists')} icon={ ({focused}) => renderIconTab("tabLists", focused) }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabNotifications" tabBarLabel={strings('title.notifications')} icon={ ({focused}) => renderIconTab("tabNotifications", focused) }
                   rightButtonImage={ openDrawer() }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>

            /** I want a button HERE to open my drawer **/            

          </Tabs>
        </Drawer>

Steps to reproduce

  1. I tried the solution of the next link, but I got a white screen and DefaultRenderer is not found with V4 version: TabBar with Button for DrawerMenu?  #1744

  2. I tried too another solution: DefaultRenderer in v4 #2710 and I could see my view but the Drawer is not rendered .

I need help to solve this problem.

Thanks!!!

@adaerodriguez
Copy link
Author

adaerodriguez commented May 18, 2018

I found the solution... tabBarOnPress on the Tabs did the trick. This is my code:

<Drawer
          key="drawer"
          contentComponent={DrawerContainer}
          // drawerIcon={dr}
          drawerWidth={260}
          drawerPosition={'right'}
          drawer={true}
          hideNavBar
          drawerImage={ () => <Image source={require('./resources/icons/ic_add.png')} style={{ width: 60, height: 60, tintColor: 'red' }}/>}
        >
          <Tabs
            initial
            key="home"
            type={'reset'}
            headerMode='none'
            tabBarPosition='bottom'
            tabs
            showLabel
            hideNavBar={true}
            swipeEnabled={true}
            lazy={true}
            wrap={false}
            tabBarStyle={styles.tabBarStyle}
            titleStyle={styles.titleStyle}
            navigationBarStyle={styles.navigationBarStyle}
            backButtonTintColor={'#FFF'}
            tabBarOnPress={ ({ scene, jumpToIndex }) => {
              const { key } = scene.route;
              if (key === 'tabOptions') {
                Actions.drawerOpen();
                return;
              }
              if(!scene.focused) {
                jumpToIndex(scene.index);
              }
            }}
          >
            <Scene key="tabProducts" tabBarLabel={strings('title.products')} icon={ ({focused}) => renderIconTab("tabProducts", focused) }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabMyAccount" tabBarLabel={strings('title.myAccount')} icon={ ({focused}) => renderIconTab("tabMyAccount", focused) }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabLists" tabBarLabel={strings('title.lists')} icon={ ({focused}) => renderIconTab("tabLists", focused) }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabNotifications" tabBarLabel={strings('title.notifications')} icon={ ({focused}) => renderIconTab("tabNotifications", focused) }
                   rightButtonImage={ openDrawer() }>
              <Scene key="products" component={ProductsContainer}/>
            </Scene>
            <Scene key="tabOptions" component={Blank} icon={ ({focused}) => renderIconTab("tabOptions", focused) }/>
          </Tabs>
        </Drawer>

I hope this could be helpful for somebody :)

I close this issue

@mobigaurav
Copy link

mobigaurav commented Apr 29, 2019

component={Blank} is not defined with the above solution.

@Belouccio
Copy link

tabBarOnPress={ ({ scene, jumpToIndex }) scene is undefined. Can you reopen this issue?

@hayait599
Copy link

this can be fixed by using the following code

tabBarOnPress = {({ navigation ) => {
  const key =  navigation.state.key;
  if (key === 'DrawerMenu') {
    Actions.drawerOpen();
    return;
  }
  if (!navigation.isFocused()) {
    Actions.jump(key);
  }
}}

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

No branches or pull requests

4 participants