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

Commit

Permalink
fix: keep screens for replace when animation is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 3, 2020
1 parent 572beae commit 7f963a7
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/stack/src/views/Stack/StackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,25 @@ class StackView extends React.Component<Props, State> {
| undefined;
const nextFocusedRoute = routes[routes.length - 1];

const isAnimationEnabled = (key: string) => {
const descriptor = props.descriptors[key] || state.descriptors[key];

return descriptor ? descriptor.options.animationEnabled !== false : true;
};

if (
previousFocusedRoute &&
previousFocusedRoute.key !== nextFocusedRoute.key
) {
// We only need to animate routes if the focused route changed
// Animating previous routes won't be visible coz the focused route is on top of everything

const isAnimationEnabled = (route: Route<string>) => {
const descriptor =
props.descriptors[route.key] || state.descriptors[route.key];

return descriptor
? descriptor.options.animationEnabled !== false
: true;
};

if (!previousRoutes.find(r => r.key === nextFocusedRoute.key)) {
// A new route has come to the focus, we treat this as a push
// A replace can also trigger this, the animation should look like push

if (
isAnimationEnabled(nextFocusedRoute) &&
isAnimationEnabled(nextFocusedRoute.key) &&
!openingRouteKeys.includes(nextFocusedRoute.key)
) {
// In this case, we need to animate pushing the focused route
Expand Down Expand Up @@ -151,7 +148,7 @@ class StackView extends React.Component<Props, State> {
// The previously focused route was removed, we treat this as a pop

if (
isAnimationEnabled(previousFocusedRoute) &&
isAnimationEnabled(previousFocusedRoute.key) &&
!closingRouteKeys.includes(previousFocusedRoute.key)
) {
// Sometimes a route can be closed before the opening animation finishes
Expand All @@ -174,14 +171,15 @@ class StackView extends React.Component<Props, State> {
// We don't know how to animate this
}
} else if (replacingRouteKeys.length || closingRouteKeys.length) {
// Keep the routes we are closing or replacing
// Keep the routes we are closing or replacing if animation is enabled for them
routes = routes.slice();
routes.splice(
routes.length - 1,
0,
...state.routes.filter(
({ key }) =>
replacingRouteKeys.includes(key) || closingRouteKeys.includes(key)
...state.routes.filter(({ key }) =>
isAnimationEnabled(key)
? replacingRouteKeys.includes(key) || closingRouteKeys.includes(key)
: false
)
);
}
Expand Down

0 comments on commit 7f963a7

Please sign in to comment.