Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

await for react-navigation transition to finish

I'm looking for a way in react-navigation to dispatch a navigation action and await for it to be fully finished before triggering the next step.

Something like:

await dispatch({
  type: 'Navigation/goBackTo',
  routeName: 'Main',
})
dispatch(anotherAction())

Currently I'm using a setTimeout workaround.

like image 294
maraujop Avatar asked Apr 27 '18 11:04

maraujop


People also ask

How do I stop animation in react navigation?

animationEnabled ​ If you set it to false , the screen won't animate when pushing or popping. Defaults to true on iOS and Android, false on Web.

What is Createstacknavigator?

Provides a way for your app to transition between screens where each new screen is placed on top of a stack. By default the stack navigator is configured to have the familiar iOS and Android look & feel: new screens slide in from the right on iOS, fade in from the bottom on Android.

What is the difference between react navigation and react navigation?

TL;DR: React Navigation has a declarative API with built-in hooks, while React Native Navigation has imperative APIs with a community library for Hooks. React has changed how we think about interface development.


1 Answers

Not specifically related to react-navigation, but useful nonetheless: the InteractionManager API from react-native.

There is a method runAfterInteractions() which will be called after all animations have been completed, so in case of navigation I find it to be a handy tool. For example you could do something like this:

class Main extends Component {

    componentDidMount() {
        // 1: Component has been mounted off-screen
        InteractionManager.runAfterInteractions(() => {
            // 2: Component is done animating
            // 3: Do your anotherAction dispatch() here
        }); 
    }
}
like image 81
dentemm Avatar answered Oct 03 '22 05:10

dentemm