Resetting the navigation stack for the home screen (React Navigation and React Native)

前端 未结 13 2382
终归单人心
终归单人心 2020-11-29 23:49

I\'ve got a problem with the navigation of React Navigation and React Native. It is about resetting navigation and returning to the home screen.

I\'ve build a StackN

13条回答
  •  离开以前
    2020-11-30 00:23

    Here is how I do it:

    import { NavigationActions } from 'react-navigation'
    
    this.props.navigation.dispatch(NavigationActions.reset({
        index: 0,
        key: null,
        actions: [NavigationActions.navigate({ routeName: 'ParentStackScreen' })]
    }))
    

    The important part is key: null.

    That wipes the stack while navigating from a child navigator to a parent navigator.

    Do that if you get this error:

    For animations, I use

    // https://github.com/oblador/react-native-animatable
    import * as Animatable from 'react-native-animatable'
    

    I just control all the animations myself. Put them on any component you want by wrapping it with .

提交回复
热议问题