SharedTransition
SharedTransition is a builder that sets how a shared view moves. Pass it to the sharedTransitionStyle prop. Without modifiers, the view moves with a 500 ms withTiming animation.
Reference
import Animated, { SharedTransition, Easing } from 'react-native-reanimated';
const transition = SharedTransition.duration(400).easing(Easing.out(Easing.cubic));
function Photo() {
return (
<Animated.View
sharedTransitionTag="photo"
sharedTransitionStyle={transition}
/>
);
}
Modifiers
Easing Optional
Easing modifiers use the withTiming function.
SharedTransition.duration(400).easing(Easing.out(Easing.cubic));
.easing(easingFunction: EasingFunction)sets the animation curve. Defaults toEasing.inOut(Easing.quad).
The .easing(...) modifier has no effect when you use .springify().
Spring-based Optional
Spring-based modifiers use the withSpring function. As in the withSpring config, a spring is duration-based (duration and dampingRatio) or physics-based (mass, damping and stiffness).
// duration-based
SharedTransition.springify(600).dampingRatio(0.7);
// physics-based
SharedTransition.springify().damping(15).stiffness(150);
.springify(duration?: number)uses a spring for the transition. The optional argument sets the perceptual duration of the spring in milliseconds. The spring stops after about 1.5 times this value. Defaults to500..dampingRatio(value: number)sets how damped the spring is. Value1means that the spring is critically damped, and value>1means that the spring is overdamped. Defaults to1..damping(value: number)sets how quickly the spring stops. Higher damping means that the spring stops faster. Defaults to120..mass(value: number)is the weight of the spring. A lower value makes the animation faster. Defaults to4..stiffness(value: number)sets the stiffness of the spring. Defaults to900..overshootClamping(value: boolean)sets whether the spring can go past its target. Defaults tofalse..energyThreshold(value: number)sets the relative energy below which the spring stops. Defaults to6e-9.
If you set damping, mass or stiffness without a duration and without dampingRatio, the spring is physics-based. In all other cases, the spring uses a duration, which is 500 ms by default.
Common Optional
SharedTransition.duration(400)
.delay(100)
.reduceMotion(ReduceMotion.System)
.withCallback((finished) => {
'worklet';
console.log(`finished without interruptions: ${finished}`);
});
.duration(duration: number)sets the length of the animation in milliseconds. Defaults to500..delay(duration: number)sets the time before the animation starts, in milliseconds. Defaults to0..reduceMotion(reduceMotion: ReduceMotion)sets how the transition responds to the reduced motion accessibility setting of the device. When reduced motion applies to one of the two views, the transition does not run, and the views show in their own places..withCallback(callback: (finished: boolean) => void)sets a function that runs once, when the transition ends. The callback is automatically workletized and runs on the UI thread.finishedistruewhen the view lands at its target, andfalsewhen the transition stops before that or does not move the view.
When a new transition of the same tag starts before the first one ends, for example when the user goes back, the first callback gets false, and the new transition reports its own result. During an iOS back gesture, the callback gets true when the navigation completes, and false when the user cancels the gesture.
Shared transition modifiers Optional
.fadeContent(config?)fades the children of the view during the transition..custom(animation)uses your own animation worklet..progressAnimation(animation)and.defaultTransitionType(type)set the transition that follows the progress of the screen change.
Remarks
.springify()sets the duration again. Call.springify(duration)with the duration that you want, not.duration(...)before.springify().- The transition uses the builder of the view that it starts from. See
sharedTransitionStyle.
Platform compatibility
| Android | iOS | Web |
|---|---|---|
| ✅ | ✅ | ❌ |