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

react-navigation reset not working in onSuccess #20

Closed
shoichi1023 opened this issue Jun 21, 2018 · 5 comments
Closed

react-navigation reset not working in onSuccess #20

shoichi1023 opened this issue Jun 21, 2018 · 5 comments

Comments

@shoichi1023
Copy link

shoichi1023 commented Jun 21, 2018

I wanna go component2 when I login successed.
but this code not working in onSuccess.
but this work in onPress.

const resetAction = NavigationActions.reset({
      index: 0,
      key: null,
      actions: [NavigationActions.navigate({ routeName: 'TabNavRoot' })],
    });
    this.props.navigation.dispatch(resetAction);

please teach me.


my navigation

StackNavigation

  • component1
  • TabNavRoot(TabNavigation)
    - component2
    - component3
    - component4
@shoichi1023
Copy link
Author

shoichi1023 commented Jun 21, 2018

/*not working*/
  onSuccess = (user) => {
    this.props.setUser(user);
    const resetAction = NavigationActions.reset({
      index: 0,
      key: null,
      actions: [NavigationActions.navigate({ routeName: 'TabNavRoot' })],
    });
    this.props.navigation.dispatch(resetAction);
  }
/*working*/
  onPress = ()=>{
    this.props.setUser({name:'aaaaaa'});
    const resetAction = NavigationActions.reset({
      index: 0,
      key: null,
      actions: [NavigationActions.navigate({ routeName: 'TabNavRoot' })],
    });
    this.props.navigation.dispatch(resetAction);
  }

@watanabeyu
Copy link
Owner

@shoichi1023

もしよければソースコード全体を https://snack.expo.io に差し支えがない範囲で載せてもらえますか?
自分が使っている範囲ではonSuccessでNavigationActionsができるので。
使っているpackageやreact-nativeのバージョンなどの情報もあわせて欲しいです。

@shoichi1023
Copy link
Author

https://snack.expo.io/@shoichi/login

{
"main": "node_modules/expo/AppEntry.js",
"private": true,
"dependencies": {
"expo": "^26.0.0",
"native-base": "^2.4.5",
"react": "16.3.0-alpha.1",
"react-native": "^0.54.2",
"react-native-elements": "^0.19.1",
"react-native-keyboard-aware-scroll-view": "^0.5.0",
"react-native-keyboard-aware-view": "0.0.14",
"react-native-myparallax-scroll-view": "^0.19.0",
"react-native-parallax-scroll-view": "^0.21.0",
"react-native-parallax-view": "^2.0.6",
"react-native-scrollable-tab-view": "^0.8.0",
"react-native-scrollable-tab-view-universal": "^0.1.1",
"react-native-simple-twitter": "^2.0.2",
"react-native-tab-view": "0.0.78",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "^1.5.11",
"react-navigation-redux-helpers": "^1.0.5",
"react-redux": "^5.0.7",
"redux": "^4.0.0"
}
}

よろしくお願いいたします。

@watanabeyu
Copy link
Owner

@shoichi1023
多分原因はreact-native-simple-twitterではなく、
箇所は特定しておりませんが@shoichi1023 さんのコード内にあるのではないかと思います。
こちらでpageNation.js内のtabNavを下記に変更し、
onSuccess時にNavigationActions.reset()を実行したところ遷移されました。

const tabNav = TabNavigator({
  Home: {
    screen: () => (
      <View><Text>ok</Text></View>
    )
  },
},{
  tabBarOptions: {
      inactiveTintColor: '#bbb',
      activeTintColor: '#000',
      showLabel: false,
    },
    initialRouteName: 'Home',
    tabBarComponent: TabBarBottom,
    tabBarPosition: 'bottom',
    swipeEnabled: true,
    lazy: false,
})

output

申し訳ないですがこちらで対応できるのはここまでですね…

よろしくお願いいたします。

@shoichi1023
Copy link
Author

恐れ入ります、ありがとうございます。
確認してみます。

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

No branches or pull requests

2 participants