Skip to content

Commit d6af2d8

Browse files
committed
Use tabs for shared element transition examples
1 parent 32e0ed8 commit d6af2d8

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { Button } from '@react-navigation/elements';
5454

5555
import Animated from 'react-native-reanimated';
5656

57+
// codeblock-focus-start
5758
function HomeScreen() {
5859
const navigation = useNavigation();
5960

@@ -87,6 +88,7 @@ function DetailsScreen() {
8788
</View>
8889
);
8990
}
91+
// codeblock-focus-end
9092

9193
const RootStack = createNativeStackNavigator({
9294
screens: {
@@ -117,25 +119,19 @@ You can customize the transition by passing a custom `SharedTransition` configur
117119

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

120-
### Old Architecture (Reanimated 3)
122+
<Tabs groupId="architecture" queryString="architecture">
123+
<TabItem value="new" label="New Architecture (Reanimated 4)">
121124

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()`:
125+
On the New Architecture, the default transition animates `width`, `height`, `originX`, `originY`, `transform`, `backgroundColor`, and `opacity` using `withTiming` with a 500 ms duration.
123126

124-
```jsx
125-
import { SharedTransition, withSpring } from 'react-native-reanimated';
127+
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:
126128

127-
// highlight-start
128-
const customTransition = SharedTransition.custom((values) => {
129-
'worklet';
129+
```jsx
130+
import { SharedTransition } from 'react-native-reanimated';
130131

131-
return {
132-
height: withSpring(values.targetHeight),
133-
width: withSpring(values.targetWidth),
134-
originX: withSpring(values.targetOriginX),
135-
originY: withSpring(values.targetOriginY),
136-
};
137-
});
138-
// highlight-end
132+
// Customize duration and use spring animation
133+
// highlight-next-line
134+
const customTransition = SharedTransition.duration(550).springify();
139135

140136
function HomeScreen() {
141137
return (
@@ -149,18 +145,26 @@ function HomeScreen() {
149145
}
150146
```
151147

152-
### New Architecture (Reanimated 4)
148+
</TabItem>
149+
<TabItem value="old" label="Old Architecture (Reanimated 3)" default>
153150

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:
151+
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()`:
157152

158153
```jsx
159-
import { SharedTransition } from 'react-native-reanimated';
154+
import { SharedTransition, withSpring } from 'react-native-reanimated';
160155

161-
// Customize duration and use spring animation
162-
// highlight-next-line
163-
const customTransition = SharedTransition.duration(550).springify();
156+
// highlight-start
157+
const customTransition = SharedTransition.custom((values) => {
158+
'worklet';
159+
160+
return {
161+
height: withSpring(values.targetHeight),
162+
width: withSpring(values.targetWidth),
163+
originX: withSpring(values.targetOriginX),
164+
originY: withSpring(values.targetOriginY),
165+
};
166+
});
167+
// highlight-end
164168

165169
function HomeScreen() {
166170
return (
@@ -174,6 +178,9 @@ function HomeScreen() {
174178
}
175179
```
176180

181+
</TabItem>
182+
</Tabs>
183+
177184
## Reference
178185

179186
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/).

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { Button } from '@react-navigation/elements';
5454

5555
import Animated from 'react-native-reanimated';
5656

57+
// codeblock-focus-start
5758
function HomeScreen() {
5859
const navigation = useNavigation();
5960

@@ -87,6 +88,7 @@ function DetailsScreen() {
8788
</View>
8889
);
8990
}
91+
// codeblock-focus-end
9092

9193
const RootStack = createNativeStackNavigator({
9294
screens: {

0 commit comments

Comments
 (0)