Skip to content

Commit 186fd16

Browse files
authored
feat: docs update (#8631)
## Summary Updating docs in Reanimated and Worklets to fix outdated info about Reanimated Babel Plugin and the like. ## Test plan πŸš€
1 parent 7b4cbbe commit 186fd16

File tree

20 files changed

+132
-599
lines changed

20 files changed

+132
-599
lines changed

β€Ž.husky/pre-commitβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ for DOCS in docs-reanimated docs-worklets; do
6565
check_and_lint_docs "$STAGED_FILES" "$DOCS_PATH" "$DOCS"
6666
done
6767

68-
# This automatically builds Reanimated Babel plugin JavaScript files if their
68+
# This automatically builds Worklets Babel plugin JavaScript files if their
6969
# TypeScript counterparts were changed. It also adds the output file to the commit
7070
# if the built file differs from currently staged one.
71-
print "Checking for changes in Reanimated Babel plugin source files..."
71+
print "Checking for changes in Worklets Babel plugin source files..."
7272
PLUGIN_PATH="packages/react-native-worklets/plugin"
7373
if echo "$STAGED_FILES" | grep -E "$PLUGIN_PATH" >/dev/null; then
74-
print "Changes spotted. Building Reanimated Babel plugin files..."
74+
print "Changes spotted. Building Worklets Babel plugin files..."
7575

7676
yarn workspace babel-plugin-worklets build
7777

β€Ždocs/docs-reanimated/docs/fundamentals/getting-started.mdxβ€Ž

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,15 @@ Install `react-native-reanimated` and `react-native-worklets` packages from npm:
4848
#### Dependencies
4949

5050
This library requires an installation of the `react-native-worklets` dependency. It was separated from `react-native-reanimated` for better modularity and must be installed separately.
51+
You can read more about Worklets in the [Worklets documentation](https://docs.swmansion.com/react-native-worklets/).
5152

5253
<Tabs groupId="package-managers">
5354
<TabItem value="npm" label="NPM">
5455
{/* TODO - add information about the necessity to specify a proper version of the library compatible with reanimated */}
55-
```bash
56-
npm install react-native-worklets
57-
```
56+
```bash npm install react-native-worklets ```
5857
</TabItem>
5958
<TabItem value="yarn" label="YARN">
60-
```bash
61-
yarn add react-native-worklets
62-
```
59+
```bash yarn add react-native-worklets ```
6360
</TabItem>
6461
</Tabs>
6562

@@ -69,14 +66,10 @@ Run prebuild to update the native code in the `ios` and `android` directories.
6966

7067
<Tabs groupId="package-managers">
7168
<TabItem value="npm" label="NPM">
72-
```bash
73-
npx expo prebuild
74-
```
69+
```bash npx expo prebuild ```
7570
</TabItem>
7671
<TabItem value="yarn" label="YARN">
77-
```bash
78-
yarn expo prebuild
79-
```
72+
```bash yarn expo prebuild ```
8073
</TabItem>
8174
</Tabs>
8275

@@ -107,26 +100,22 @@ When using [React Native Community CLI](https://github.com/react-native-communit
107100
<details>
108101
<summary>Why do I need this?</summary>
109102

110-
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.
103+
In short, the Worklets 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.
111104

112-
Since [Expo SDK 50](https://expo.dev/changelog/2024/01-18-sdk-50), the Expo starter template includes the Reanimated babel plugin by default.
105+
Since [Expo SDK 50](https://expo.dev/changelog/2024/01-18-sdk-50), the Expo starter template includes the Worklets Babel plugin by default.
113106

114-
To learn more about the plugin head onto to [Reanimated babel plugin](/docs/fundamentals/glossary#reanimated-babel-plugin) section.
107+
To learn more about the plugin head onto to [Worklets Babel plugin docs page](https://docs.swmansion.com/react-native-worklets/docs/worklets-babel-plugin/about).
115108

116109
</details>
117110

118111
#### Clear Metro bundler cache (recommended)
119112

120113
<Tabs groupId="package-managers">
121114
<TabItem value="npm" label="NPM">
122-
```bash
123-
npm start -- --reset-cache
124-
```
115+
```bash npm start -- --reset-cache ```
125116
</TabItem>
126117
<TabItem value="yarn" label="YARN">
127-
```bash
128-
yarn start --reset-cache
129-
```
118+
```bash yarn start --reset-cache ```
130119
</TabItem>
131120
</Tabs>
132121

@@ -150,14 +139,10 @@ To use Reanimated on the web all you need to do is to install and add [`@babel/p
150139

151140
<Tabs groupId="package-managers">
152141
<TabItem value="npm" label="NPM">
153-
```bash
154-
npm install @babel/plugin-proposal-export-namespace-from
155-
```
142+
```bash npm install @babel/plugin-proposal-export-namespace-from ```
156143
</TabItem>
157144
<TabItem value="yarn" label="YARN">
158-
```bash
159-
yarn add @babel/plugin-proposal-export-namespace-from
160-
```
145+
```bash yarn add @babel/plugin-proposal-export-namespace-from ```
161146
</TabItem>
162147
</Tabs>
163148

β€Ždocs/docs-reanimated/docs/fundamentals/glossary.mdxβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function onPress() {
170170

171171
To convert a JavaScript function into a serializable object which can be copied and run over on [UI thread](/docs/fundamentals/glossary#ui-thread).
172172

173-
Functions marked with `"worklet";` directive are automatically picked up and workletized by the Reanimated Babel plugin.
173+
Functions marked with `"worklet"` directive are automatically picked up and workletized by the Worklets Babel plugin.
174174

175175
## JavaScript thread
176176

@@ -184,8 +184,8 @@ UI thread is responsible for handling user interface updates. Also known as Main
184184

185185
You can learn more about it by reading the [Threading model](https://reactnative.dev/architecture/threading-model) article in the official React Native docs.
186186

187-
## Reanimated Babel plugin
187+
## Worklets Babel plugin
188188

189189
The plugin performs automatic [workletization](/docs/fundamentals/glossary#to-workletize) of certain functions used with Reanimated to reduce the amount of boilerplate code.
190190

191-
You can learn the details by reading the [Reanimated Babel plugin README](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/plugin/README-dev.md).
191+
You can learn the details by reading the [Worklets docs](https://docs.swmansion.com/react-native-worklets/docs/worklets-babel-plugin/about).

β€Ždocs/docs-reanimated/docs/guides/debugging-worklets.mdxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ _Warnings about mismatched patch versions can be safely ignored if the patch was
181181
You may choose either `Reanimated Runtime` or `Reanimated Runtime experimental
182182
(Improved Chrome Reloads)`, but we recommend the latter.
183183

184-
_Debugging relies on source maps that are generated by the Reanimated Babel plugin, so you
184+
_Debugging relies on source maps that are generated by the Worklets Babel plugin, so you
185185
might have to run `yarn start --reset-cache` for those changes to take effect.
186186
In case it still doesn't work after that please reinstall the app and reset metro
187187
cache once again._
@@ -247,7 +247,7 @@ _Warnings about mismatched patch versions can be safely ignored if the patch was
247247

248248
![Screenshot showing the plugin working](/img/debugging/flipper3.png)
249249

250-
_Debugging relies on source maps that are generated by the Reanimated Babel plugin, so you
250+
_Debugging relies on source maps that are generated by the Worklets Babel plugin, so you
251251
might have to run `yarn start --reset-cache` for those changes to take effect.
252252
In case it still doesn't work after that please reinstall the app and reset metro
253253
cache once again._

β€Ždocs/docs-reanimated/docs/guides/troubleshooting.mdxβ€Ž

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ sidebar_label: Troubleshooting
88

99
## Initialization issues
1010

11-
Reanimated has four core components that compose its code:
11+
Reanimated has three core components that compose its code:
1212

1313
- C++,
1414
- Java,
15-
- JavaScript,
16-
- Reanimated Babel plugin.
15+
- JavaScript.
16+
17+
It also depends on React Native Worklets and its Worklets Babel plugin.
1718

1819
All of them are supposed to work correctly only within the same minor version. Therefore, having any of those pieces in your code - directly or indirectly - separate from `react-native-reanimated`, especially having any code transpiled with a different version of the aforementioned plugin will result in undefined behavior and errors.
1920

2021
### Failed to create a worklet
2122

22-
**Problem:** This usually happens when Reanimated is not properly installed, e.g. forgetting to include the Reanimated Babel plugin in `babel.config.js`.
23+
**Problem:** This usually happens when Reanimated is not properly installed, e.g. forgetting to include the Worklets Babel plugin in `babel.config.js`.
2324

24-
**Solution:** See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/#step-2-add-reanimateds-babel-plugin for more information.
25+
**Solution:** See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/#react-native-community-cli for more information.
2526

2627
### Native part of Reanimated doesn't seem to be initialized
2728

@@ -63,7 +64,7 @@ See [Couldn't determine the version of the native part of Reanimated](#couldnt-d
6364

6465
### Mismatch between C++ code version and JavaScript code version
6566

66-
See [Mismatch between JavaScript part and native part of Reanimated](#mismatch-between-javascript-part-and-native-part-of-reanimated) and [Mismatch between JavaScript code version and Reanimated Babel plugin version](https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version).
67+
See [Mismatch between JavaScript part and native part of Reanimated](#mismatch-between-javascript-part-and-native-part-of-reanimated) and [Mismatch between JavaScript code version and Worklets Babel plugin version](https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version).
6768

6869
### C++ side failed to resolve Java code version
6970

β€Ždocs/docs-reanimated/docs/guides/worklets.mdxβ€Ž

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ sidebar_position: 1
66

77
# Worklets
88

9-
Worklets are short-running JavaScript functions that can run on the [UI thread](/docs/fundamentals/glossary#ui-thread). Reanimated uses worklets to calculate view styles and react to events on the UI thread.
9+
Worklet is a short-running JavaScript function that can be moved and executed across different Javascript Runtimes. Reanimated uses worklets to calculate view styles and react to events on the UI thread.
1010

1111
## Defining worklets
1212

13-
You can create your own worklets using the `'worklet';` directive at the top of a function.
13+
You can create your own worklets using the `'worklet'` directive at the top of a function.
1414

1515
```javascript
1616
function myWorklet() {
@@ -21,7 +21,7 @@ function myWorklet() {
2121

2222
## Workletization
2323

24-
The [Reanimated Babel Plugin](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/plugin/README-dev.md#basics) looks for functions marked with the `'worklet'` directive and converts them into serializable objects. We call this process [workletization](/docs/fundamentals/glossary#to-workletize). These objects can then be copied and run over on the UI thread.
24+
The [Worklets Babel plugin](https://docs.swmansion.com/react-native-worklets/docs/worklets-babel-plugin/about) looks for functions marked with the `'worklet'` directive and converts them into serializable objects. We call this process [workletization](/docs/fundamentals/glossary#to-workletize). These objects can then be copied and run over on the UI thread.
2525

2626
Most of the time when working with Reanimated and [Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler/) the code is automatically workletized and run on the UI thread by default.
2727

@@ -36,9 +36,9 @@ function App() {
3636
}
3737
```
3838

39-
## Running worklets on the UI thread
39+
## Running worklets on the UI Runtime (UI Thread)
4040

41-
You can use [`runOnUI`](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI) to manually schedule worklet execution on the UI thread:
41+
You can use [`scheduleOnUI`](https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnUI) to manually schedule worklet execution on the UI Runtime:
4242

4343
```javascript
4444
function myWorklet() {
@@ -47,7 +47,7 @@ function myWorklet() {
4747
}
4848

4949
function onPress() {
50-
runOnUI(myWorklet)();
50+
scheduleOnUI(myWorklet);
5151
}
5252
```
5353

@@ -60,13 +60,13 @@ function myWorklet(greeting) {
6060
}
6161

6262
function onPress() {
63-
runOnUI(myWorklet)('Howdy');
63+
scheduleOnUI(myWorklet, 'Howdy');
6464
}
6565
```
6666

6767
## Running functions from worklets
6868

69-
You can run functions on the JS thread from the UI thread with [`runOnJS`](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnJS). Most frequently used to call functions that aren't marked with a `'worklet';` directive (i.e. most third-party libraries) or to update the React state.
69+
You can run functions on the RN Runtime (JS thread) from the UI Runtime (UI thread) with [`scheduleOnRN`](https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnRN). Most frequently used to call functions that aren't marked with a `'worklet';` directive (i.e. most third-party libraries) or to update the React state.
7070

7171
```javascript
7272
import { router } from 'expo-router';
@@ -76,26 +76,26 @@ function App() {
7676
const tap = Gesture.Tap().onEnd(() => {
7777
// i'm a worklet too!
7878
// highlight-next-line
79-
runOnJS(router.back)();
79+
scheduleOnRN(router.back);
8080
});
8181
}
8282
```
8383

84-
Functions passed to `runOnJS` must be defined in the [JavaScript thread](/docs/fundamentals/glossary#javascript-thread) scope, i.e. in the component body or the global scope. This code won't work because `myFunction` is defined in the `withTiming` callback, which is only executed in the [UI thread](/docs/fundamentals/glossary#ui-thread):
84+
Functions passed to `scheduleOnRN` must be defined in the [JavaScript thread](/docs/fundamentals/glossary#javascript-thread) scope, i.e. in the component body or the global scope. This code won't work because `myFunction` is defined in the `withTiming` callback, which is only executed in the [UI Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime):
8585

8686
```javascript
8787
function App() {
8888
const tap = Gesture.Tap().onEnd(() => {
89-
// myFunction is defined on the UI thread 🚨
89+
// myFunction is defined on the UI runtime 🚨
9090
const myFunction = () => {};
91-
runOnJS(myFunction)(); // πŸ’₯
91+
scheduleOnRN(myFunction); // πŸ’₯
9292
});
9393
}
9494
```
9595

9696
## Hoisting
9797

98-
Functions marked with `'worklet';` aren't [hoisted](https://developer.mozilla.org/en-US/docs/Glossary/Hoisting). Besides affecting hoisting, the `'worklet';` directive has no effect on the [JavaScript thread](/docs/fundamentals/glossary#javascript-thread).
98+
Functions marked with `'worklet'` aren't [hoisted](https://developer.mozilla.org/en-US/docs/Glossary/Hoisting). Besides affecting hoisting, the `'worklet'` directive has no effect on the [RN Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#react-native-runtime-rn-runtime).
9999

100100
## Capturing closure
101101

@@ -173,10 +173,10 @@ function App() {
173173

174174
There's no separate UI thread available on the Web. Because of that, when Reanimated runs in the browser, worklets are resolved to plain JavaScript functions.
175175

176-
However, the `'worklet';` directive is still necessary on the Web, because Reanimated relies on the Babel plugin to capture dependencies inside worklet functions.
176+
However, the `'worklet'` directive is still necessary on the Web, because Reanimated relies on the Worklets Babel plugin to capture dependencies inside worklet functions.
177177

178178
## Other worklet runtimes
179179

180-
Worklets can run in other runtimes than the one provided by Reanimated. For example [VisionCamera](https://github.com/mrousavy/react-native-vision-camera) and [LiveMarkdown](https://github.com/Expensify/react-native-live-markdown) create their own worklet runtimes.
180+
Worklets can run in other runtimes than the one provided by React Native Worklets. For example [VisionCamera](https://github.com/mrousavy/react-native-vision-camera) and [LiveMarkdown](https://github.com/Expensify/react-native-live-markdown) create their own worklet runtimes.
181181

182182
You can create your own worklet runtimes with [`createWorkletRuntime`](https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime) function.

0 commit comments

Comments
Β (0)