Skip to content

StackNavigator: Allow configurable, different transition animations between screens #124

@lintonye

Description

@lintonye

Motivation

Right now only one kind of animation is supported in a StackNavigator. It's useful to support different transitions between different screens in a same stack. For example, you may want shared elements transition between a photo grid and the photo's detail screen, and the default system transition when navigating to the settings screen.

Proposed API

const SimpleStack = StackNavigator({
  PhotoGrid: {
    screen: PhotoGrid,
  },
  PhotoDetail: {
    screen: PhotoDetail,
  },
  Settings: {
    screen: Settings,
  },
}, {
  transitions: [
    {routeNames: ['PhotoGrid', 'PhotoDetail'], transition: SharedElements},
    // The rest are default: CardStack
  ]
});

Or, better yet, determine the transition dynamically:

{
  transition: (fromRoute, toRoute) => {
    const routeNames = [ fromRoute.routeName, toRoute.routeName];
    return (routeNames.includes('PhotoGrid') && routeNames.includes('PhotoDetail') 
      ? SharedElements
      : CardStack);
  }
}

Implementation Plan

With a minor change to CardStack, which exposes transitionProps and prevTransitionProps to the transitionConfig prop function, we can implement this for simple transitions such as opacity or translateX/Y animations. @ericvicenti also mentioned an approach to allow each screen to define what Card component to use. This should give more flexibility on how individual screens are animated during the transition.

However, for more complex transitions that require information from multiple screens, such as the shared elements transition, we'd need some extra support. See #175.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions