Children of shared views
By default, the shared view moves together with its own children, and the children of the target view show at once when the transition ends. When the two views have different children, for example a card in a list and a header on a details screen, this change is sudden. You can change this in two ways, also together:
- Give a child its own
sharedTransitionTagwhen the same child is on both screens, for example an icon. The child then moves to its own match, as a separate shared view. - Use
fadeContent()for the other children. The children of the moving view fade out while it moves, and the children of the target view fade in when the transition ends. The view itself stays visible, and its frame and style animate as usual.
Children with their own tag
A child with its own matching sharedTransitionTag moves from its place in the old view to its place in the new view. It does not fade with its parent, also with fadeContent(). When its target is inside the target of the parent, it moves inside the moving parent: it keeps its place in the drawing order and the clipping of the parent, and the two land together when the slower one ends. In other cases, for example when the child is inside a shared view on only one of the screens, it moves on its own, above the other views. To see the difference, toggle the Icon has its own tag switch in the demo above.
<Animated.View sharedTransitionTag="card" sharedTransitionStyle={transition}>
<Animated.Text sharedTransitionTag="card-icon">☀</Animated.Text>
<Text>Sun</Text>
</Animated.View>
Give the child the same tag on both screens, and use the same native component on both screens, as for any shared view.
The moving view keeps its own content, so a different fontSize on the two screens changes at once when the transition ends. To change the size of a child smoothly, give it the same fontSize on both screens and scale it with transform, which animates.
fadeContent()
Reference
import Animated, { SharedTransition } from 'react-native-reanimated';
const transition = SharedTransition.duration(450).fadeContent();
function Card() {
return (
<Animated.View
sharedTransitionTag="card"
sharedTransitionStyle={transition}>
<Text>Florence</Text>
</Animated.View>
);
}


Type definitions
type FadeContentConfig = {
fadeOut?: { end?: number };
fadeIn?: { duration?: number };
};
class SharedTransition {
static fadeContent(config?: FadeContentConfig): SharedTransition;
fadeContent(config?: FadeContentConfig): this;
// ...
}
Arguments
config Optional
An object with two optional fields:
fadeOut.end- the point of the move, more than 0 and at most 1, where the children reach opacity 0. For example, with0.5the children are gone in the middle of the move. The point follows the easing or the spring of the move. Defaults to1.fadeIn.duration- the length of the fade-in after the transition ends, in milliseconds. Defaults to half of the transition duration.
const transition = SharedTransition.duration(450).fadeContent({
fadeOut: { end: 0.5 },
fadeIn: { duration: 150 },
});
Remarks
- The direct children of the shared view fade, also a child that fills the view, for example a background image. A nested shared view and the views that contain it keep their opacity. The views beside them fade instead.
- A shared view without children, for example a shared
Image, has nothing to fade. - A child of the target view that fades and has an
enteringanimation plays it after the transition ends, in place of the fade-in. - The transition uses the builder of the view that it starts from. To fade the content in both directions, give
fadeContent()to both views. - A nested shared view moves relative to its moving parent. If the two have different timing, the nested view does not move along a straight line on screen.
- With
SharedTransition.custom(), the children fade with the duration, easing or spring of the builder, not with the timing of your worklet. To fade them over the whole move, give the builder the same timing, for exampleSharedTransition.custom(animation).duration(800).fadeContent().
Platform compatibility
| Android | iOS | Web |
|---|---|---|
| ✅ | ✅ | ❌ |