Skip to content

Commit d1c4c46

Browse files
Also cover 6.x docs
1 parent 83283d3 commit d1c4c46

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

versioned_docs/version-6.x/shared-element-transitions.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Animating elements between screens
22

3-
This guide covers how to animate elements between screens. This feature is known as a [Shared Element Transition](https://docs.swmansion.com/react-native-reanimated/docs/api/sharedElementTransitions) and it's implemented in the [`@react-navigation/native-stack`](/docs/native-stack-navigator) with [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/).
3+
This guide covers how to animate elements between screens. This feature is known as a [Shared Element Transition](https://docs.swmansion.com/react-native-reanimated/docs/shared-element-transitions/overview/) and it's implemented in the [`@react-navigation/native-stack`](native-stack-navigator.md) with [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/).
44

55
:::warning
66

7-
As of writing this guide, Shared Element Transitions are considered an experimental feature not recommended for production use.
7+
Shared Element Transitions are an experimental feature not recommended for production use yet.
8+
9+
**Architecture support:**
10+
11+
- **Reanimated 3** supports Shared Element Transitions on the **Old Architecture** (Paper).
12+
- **Reanimated 4** supports them on the **New Architecture** (Fabric) since 4.2.0, but the feature is behind a feature flag. You need to [enable the `ENABLE_SHARED_ELEMENT_TRANSITIONS` feature flag](https://docs.swmansion.com/react-native-reanimated/docs/guides/feature-flags#enable_shared_element_transitions) to use it.
13+
14+
Check [the Reanimated documentation](https://docs.swmansion.com/react-native-reanimated/docs/shared-element-transitions/overview/) for details and [send feedback to the Reanimated team](https://github.com/software-mansion/react-native-reanimated)
815

916
:::
1017

@@ -18,6 +25,7 @@ Before continuing this guide make sure your app meets these criteria:
1825

1926
- You are using [`@react-navigation/native-stack`](native-stack-navigator.md). The Shared Element Transitions feature isn't supported in JS-based [`@react-navigation/stack`](stack-navigator.md).
2027
- You have [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started) **v3.0.0 or higher** installed and configured.
28+
- If you are using **Reanimated 4** (New Architecture), you must [enable the `ENABLE_SHARED_ELEMENT_TRANSITIONS` feature flag](https://docs.swmansion.com/react-native-reanimated/docs/guides/feature-flags#enable_shared_element_transitions).
2129

2230
## Minimal example
2331

@@ -92,18 +100,18 @@ const styles = StyleSheet.create({
92100

93101
## Customizing the transition
94102

95-
By default, the transition animates the `width`, `height`, `originX`, `originY` and `transform` properties using `withTiming` with a 500 ms duration. You can easily customize `width`, `height`, `originX`, and `originY` props. Customizing `transform` is also possible but it's far beyond the scope of this guide.
96-
97-
:::warning
103+
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.
98104

99-
Custom SharedTransition API is not finalized and might change in a future release.
105+
Custom transition configuration is not fully finalized and might change in a future release.
100106

101107
:::
102108

103-
To customize the transition you need to pass all the properties besides `transform`.
109+
### Old Architecture (Reanimated 3)
110+
111+
By default, the transition animates `width`, `height`, `originX`, `originY`, and `transform` using `withTiming` with a 500 ms duration. You can customize the transition using `SharedTransition.custom()`:
104112

105113
```jsx
106-
import { SharedTransition } from 'react-native-reanimated';
114+
import { SharedTransition, withSpring } from 'react-native-reanimated';
107115

108116
const customTransition = SharedTransition.custom((values) => {
109117
'worklet';
@@ -127,10 +135,54 @@ function HomeScreen() {
127135
}
128136
```
129137

138+
### New Architecture (Reanimated 4)
139+
140+
On the New Architecture, the default transition animates `width`, `height`, `originX`, `originY`, `transform`, `backgroundColor`, and `opacity` using `withTiming` with a 500 ms duration.
141+
142+
Currently customization is more limited due to ongoing development. You can't define fully custom animation functions. Instead, use the `SharedTransition` builder class to configure duration and spring-based animations:
143+
144+
```jsx
145+
import { SharedTransition } from 'react-native-reanimated';
146+
147+
// Example: customize duration and use spring animation
148+
const customTransition = SharedTransition.duration(550).springify();
149+
150+
function HomeScreen() {
151+
return (
152+
<Animated.Image
153+
style={{ width: 300, height: 300 }}
154+
sharedTransitionTag="tag"
155+
// highlight-next-line
156+
sharedTransitionStyle={customTransition}
157+
/>
158+
);
159+
}
160+
```
161+
130162
## Reference
131163

132164
You can find a full Shared Element Transitions reference in the [React Native Reanimated documentation](https://docs.swmansion.com/react-native-reanimated/docs/shared-element-transitions/overview/).
133165

166+
## Limitations
167+
168+
Shared Element Transitions have several current limitations to be aware of:
169+
170+
- Only the native stack navigator is supported
171+
- The Tab navigator is not supported
172+
- Transitions with native modals don't work properly on iOS
173+
174+
### New Architecture specific limitations (Reanimated 4)
175+
176+
The following limitations apply specifically when using Reanimated 4 on the New Architecture:
177+
178+
- The feature must be enabled via the `ENABLE_SHARED_ELEMENT_TRANSITIONS` feature flag
179+
- Custom animation functions are not supported; you can only customize duration and use spring-based animations
180+
- Some properties (e.g., `backgroundColor`) are not supported in progress-based transitions (iOS back gesture)
181+
- There are performance bottlenecks with transforms being recalculated too eagerly
182+
- On iOS, you may encounter issues with vertical positioning due to header height information propagation
183+
184+
The limitations will be addressed in future Reanimated releases.
185+
134186
## Alternatives
135187

136188
Alternatively, you can use [`react-native-shared-element`](https://github.com/IjzerenHein/react-native-shared-element) library with a [React Navigation binding](https://github.com/IjzerenHein/react-navigation-shared-element) which implements Shared Element Transitions in a JS-based `@react-navigation/stack` navigator. This solution, however, isn't actively maintained.

0 commit comments

Comments
 (0)