Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

pass onTransitionStart's return value back to caller #27

Closed
wants to merge 1 commit into from

Conversation

mramad2
Copy link

@mramad2 mramad2 commented Jun 26, 2019

Use case: If we want to wait for an async call to complete before proceeding with the navigation

Transitioner checks to see if value is promise, and if so it waits.
https://github.com/react-navigation/stack/blob/676bc3b45a7715edecd13530ae3b39ee1fe48833/src/views/Transitioner.tsx#L204

@satya164
Copy link
Member

The implemention of stack is going to change very soon. I'd not recommend relying on these props.

react-navigation/stack#131

Also this feels like the wrong place to put async logic. Why not do the async call first before triggering the navigation?

@mramad2
Copy link
Author

mramad2 commented Jun 26, 2019

We want to use the opportunity before navigating to a screen to fetch down some additional content to store offline and use on the screen. The react navigation gets invoked in such a way that we have no means of examining where the route leads to before the transition starts. The scenario we hope to accomplish is somewhat more complex than how I explained it, but looking at onTransitionStart, I was under the impression that it would wait on async actions to complete.

@satya164
Copy link
Member

I was under the impression that it would wait on async actions to complete.

I don't know the original intention behind the await. But I doubt that it waits for the new screen to mount after onTransitionStart was already called. Have you tested it?

The react navigation gets invoked in such a way that we have no means of examining where the route leads to before the transition starts
We want to use the opportunity before navigating to a screen to fetch down some additional content to store offline and use on the screen

It sounds like the way your code is structured, and it should be possible to restructure it to achieve what you want. I feel the most maintainable way is to make a screen fetch it's own data rather than fetching it before navigating, and waiting for unknown amount of time (network can be slow) before navigating isn't a great UX either.

Anyway, I'm closing this because transitioner is going away and whatever this will enable will break very soon.

@satya164 satya164 closed this Jun 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants