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

TabNavigator: Customize onPress functionality for custom tabs? #1059

Closed
joncursi opened this issue Apr 15, 2017 · 16 comments
Closed

TabNavigator: Customize onPress functionality for custom tabs? #1059

joncursi opened this issue Apr 15, 2017 · 16 comments

Comments

@joncursi
Copy link

joncursi commented Apr 15, 2017

Right now the TabNavigator has full control of the onPress functionality of what happens when you tap on a tab. All you can really do is specify a screen, and the TabNavigator takes care of the rest.

const Tabs = TabNavigator({
  ...
  SomeScreen: { screen: SomeScreen },
  ...
});

What if I want to render a tab, but with custom onPress functionality rather than pushing or jumping to a new screen? Consider yelp's "Add" tab:

img_3575

Tapping the "+" doesn't push a new screen or jump to a new tab. It simply renders an overlay over the existing screen.

img_3574

Is it possible to reacreate the Yelp example with the existing TabNavigator API? I've been scratching my head over this. Thanks!

@joncursi
Copy link
Author

Reddit is another example:

img_3576

@guoliang1206
Copy link

hi man, did you find some way to handle the custom events of tabs on TabNavigator?

@joncursi
Copy link
Author

Not yet, I'm also waiting to hear from the authors on possible ways we can achieve this

@manan
Copy link

manan commented Apr 23, 2017

Me too!

@augustoabreu
Copy link

augustoabreu commented Apr 25, 2017

I'm trying to do a similar behaviour #1227

@ofairfoul
Copy link

ofairfoul commented May 8, 2017

@joncursi you can create your own tab bar component quite easily. start by copying the source from TabBarBottom.js. Then you can insert your own custom center button into the view hierarchy. You have access to the navigation prop for navigating or connect it to redux.

Here is a super-stripped-down version I created for my project, doesn't support animation, swipe or tab labels.

import React from 'react';
import { View, StyleSheet, TouchableWithoutFeedback } from 'react-native';

const styles = StyleSheet.create({
  tabbar: {
    height: 49,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    borderTopWidth: 1,
    borderTopColor: colors.border,
    backgroundColor: colors.bgLightGrey
  },
  tab: {
    alignSelf: 'stretch',
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
  }
});

const TabBar = React.createClass({
  render() {

    const {
      navigation,
      renderIcon,
      activeTintColor,
      inactiveTintColor,
      jumpToIndex
    } = this.props;

    const {
      routes
    } = navigation.state;

    return (
      <View style={styles.tabbar}>

        {routes && routes.map((route, index) => {
          const focused = index === navigation.state.index;
          const tintColor = focused ? activeTintColor : inactiveTintColor;
          return (
            <TouchableWithoutFeedback
              key={route.key}
              style={styles.tab}
              onPress={() => jumpToIndex(index)}
            >
              <View style={styles.tab}>
                {renderIcon({
                  route,
                  index,
                  focused,
                  tintColor
                })}
              </View>
            </TouchableWithoutFeedback>
          );
        })}

      </View>
    );
  }
});

export default TabBar;

and in your TabNavigator definition set the tabBarComponent

const TabsNavigator = TabNavigator(
  {
      ...routeConfig
  },
  {
    tabBarComponent: TabBar,
    tabBarPosition: 'bottom'
  }
);

@valeriaabo
Copy link

So what @ofairfoul posted should work? Im looking exactly for this 😮

@valeriaabo
Copy link

@joncursi Did you get to recreate the yelp Example? Please IM Stucked!

I used @ofairfoul code but my middle button that opens more options is not overlaying.

@joncursi
Copy link
Author

No, I haven't gotten it yet either :/

@ericlewis
Copy link

have you checked where that overlay is in your view hierarchy? if its anything like other overlays, you need to actually do this elsewhere than the tab bar itself or utilize zIndex.

@javidjamae
Copy link

+1 (so I can search for this later)...

@spencercarli
Copy link
Member

This use case should be solved by #1335 (will be merging soon)

@fqueiruga
Copy link

+1

@kelset
Copy link

kelset commented Oct 14, 2017

Pinging OP @joncursi since this issue is quite old and related to an old version of the lib (we merged #1335 so beta.13 has this feature). If no answer I'll close in 7 days.

@kelset
Copy link

kelset commented Oct 21, 2017

Hi there @joncursi ,

In an effort to cleanup this project and prioritize a bit, since this issue had no follow up since my last comment I'm going to close it.

If you are still having the issue (especially if it's a bug report) please open a new issue that uses the new Issue Template to provide some more details to help us solve it.

@anuragfexle
Copy link

No, I haven't gotten it yet either :/

Hey @joncursi did you get the solution for this? Please help if you resolve the issue I am tucked here. I want to show exactly the same UI on middle button click.

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