nav: Don't show a transition animation between 'loading' and 'main'. #4260
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A followup to #4249; see #4249 (review).
New in the recent React Navigation upgrades to v3 and v4, there's
now a transition animation when the loading screen exits. We don't
want to prolong the effect of the loading screen [1], so, get rid of
that exit animation.
Most accurately, we want to target the exit of the loading screen
and disable the animation there. But it seems that the
animationEnabled
switch innavigationOptions
operates on theentrance of particular screen; I haven't found a similar option
for the exit of a particular screen.
A good workaround, to the extent that it's practical, would be to
tell all screens to disable their entrance animations if and only if
they're being reached directly from the loading screen. The only
reasonably simple way I can think of to implement this would be to
set
defaultNavigationOptions
to a function instead of anobject [2] and use that function's inputs to conditionalize on the
identity of the route being navigated from, i.e., the previous
route. Unfortunately, that doesn't seem possible; the
navigation
object is the most likely-looking of those inputs, and logging shows
that it doesn't have data about the previous route, only the current
route (in
navigation.state
).So, we use a heuristic: always cancel the entrance animation of the
main-tabs screen. This is supported by the following observations
(but naturally there may be edge cases I haven't considered):
from the loading screen to the main-tabs screen.
other than the main-tabs navigator.
anywhere other than the loading screen.
[1] #4249 (review)
[2] The best link I've found for this is
https://reactnavigation.org/docs/4.x/headers/#using-params-in-the-title.