Skip to content

Commit 4e47778

Browse files
docs: update Reanimated 4 docs (#6931)
This PR updates Reanimated 4 documentation: - updates installation steps in Getting Started - removes `paper-example` mentions from Contributing - documents `textShadow` style props behavior --------- Co-authored-by: Mateusz Łopaciński <[email protected]>
1 parent 7b1b339 commit 4e47778

File tree

3 files changed

+109
-75
lines changed

3 files changed

+109
-75
lines changed

packages/docs-reanimated/docs/fundamentals/getting-started.mdx

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,51 @@ With Reanimated, you can easily create smooth animations and interactions that r
2020
Reanimated 4.x works only with [the React Native New Architecture (Fabric)](https://reactnative.dev/architecture/landing-page).
2121
If your app still uses the old architecture, you can use Reanimated in version 3 which is still actively maintained.
2222

23-
## Quick start
23+
Alternatively, you can dive into [our examples](https://github.com/software-mansion/react-native-reanimated/tree/3.14.0/apps/common-app/src/examples) on GitHub.
24+
25+
## Installation
26+
27+
It takes two steps to add Reanimated 4 to an Expo project:
28+
29+
### Step 1: Install the package
2430

25-
If you don't have an existing project, you can create a new Expo app using a template:
31+
Install `react-native-reanimated@next` package from npm:
2632

2733
<Tabs groupId="package-managers">
2834
<TabItem value="npm" label="NPM">
2935

30-
npx create-expo-app@latest my-app -e with-reanimated
36+
npm install react-native-reanimated@next
3137

3238
</TabItem>
3339
<TabItem value="yarn" label="YARN">
3440

35-
yarn create expo-app my-app -e with-reanimated
41+
yarn add react-native-reanimated@next
3642

3743
</TabItem>
3844
</Tabs>
3945

40-
Alternatively, you can dive into [our examples](https://github.com/software-mansion/react-native-reanimated/tree/3.14.0/apps/common-app/src/examples) on GitHub.
41-
42-
## Installation
46+
### Step 2: Rebuild native dependencies
4347

44-
It takes three steps to add Reanimated to a project:
45-
46-
### Step 1: Install the package
47-
48-
Install `react-native-reanimated` package from npm:
48+
Run prebuild to update the native code in the `ios` and `android` directories.
4949

5050
<Tabs groupId="package-managers">
51-
<TabItem value="expo" label="EXPO" default>
52-
53-
npx expo install react-native-reanimated
54-
55-
</TabItem>
5651
<TabItem value="npm" label="NPM">
5752

58-
npm install react-native-reanimated
53+
npx expo prebuild
5954

6055
</TabItem>
6156
<TabItem value="yarn" label="YARN">
6257

63-
yarn add react-native-reanimated
58+
yarn expo prebuild
6459

6560
</TabItem>
6661
</Tabs>
6762

68-
### Step 2: Add Reanimated's babel plugin
63+
And that's it! Reanimated 4 is now configured in your Expo project.
64+
65+
### React Native Community CLI
6966

70-
Add `react-native-reanimated/plugin` plugin to your `babel.config.js`.
67+
When using [React Native Community CLI](https://github.com/react-native-community/cli), you also need to manually add the `react-native-reanimated/plugin` plugin to your `babel.config.js`.
7168

7269
```js {7}
7370
module.exports = {
@@ -92,44 +89,15 @@ Add `react-native-reanimated/plugin` plugin to your `babel.config.js`.
9289

9390
In short, the Reanimated babel plugin automatically converts special JavaScript functions (called [worklets](/docs/fundamentals/glossary#worklet)) to allow them to be passed and run on the UI thread.
9491

95-
To learn more about the plugin head onto to [Reanimated babel plugin](/docs/fundamentals/glossary#reanimated-babel-plugin) section.
96-
97-
</details>
98-
99-
### Step 3: Wrap metro config with reanimated wrapper (recommended)
100-
101-
Wrap your existing Metro configuration in the `metro.config.js` file with the `wrapWithReanimatedMetroConfig` function.
92+
Since [Expo SDK 50](https://expo.dev/changelog/2024/01-18-sdk-50), the Expo starter template includes the Reanimated babel plugin by default.
10293

103-
```js
104-
// metro.config.js
105-
const {
106-
wrapWithReanimatedMetroConfig,
107-
} = require('react-native-reanimated/metro-config');
108-
109-
const config = {
110-
// Your existing Metro configuration options
111-
};
112-
113-
module.exports = wrapWithReanimatedMetroConfig(config);
114-
```
115-
116-
<details>
117-
<summary>Why should I do this?</summary>
118-
119-
Wrapping your Metro configuration with the Reanimated Metro config wrapper will result in displaying improved reanimated errors and warnings with more accurate call stacks. Thanks to this, identifying misuses of the Reanimated API will be much easier than before.
120-
121-
To learn more about this feature, head onto to [Accurate Call Stacks](/docs/debugging/accurate-call-stacks).
94+
To learn more about the plugin head onto to [Reanimated babel plugin](/docs/fundamentals/glossary#reanimated-babel-plugin) section.
12295

12396
</details>
12497

125-
### Step 4: Clear Metro bundler cache (recommended)
98+
#### Clear Metro bundler cache (recommended)
12699

127100
<Tabs groupId="package-managers">
128-
<TabItem value="expo" label="EXPO" default>
129-
130-
npx expo start -c
131-
132-
</TabItem>
133101
<TabItem value="npm" label="NPM">
134102

135103
npm start -- --reset-cache
@@ -142,16 +110,6 @@ To learn more about this feature, head onto to [Accurate Call Stacks](/docs/debu
142110
</TabItem>
143111
</Tabs>
144112

145-
### Expo development build
146-
147-
When using an [Expo development build](https://docs.expo.dev/develop/development-builds/introduction/), run prebuild to update the native code in the `ios` and `android` directories.
148-
149-
```bash
150-
npx expo prebuild
151-
```
152-
153-
### Platform specific setup
154-
155113
#### Android
156114

157115
No additional steps are necessary.
@@ -171,11 +129,6 @@ For building apps that target web using [react-native-web](https://www.npmjs.com
171129
To use Reanimated on the web all you need to do is to install and add [`@babel/plugin-proposal-export-namespace-from`](https://babeljs.io/docs/en/babel-plugin-proposal-export-namespace-from) Babel plugin to your `babel.config.js`.
172130

173131
<Tabs groupId="package-managers">
174-
<TabItem value="expo" label="EXPO" default>
175-
176-
npx expo install @babel/plugin-proposal-export-namespace-from
177-
178-
</TabItem>
179132
<TabItem value="npm" label="NPM">
180133

181134
npm install @babel/plugin-proposal-export-namespace-from

packages/docs-reanimated/docs/guides/contributing.mdx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ The React Native Reanimated repository is a monorepo with the following structur
2525
```
2626
├── apps
2727
│ ├── common-app // shared source code of example apps
28-
│ ├── paper-example // React Native app wrapper running the Old Architecture for shared examples
2928
│ ├── fabric-example // React Native app wrapper running the New Architecture for shared examples
3029
│ ├── macos-example // React Native for MacOS app wrapper for shared example code
3130
│ ├── next-example // Next.js wrapper for shared example code
@@ -34,6 +33,7 @@ The React Native Reanimated repository is a monorepo with the following structur
3433
└── packages
3534
├── docs-reanimated // documentation described further in Helping with documentation
3635
├── eslint-plugin-reanimated // source of eslint plugin
36+
├── react-native-worklets // source of worklets package
3737
└── react-native-reanimated
3838
├── android // source code of Android native implementation
3939
├── apple // source code of iOS native implementation
@@ -215,7 +215,19 @@ We have shared code of example app, that is run on different platforms and archi
215215
- `packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated` &ndash; containing source code related to Android native part of Reanimated features
216216
- `packages/react-native-reanimated/apple` &ndash; containing source code related to iOS native part of Reanimated features
217217

218-
Our workflow usually starts from editing `apps/common-app/src/examples/EmptyExample.tsx` with testing example for our new feature or a bug. This is the part that we often attach to PR so other developers can test the same use-case (remember not to commit your changes from `EmptyExample` file!). Next, we run the `apps/paper-example` (or `apps/fabric-example` depending on the architecture) app and start development.
218+
We use two separate example apps depending on the feature or a bug we're currently working on. If the code relates to CSS Animations then we start from editing
219+
220+
```
221+
apps/common-app/src/apps/css/examples/animations/screens/testExamples/Playground.tsx
222+
```
223+
224+
For other features like worklet API, Layout Animations and Shared Element Transitions we would usually start from editing
225+
226+
```
227+
apps/common-app/src/apps/reanimated/examples/EmptyExample.tsx
228+
```
229+
230+
This is the part that we often attach to PR so other developers can test the same use-case (remember not to commit your changes from `Playground`/`EmptyExample` file!). Next, we run the `apps/fabric-example` app and start development.
219231

220232
:::info
221233

@@ -228,10 +240,10 @@ If you want to implement a new feature or fix a bug, but still are unsure after
228240
To start with, let's install all dependencies:
229241

230242
1. `yarn && yarn build`
231-
2. `cd apps/paper-example`
243+
2. `cd apps/fabric-example`
232244
3. `yarn start` &ndash; make sure to start metro bundler before building the app in Android Studio.
233245

234-
and open `react-native-reanimated/apps/paper-example/android` with Android Studio.
246+
and open `react-native-reanimated/apps/fabric-example/android` with Android Studio.
235247

236248
<img src={useBaseUrl('/img/contributing/android_studio.png')} />
237249

@@ -242,10 +254,10 @@ The native source code of Reanimated can be found in `react-native-reanimated` m
242254
To begin with, let's install all the necessary dependencies:
243255

244256
1. `yarn && yarn build`
245-
2. `(cd apps/paper-example/ios && bundle install && bundle exec pod install)` &ndash; install Pods for iOS
246-
3. `cd apps/paper-example && yarn start` &ndash; make sure to start metro bundler before building the app in Xcode.
257+
2. `(cd apps/fabric-example/ios && bundle install && bundle exec pod install)` &ndash; install Pods for iOS
258+
3. `cd apps/fabric-example && yarn start` &ndash; make sure to start metro bundler before building the app in Xcode.
247259

248-
and open `react-native-reanimated/apps/paper-example/ios/ReanimatedExample.xcworkspace` with Xcode.
260+
and open `react-native-reanimated/apps/fabric-example/ios/ReanimatedExample.xcworkspace` with Xcode.
249261

250262
<img src={useBaseUrl('/img/contributing/xcode.png')} />
251263

packages/docs-reanimated/docs/guides/supported-properties.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,72 @@ Yoga calculates borders in different ways for numeric values and relative (%) va
182182
### flexBasis
183183

184184
Even though changes of this property are calculated properly during the animation, they aren't applied to the view. Other flex properties, such as `flexGrow` and `flexShrink` work fine, so they could be used for animations.
185+
186+
### Animating text shadow styles
187+
188+
On the web, all text shadow styles (i.e. `textShadowColor`, `textShadowOffset`, `textShadowRadius`) need to be specified in the animation keyframes to preserve the style during animation.
189+
190+
iOS and Android text shadow styles doesn't have this limitations and work as intended.
191+
192+
So, for example, if we want to have a shadow color and animate the shadow radius, we can't specify `textShadowColor` just in the element style but we also have to add it to every keyframe of the animation, even though only the `textShadowRadius` is the style we want to animate. Consider this:
193+
194+
```jsx
195+
<Animated.Text
196+
style={{
197+
animationName: {
198+
from: {
199+
textShadowRadius: 8, // while the shadow radius correctly animates from 8 ✅
200+
},
201+
to: {
202+
textShadowRadius: 16, // to 16 ✅
203+
},
204+
},
205+
textShadowColor: 'red', // 🚨 the shadow color would be overridden in the animation keyframes
206+
// that means the shadow would be black!
207+
}}>
208+
Reanimated
209+
</Animated.Text>
210+
```
211+
212+
To mitigate this limitation, you need to specify the `textShadowColor` in every keyframe definition:
213+
214+
```jsx
215+
<Animated.Text
216+
style={{
217+
animationName: {
218+
from: {
219+
textShadowColor: 'red', // shadows starts 'red'
220+
textShadowRadius: 8,
221+
},
222+
to: {
223+
textShadowColor: 'red', // and keeps being 'red' throughout the animation
224+
textShadowRadius: 16,
225+
},
226+
},
227+
}}>
228+
Reanimated
229+
</Animated.Text>
230+
```
231+
232+
<details>
233+
<summary>Why do I need this?</summary>
234+
235+
In CSS the `text-shadow` is a single property but in React Native that's three separate properties for color, offset and radius. Because of that Reanimated has to provide these default values to every keyframe definition:
236+
237+
```json
238+
{
239+
"textShadowColor": "#000",
240+
"textShadowRadius": 0,
241+
"textShadowOffset": { "width": 0, "height": 0 }
242+
}
243+
```
244+
245+
and the shadow styles aren't inherited from the style object provided to the element. To retain the styles in an animation you need to override these styles to achieve your expected result.
246+
247+
</details>
248+
249+
### Animating box shadow styles
250+
251+
Similarly to the text shadow styles - all shadow styles (i.e. `shadowColor`, `shadowOffset`, `shadowOpacity`, `shadowRadius`) need to be specified in the animation keyframes to preserve the style during animation on the Web. Keep in mind that `shadowOffset`, `shadowOpacity`, `shadowRadius` style properties [aren't implemented on Android in React Native](https://reactnative.dev/docs/shadow-props#props) so they also can't be animated.
252+
253+
We highly recommend to use [the `boxShadow` property](https://reactnative.dev/blog/2024/10/23/release-0.76-new-architecture#boxshadow) which doesn't have this limitation and also works on Android.

0 commit comments

Comments
 (0)