-
Notifications
You must be signed in to change notification settings - Fork 4
tabBarOnPress implemented on TabNavigator to reset Home stack #497
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import React, { Component } from 'react'; | ||
| import { Platform, View } from 'react-native'; | ||
| import PropTypes from 'prop-types'; | ||
| import { TabNavigator } from 'react-navigation'; | ||
| import { TabNavigator, NavigationActions } from 'react-navigation'; | ||
|
|
||
| import Icon from 'react-native-vector-icons/FontAwesome'; | ||
| import { graphql, compose } from 'react-apollo'; | ||
| import { connect } from 'react-redux'; | ||
|
|
@@ -43,11 +44,21 @@ const MainTabNavigator = TabNavigator( | |
| { | ||
| Home: { | ||
| screen: HomeNavigator, | ||
| navigationOptions: { | ||
| navigationOptions: ({ navigation }) => ({ | ||
| tabBarLabel: 'Home', | ||
| // eslint-disable-next-line react/prop-types | ||
| tabBarIcon: ({ tintColor }) => <Icon size={34} name="home" color={tintColor} />, | ||
| }, | ||
| tabBarOnPress() { | ||
| const resetAction = NavigationActions.reset({ | ||
| index: 0, | ||
| key: 'Home', | ||
| actions: [ | ||
| NavigationActions.navigate({ routeName: 'Root' }), | ||
| ], | ||
| }); | ||
| navigation.dispatch(resetAction); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you try ditching the reset and just using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might help if you explain what you tried before you came to this being the best option
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the first thing I tried, and its what 'the internet' documents as the correct way to reset a stack. There is currently nothing in our code to reset the stack and nothing documented in stacknav that would suggest it should be resetting. When we swap tabs it should just keep the set of tabs in that stack in place.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you just try nav to root you will end up with a weirdly large stack of screens in your stack i believe as it would just add another home screen to the mix. |
||
| }, | ||
| }), | ||
| }, | ||
| Groups: { | ||
| screen: GroupsNavigator, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you not do this only if the tab is already selected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with detecting that and its possible.
But found that users would be on another tab and want to go home so press home, and it wouldnt take them home, and that was confusing.