Skip to content

Commit 7ffbcaa

Browse files
Update SETs documentation (#1453)
Co-authored-by: Satyajit Sahoo <[email protected]>
1 parent 7951f82 commit 7ffbcaa

File tree

3 files changed

+166
-207
lines changed

3 files changed

+166
-207
lines changed

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

Lines changed: 64 additions & 10 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

@@ -16,8 +23,9 @@ As of writing this guide, Shared Element Transitions are considered an experimen
1623

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

19-
- 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).
26+
- You are using [`@react-navigation/native-stack`](native-stack-navigator.md). JS-based [`@react-navigation/stack`](stack-navigator.md) or other navigators are not supported.
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,28 +100,29 @@ 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.
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.
96104

97-
:::warning
105+
Custom transition configuration is not fully finalized and might change in a future release.
98106

99-
Custom SharedTransition API is not finalized and might change in a future release.
107+
### Old Architecture (Reanimated 3)
100108

101-
:::
102-
103-
To customize the transition you need to pass all the properties besides `transform`.
109+
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()`:
104110

105111
```jsx
106-
import { SharedTransition } from 'react-native-reanimated';
112+
import { SharedTransition, withSpring } from 'react-native-reanimated';
107113

114+
// highlight-start
108115
const customTransition = SharedTransition.custom((values) => {
109116
'worklet';
117+
110118
return {
111119
height: withSpring(values.targetHeight),
112120
width: withSpring(values.targetWidth),
113121
originX: withSpring(values.targetOriginX),
114122
originY: withSpring(values.targetOriginY),
115123
};
116124
});
125+
// highlight-end
117126

