Skip to main content

Animating elements between screens

This guide covers how to animate elements between screens. This feature is known as a Shared Element Transition and it's implemented in the @react-navigation/native-stack with React Native Reanimated.

warning

Shared Element Transitions are an experimental feature not recommended for production use yet.

Architecture support:

Check the Reanimated documentation for details and send feedback to the Reanimated team

Pre-requisites

Before continuing this guide make sure your app meets these criteria:

Minimal example

To create a shared transition:

  1. Use Animated components imported from react-native-reanimated.
  2. Assign the same sharedTransitionTag to elements on different screens.
  3. Navigate between screens. The transition will start automatically.
function HomeScreen() {
const navigation = useNavigation();

return (
<View style={styles.container}>
<Button onPress={() => navigation.navigate('Details')}>
Go to Details
</Button>
<Animated.Image
source={{ uri: 'https://picsum.photos/id/39/200' }}
style={{ width: 300, height: 300 }}
sharedTransitionTag="tag"
/>
</View>
);
}

function DetailsScreen() {
const navigation = useNavigation();

return (
<View style={styles.container}>
<Button onPress={() => navigation.goBack()}>Go back</Button>
<Animated.Image
source={{ uri: 'https://picsum.photos/id/39/200' }}
style={{ width: 100, height: 100 }}
sharedTransitionTag="tag"
/>
</View>
);
}

sharedTransitionTag is a string that has to be unique in the context of a single screen, but has to match elements between screens. This prop allows Reanimated to identify and animate the elements, similarly to the key property, which tells React which element in the list is which.

Customizing the transition

You can customize the transition by passing a custom SharedTransition configuration via the sharedTransitionStyle prop. Apply the same sharedTransitionStyle to the matching element on the target screen.

Custom transition configuration is not fully finalized and might change in a future release.