You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs-reanimated/docs/fundamentals/getting-started.mdx
+12-27Lines changed: 12 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,18 +48,15 @@ Install `react-native-reanimated` and `react-native-worklets` packages from npm:
48
48
#### Dependencies
49
49
50
50
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/).
51
52
52
53
<TabsgroupId="package-managers">
53
54
<TabItemvalue="npm"label="NPM">
54
55
{/* 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 ```
58
57
</TabItem>
59
58
<TabItemvalue="yarn"label="YARN">
60
-
```bash
61
-
yarn add react-native-worklets
62
-
```
59
+
```bash yarn add react-native-worklets ```
63
60
</TabItem>
64
61
</Tabs>
65
62
@@ -69,14 +66,10 @@ Run prebuild to update the native code in the `ios` and `android` directories.
69
66
70
67
<TabsgroupId="package-managers">
71
68
<TabItemvalue="npm"label="NPM">
72
-
```bash
73
-
npx expo prebuild
74
-
```
69
+
```bash npx expo prebuild ```
75
70
</TabItem>
76
71
<TabItemvalue="yarn"label="YARN">
77
-
```bash
78
-
yarn expo prebuild
79
-
```
72
+
```bash yarn expo prebuild ```
80
73
</TabItem>
81
74
</Tabs>
82
75
@@ -107,26 +100,22 @@ When using [React Native Community CLI](https://github.com/react-native-communit
107
100
<details>
108
101
<summary>Why do I need this?</summary>
109
102
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.
111
104
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.
113
106
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).
115
108
116
109
</details>
117
110
118
111
#### Clear Metro bundler cache (recommended)
119
112
120
113
<TabsgroupId="package-managers">
121
114
<TabItemvalue="npm"label="NPM">
122
-
```bash
123
-
npm start -- --reset-cache
124
-
```
115
+
```bash npm start -- --reset-cache ```
125
116
</TabItem>
126
117
<TabItemvalue="yarn"label="YARN">
127
-
```bash
128
-
yarn start --reset-cache
129
-
```
118
+
```bash yarn start --reset-cache ```
130
119
</TabItem>
131
120
</Tabs>
132
121
@@ -150,14 +139,10 @@ To use Reanimated on the web all you need to do is to install and add [`@babel/p
Copy file name to clipboardExpand all lines: docs/docs-reanimated/docs/fundamentals/glossary.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,7 +170,7 @@ function onPress() {
170
170
171
171
To convert a JavaScript function into a serializable object which can be copied and run over on [UI thread](/docs/fundamentals/glossary#ui-thread).
172
172
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.
174
174
175
175
## JavaScript thread
176
176
@@ -184,8 +184,8 @@ UI thread is responsible for handling user interface updates. Also known as Main
184
184
185
185
You can learn more about it by reading the [Threading model](https://reactnative.dev/architecture/threading-model) article in the official React Native docs.
186
186
187
-
## Reanimated Babel plugin
187
+
## Worklets Babel plugin
188
188
189
189
The plugin performs automatic [workletization](/docs/fundamentals/glossary#to-workletize) of certain functions used with Reanimated to reduce the amount of boilerplate code.
190
190
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).
Copy file name to clipboardExpand all lines: docs/docs-reanimated/docs/guides/troubleshooting.mdx
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,20 +8,21 @@ sidebar_label: Troubleshooting
8
8
9
9
## Initialization issues
10
10
11
-
Reanimated has four core components that compose its code:
11
+
Reanimated has three core components that compose its code:
12
12
13
13
- C++,
14
14
- Java,
15
-
- JavaScript,
16
-
- Reanimated Babel plugin.
15
+
- JavaScript.
16
+
17
+
It also depends on React Native Worklets and its Worklets Babel plugin.
17
18
18
19
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.
19
20
20
21
### Failed to create a worklet
21
22
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`.
23
24
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.
25
26
26
27
### Native part of Reanimated doesn't seem to be initialized
27
28
@@ -63,7 +64,7 @@ See [Couldn't determine the version of the native part of Reanimated](#couldnt-d
63
64
64
65
### Mismatch between C++ code version and JavaScript code version
65
66
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).
Copy file name to clipboardExpand all lines: docs/docs-reanimated/docs/guides/worklets.mdx
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,11 @@ sidebar_position: 1
6
6
7
7
# Worklets
8
8
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.
10
10
11
11
## Defining worklets
12
12
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.
14
14
15
15
```javascript
16
16
functionmyWorklet() {
@@ -21,7 +21,7 @@ function myWorklet() {
21
21
22
22
## Workletization
23
23
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.
25
25
26
26
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.
27
27
@@ -36,9 +36,9 @@ function App() {
36
36
}
37
37
```
38
38
39
-
## Running worklets on the UI thread
39
+
## Running worklets on the UI Runtime (UI Thread)
40
40
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:
42
42
43
43
```javascript
44
44
functionmyWorklet() {
@@ -47,7 +47,7 @@ function myWorklet() {
47
47
}
48
48
49
49
functiononPress() {
50
-
runOnUI(myWorklet)();
50
+
scheduleOnUI(myWorklet);
51
51
}
52
52
```
53
53
@@ -60,13 +60,13 @@ function myWorklet(greeting) {
60
60
}
61
61
62
62
functiononPress() {
63
-
runOnUI(myWorklet)('Howdy');
63
+
scheduleOnUI(myWorklet, 'Howdy');
64
64
}
65
65
```
66
66
67
67
## Running functions from worklets
68
68
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.
70
70
71
71
```javascript
72
72
import { router } from'expo-router';
@@ -76,26 +76,26 @@ function App() {
76
76
consttap=Gesture.Tap().onEnd(() => {
77
77
// i'm a worklet too!
78
78
// highlight-next-line
79
-
runOnJS(router.back)();
79
+
scheduleOnRN(router.back);
80
80
});
81
81
}
82
82
```
83
83
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):
85
85
86
86
```javascript
87
87
functionApp() {
88
88
consttap=Gesture.Tap().onEnd(() => {
89
-
// myFunction is defined on the UI thread π¨
89
+
// myFunction is defined on the UI runtime π¨
90
90
constmyFunction= () => {};
91
-
runOnJS(myFunction)(); // π₯
91
+
scheduleOnRN(myFunction); // π₯
92
92
});
93
93
}
94
94
```
95
95
96
96
## Hoisting
97
97
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).
99
99
100
100
## Capturing closure
101
101
@@ -173,10 +173,10 @@ function App() {
173
173
174
174
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.
175
175
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.
177
177
178
178
## Other worklet runtimes
179
179
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.
181
181
182
182
You can create your own worklet runtimes with [`createWorkletRuntime`](https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime) function.
0 commit comments