118127
function HomeScreen() {
119128
return (
@@ -127,10 +136,55 @@ function HomeScreen() {
127136
}
128137
```
129138

139+
### New Architecture (Reanimated 4)
140+
141+
On the New Architecture, the default transition animates `width`, `height`, `originX`, `originY`, `transform`, `backgroundColor`, and `opacity` using `withTiming` with a 500 ms duration.
142+
143+
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:
144+
145+
```jsx
146+
import { SharedTransition } from 'react-native-reanimated';
147+
148+
// Customize duration and use spring animation
149+
// highlight-next-line
150+
const customTransition = SharedTransition.duration(550).springify();
151+
152+
function HomeScreen() {
153+
return (
154+
<Animated.Image
155+
style={{ width: 300, height: 300 }}
156+
sharedTransitionTag="tag"
157+
// highlight-next-line
158+
sharedTransitionStyle={customTransition}
159+
/>
160+
);
161+
}
162+
```
163+
130164
## Reference
131165

132166
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/).
133167

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

136190
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.

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

Lines changed: 61 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ This guide covers how to animate elements between screens. This feature is known
1111

1212
:::warning
1313

14-
As of writing this guide, Shared Element Transitions are considered an experimental feature not recommended for production use.
14+
Shared Element Transitions are an experimental feature not recommended for production use yet.
1515

16-
Shared Element Transitions are currently only supported on **old React Native architecture** (Paper).
16+
**Architecture support:**
17+
18+
- **Reanimated 3** supports Shared Element Transitions on the **Old Architecture** (Paper).
19+
- **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.
20+
21+
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)
1722

1823
:::
1924

@@ -25,8 +30,9 @@ Shared Element Transitions are currently only supported on **old React Native ar
2530

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

28-
- 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).
33+
- You are using [`@react-navigation/native-stack`](native-stack-navigator.md). JS-based [`@react-navigation/stack`](stack-navigator.md) or other navigators are not supported.
2934
- You have [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started) **v3.0.0 or higher** installed and configured.
35+
- 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).
3036

3137
## Minimal example
3238

@@ -36,10 +42,7 @@ To create a shared transition:
3642
2. Assign the same `sharedTransitionTag` to elements on different screens.
3743
3. Navigate between screens. The transition will start automatically.
3844

39-
<Tabs groupId="config" queryString="config">
40-
<TabItem value="static" label="Static" default>
41-
42-
```js name="Shared transition"
45+
```js static2dynamic name="Shared transition"
4346
import * as React from 'react';
4447
import { View, StyleSheet } from 'react-native';
4548
import {
@@ -85,14 +88,12 @@ function DetailsScreen() {
8588
);
8689
}
8790

88-
// highlight-start
8991
const RootStack = createNativeStackNavigator({
9092
screens: {
9193
Home: HomeScreen,
9294
Details: DetailsScreen,
9395
},
9496
});
95-
// highlight-end
9697

9798
const Navigation = createStaticNavigation(RootStack);
9899

@@ -108,111 +109,66 @@ const styles = StyleSheet.create({
108109
});
109110
```
110111

111-
</TabItem>
112-
<TabItem value="dynamic" label="Dynamic">
113-
114-
```js name="Shared transition"
115-
import * as React from 'react';
116-
import { View, StyleSheet } from 'react-native';
117-
import { NavigationContainer, useNavigation } from '@react-navigation/native';
118-
import { createNativeStackNavigator } from '@react-navigation/native-stack';
119-
import { Button } from '@react-navigation/elements';
120-
121-
import Animated from 'react-native-reanimated';
122-
123-
// highlight-next-line
124-
const Stack = createNativeStackNavigator();
125-
126-
function HomeScreen() {
127-
const navigation = useNavigation();
128-
129-
return (
130-
<View style={styles.container}>
131-
<Button onPress={() => navigation.navigate('Details')}>
132-
Go to Details
133-
</Button>
134-
<Animated.Image
135-
source={{ uri: 'https://picsum.photos/id/39/200' }}
136-
style={{ width: 300, height: 300 }}
137-
// highlight-next-line
138-
sharedTransitionTag="tag"
139-
/>
140-
</View>
141-
);
142-
}
143-
144-
function DetailsScreen() {
145-
const navigation = useNavigation();
146-
147-
return (
148-
<View style={styles.container}>
149-
<Button onPress={() => navigation.goBack()}>Go back</Button>
150-
<Animated.Image
151-
source={{ uri: 'https://picsum.photos/id/39/200' }}
152-
style={{ width: 100, height: 100 }}
153-
// highlight-next-line
154-
sharedTransitionTag="tag"
155-
/>
156-
</View>
157-
);
158-
}
159-
160-
export default function App() {
161-
return (
162-
<NavigationContainer>
163-
<Stack.Navigator>
164-
<Stack.Screen name="Home" component={HomeScreen} />
165-
<Stack.Screen name="Details" component={DetailsScreen} />
166-
</Stack.Navigator>
167-
</NavigationContainer>
168-
);
169-
}
170-
171-
const styles = StyleSheet.create({
172-
container: {
173-
flex: 1,
174-
alignItems: 'center',
175-
},
176-
});
177-
```
178-
179-
</TabItem>
180-
</Tabs>
181-
182112
`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`](https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key) property, which tells React which element in the list is which.
183113

184114
## Customizing the transition
185115

186-
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.
116+
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.
187117

188-
:::warning
118+
Custom transition configuration is not fully finalized and might change in a future release.
189119

190-
Custom SharedTransition API is not finalized and might change in a future release.
120+
### Old Architecture (Reanimated 3)
191121

192-
:::
193-
194-
To customize the transition you need to pass all the properties besides `transform`.
122+
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()`:
195123

196124
```jsx
197-
import { SharedTransition } from 'react-native-reanimated';
125+
import { SharedTransition, withSpring } from 'react-native-reanimated';
198126

127+
// highlight-start
199128
const customTransition = SharedTransition.custom((values) => {
200129
'worklet';
130+
201131
return {
202132
height: withSpring(values.targetHeight),
203133
width: withSpring(values.targetWidth),
204134
originX: withSpring(values.targetOriginX),
205135
originY: withSpring(values.targetOriginY),
206136
};
207137
});
138+
// highlight-end
208139

209140
function HomeScreen() {
210141
return (
211142
<Animated.Image
212143
style={{ width: 300, height: 300 }}
213144
sharedTransitionTag="tag"
214145
// highlight-next-line
215-
sharedTransitionStyle={customTransition} // add this to both elements on both screens
146+
sharedTransitionStyle={customTransition}
147+
/>
148+
);
149+
}
150+
```
151+
152+
### New Architecture (Reanimated 4)
153+
154+
On the New Architecture, the default transition animates `width`, `height`, `originX`, `originY`, `transform`, `backgroundColor`, and `opacity` using `withTiming` with a 500 ms duration.
155+
156+
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:
157+
158+
```jsx
159+
import { SharedTransition } from 'react-native-reanimated';
160+
161+
// Customize duration and use spring animation
162+
// highlight-next-line
163+
const customTransition = SharedTransition.duration(550).springify();
164+
165+
function HomeScreen() {
166+
return (
167+
<Animated.Image
168+
style={{ width: 300, height: 300 }}
169+
sharedTransitionTag="tag"
170+
// highlight-next-line
171+
sharedTransitionStyle={customTransition}
216172
/>
217173
);
218174
}
@@ -222,8 +178,22 @@ function HomeScreen() {
222178

223179
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/).
224180

225-
## Alternatives
181+
## Limitations
182+
183+
Shared Element Transitions currently have several limitations to be aware of:
184+
185+
- Only the [native stack navigator](native-stack-navigator.md) is supported
186+
- Other navigators such as JS stack, drawer, and bottom tabs are not supported
187+
- Transitions with native modals don't work properly on iOS
188+
189+
### New Architecture specific limitations (Reanimated 4)
190+
191+
The following limitations apply specifically when using Reanimated 4 on the New Architecture:
226192

227-
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.
193+
- The feature must be enabled via the `ENABLE_SHARED_ELEMENT_TRANSITIONS` feature flag
194+
- Custom animation functions are not supported; you can only customize duration and use spring-based animations
195+
- Some properties (e.g., `backgroundColor`) are not supported in progress-based transitions (iOS back gesture)
196+
- There are performance bottlenecks with transforms being recalculated too eagerly
197+
- On iOS, you may encounter issues with vertical positioning due to header height information propagation
228198

229-
The [`react-native-navigation`](https://github.com/wix/react-native-navigation) also comes with support for Shared Element Transitions. You can read more about it [here](https://wix.github.io/react-native-navigation/docs/style-animations#shared-element-transitions).
199+
The limitations will be addressed in future Reanimated releases.

0 commit comments

Comments
 (0)