@react-native-ohos/react-native-reanimated 3.18.1-rc.6 → 3.18.2-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +10 -10
  4. package/harmony/reanimated/BuildProfile.ets +16 -16
  5. package/harmony/reanimated/build-profile.json5 +11 -11
  6. package/harmony/reanimated/oh-package.json5 +11 -11
  7. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +68 -68
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +96 -87
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -252
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +173 -155
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +189 -182
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
  80. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
  81. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
  82. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +7 -0
  83. package/harmony/reanimated/src/main/module.json5 +12 -12
  84. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  85. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  86. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  87. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  88. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  89. package/harmony/reanimated/ts.ts +6 -6
  90. package/harmony/reanimated.har +0 -0
  91. package/package.json +50 -50
@@ -1,191 +1,191 @@
1
- # Hermes Runtime initialization
2
-
3
- _Last updated_: 13/09/2022 by @Kwasow
4
-
5
- This document describes the current way of initializing Hermes and connecting
6
- it to the debugger. The work I did was mainly based on
7
-
8
- [HermesExecutorFactory.cpp](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp)
9
- from React Native.
10
-
11
- ## Runtime initialization
12
-
13
- If you take a look at `NativeProxy` (both on Android and iOS) you'll find
14
- that it only makes a call to `ReanimatedRuntime::make(jsQueue)`. This
15
- static function will return the correct runtime based on the user's configuration.
16
-
17
- The initialization process is pretty simple and has only been moved out of
18
- `NativeProxy` into `ReanimatedRuntime` without any major changes.
19
-
20
- ## Hermes runtime debugging
21
-
22
- To enable debugging on the Hermes runtime we need to do two things:
23
-
24
- 1. Include source maps in JavaScript files
25
-
26
- This part is done purely in JavaScript via the Babel plugin. The `makeWorklet`
27
- function received an AST tree, which is aware of the modifications it made to
28
- the code and therefore can generate the necessary source maps. It is important
29
- that when we want to create a string from the AST we use the `generate` function
30
- and enable source map generation so line mappings are not lost. Then when
31
- transforming that code (ex. with `transformSync`) we have to pass the source
32
- map as input so it can be updated.
33
-
34
- Source map settings should always be set to `inline` so they are automatically
35
- appended to the source code. The generated source map will be a base64 encoded
36
- json.
37
-
38
- A workletized function would look like this (after formattings):
39
-
40
- ```js
41
- function _f(number) {
42
- console.log(_WORKLET, number);
43
- }
44
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBYXNCLFNBQUNBLEVBQUQsQ0FBQ0EsTUFBRCxFQUFvQjtBQUV0Q0MsU0FBTyxDQUFDQyxHQUFSRCxDQUFZRSxRQUFaRixFQUFzQkQsTUFBdEJDO0FBRmtCIiwibmFtZXMiOlsibnVtYmVyIiwiY29uc29sZSIsImxvZyIsIl9XT1JLTEVUIl0sInNvdXJjZXMiOlsiL1VzZXJzL2thcm9sL0dpdC9yZWFjdC1uYXRpdmUtcmVhbmltYXRlZC9GYWJyaWNFeGFtcGxlL3NyYy9Xb3JrbGV0RXhhbXBsZS50c3giXSwic291cmNlc0NvbnRlbnQiOlsiLyogZ2xvYmFsIF9XT1JLTEVUICovXG5pbXBvcnQgeyBCdXR0b24sIFZpZXcsIFN0eWxlU2hlZXQgfSBmcm9tICdyZWFjdC1uYXRpdmUnO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XtoYW5kbGVQcmVzczF9IHRpdGxlPVwicnVuT25VSSBkZW1vXCIgLz5cbiAgICAgIDxCdXR0b24gb25QcmVzcz17aGFuZGxlUHJlc3MyfSB0aXRsZT1cInJ1bk9uSlMgZGVtb1wiIC8+XG4gICAgPC9WaWV3PlxuICApO1xufVxuXG5jb25zdCBzdHlsZXMgPSBTdHlsZVNoZWV0LmNyZWF0ZSh7XG4gIGNvbnRhaW5lcjoge1xuICAgIGZsZXg6IDEsXG4gICAgYWxpZ25JdGVtczogJ2NlbnRlcicsXG4gICAganVzdGlmeUNvbnRlbnQ6ICdjZW50ZXInLFxuICB9LFxufSk7XG4iXX0=
45
- ```
46
-
47
- And the base64 string after decoding is:
48
-
49
- ```json
50
- {
51
- "version": 3,
52
- "mappings": "AAasB,SAACA,EAAD,CAACA,MAAD,EAAoB;AAEtCC,SAAO,CAACC,GAARD,CAAYE,QAAZF,EAAsBD,MAAtBC;AAFkB",
53
- "names": ["number", "console", "log", "_WORKLET"],
54
- "sources": [
55
- "/Users/karol/Git/react-native-reanimated/FabricExample/src/WorkletExample.tsx"
56
- ],
57
- "sourcesContent": [
58
- "/* global _WORKLET */\nimport { Button, View, StyleSheet } from 'react-native';\nimport {\n runOnJS,\n runOnUI,\n useDerivedValue,\n useSharedValue,\n} from 'react-native-reanimated';\n\nimport React from 'react';\n\nexport default function WorkletExample() {\n // runOnUI demo\n const someWorklet = (number: number) => {\n 'worklet';\n console.log(_WORKLET, number); // _WORKLET should be true\n };\n\n const handlePress1 = () => {\n runOnUI(someWorklet)(Math.random());\n };\n\n // runOnJS demo\n const x = useSharedValue(0);\n\n const someFunction = (number: number) => {\n console.log(_WORKLET, number); // _WORKLET should be false\n };\n\n useDerivedValue(() => {\n runOnJS(someFunction)(x.value);\n });\n\n const handlePress2 = () => {\n x.value = Math.random();\n };\n\n return (\n <View style={styles.container}>\n <Button onPress={handlePress1} title=\"runOnUI demo\" />\n <Button onPress={handlePress2} title=\"runOnJS demo\" />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n },\n});\n"
59
- ]
60
- }
61
- ```
62
-
63
- We run jest tests in release mode, because source maps will contain absolute
64
- paths, which will be different on every machine and therefore would also alter
65
- worklet hashes. Running in release mode prevents this.
66
-
67
- 2. Enable debugging on the runtime object
68
-
69
- This is done by creating an adapter (`HermesExecutorRuntimeAdapter` inside of
70
- `ReanimatedHermesRuntime.cpp`) which holds the runtime and allows the debugger
71
- to communicate with it. The adapter is managed by a `Connection` (`ConnectionDemux`)
72
- object, but this is not important in our case. We just have to make a call
73
- to `facebook::hermes::inspector::chrome::enableDebugging()` and pass the adapter
74
- and runtime name as parameters.
75
-
76
- It is important to also `disableDebugging()` before the runtime is destroyed.
77
- Failing to do so will probably crash the app as the debugger will try to
78
- connect to a non-existent runtime.
79
-
80
- The runtime should also be destroyed before the Reanimated module, because
81
- otherwise there might be weird BAD_ACCESS errors when the gc gets it
82
- hand on the runtime.
83
-
84
- ## Metro endpoint
85
-
86
- Flipper and Chrome DevTools in general use the `localhost:8081/json` (where `8081`
87
- is the port metro is running on) endpoint of metro to get the list of debuggable
88
- targets (runtimes). For a normal React Native app the output would look something
89
- like this:
90
-
91
- ```json
92
- [
93
- {
94
- "id": "0-1",
95
- "description": "org.reactjs.native.example.FabricExample",
96
- "title": "Hermes React Native",
97
- "faviconUrl": "https://reactjs.org/favicon.ico",
98
- "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D1",
99
- "type": "node",
100
- "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=0&page=1",
101
- "vm": "Hermes"
102
- },
103
- {
104
- "id": "0--1",
105
- "description": "org.reactjs.native.example.FabricExample",
106
- "title": "React Native Experimental (Improved Chrome Reloads)",
107
- "faviconUrl": "https://reactjs.org/favicon.ico",
108
- "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-1",
109
- "type": "node",
110
- "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=0&page=-1",
111
- "vm": "don't use"
112
- }
113
- ]
114
- ```
115
-
116
- For an Android app with Reanimated it should include the Reanimated runtime like
117
- this:
118
-
119
- ```json
120
- [
121
- {
122
- "id": "0-2",
123
- "description": "com.fabricexample",
124
- "title": "Reanimated Runtime",
125
- "faviconUrl": "https://reactjs.org/favicon.ico",
126
- "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D3",
127
- "type": "node",
128
- "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=2",
129
- "vm": "Hermes"
130
- },
131
- {
132
- "id": "0-1",
133
- "description": "com.fabricexample",
134
- "title": "Hermes React Native",
135
- "faviconUrl": "https://reactjs.org/favicon.ico",
136
- "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D2",
137
- "type": "node",
138
- "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=1",
139
- "vm": "Hermes"
140
- },
141
- {
142
- "id": "0--1",
143
- "description": "com.fabricexample",
144
- "title": "React Native Experimental (Improved Chrome Reloads)",
145
- "faviconUrl": "https://reactjs.org/favicon.ico",
146
- "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-1",
147
- "type": "node",
148
- "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=-1",
149
- "vm": "don't use"
150
- },
151
- {
152
- "id": "0--2",
153
- "description": "com.fabricexample",
154
- "title": "Reanimated Runtime Experimental (Improved Chrome Reloads)",
155
- "faviconUrl": "https://reactjs.org/favicon.ico",
156
- "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-2",
157
- "type": "node",
158
- "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=-2",
159
- "vm": "don't use"
160
- }
161
- ]
162
- ```
163
-
164
- Runtimes with negative IDs are 'virtual' - they are just references to the real
165
- runtimes but their IDs don't change after a reload. If we were to connect to
166
- the normal runtime and reload the app it would crash, as the debugger would try
167
- to communicate with a non-existent runtime. These 'virtual' runtimes are made
168
- and managed by metro (PR: [facebook/metro#864](https://github.com/facebook/metro/pull/864)).
169
-
170
- ## Known issues
171
-
172
- **IFrame sandboxing**
173
-
174
- Source maps always define a `sources` array, which contain names of files used
175
- to generate the source map. For Chrome DevTools this is sufficient as it will
176
- read files from disk, but the `IFrame` interface used by Flipper is sandboxed
177
- and doesn't allow filesystem access. Therefore we also need to include the files
178
- content in the `sourcesContent` array.
179
-
180
- **Chrome version 105.0.5195.102 doesn't load source maps**
181
-
182
- This version of Chrome introduced a regression into DevTools that broke source
183
- maps loading for node.js apps. This issue is not caused by Reanimated in any
184
- way and should be fixed by Chrome developers in later versions.
185
-
186
- The issue was tracked here: https://bugs.chromium.org/p/chromium/issues/detail?id=1358497
187
-
188
- **App reloads don't work**
189
-
190
- On iOS the app will crash on every reload if a debugger is connected to the runtime.
191
- On Android it will also crash but only after a few reloads.
1
+ # Hermes Runtime initialization
2
+
3
+ _Last updated_: 13/09/2022 by @Kwasow
4
+
5
+ This document describes the current way of initializing Hermes and connecting
6
+ it to the debugger. The work I did was mainly based on
7
+
8
+ [HermesExecutorFactory.cpp](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp)
9
+ from React Native.
10
+
11
+ ## Runtime initialization
12
+
13
+ If you take a look at `NativeProxy` (both on Android and iOS) you'll find
14
+ that it only makes a call to `ReanimatedRuntime::make(jsQueue)`. This
15
+ static function will return the correct runtime based on the user's configuration.
16
+
17
+ The initialization process is pretty simple and has only been moved out of
18
+ `NativeProxy` into `ReanimatedRuntime` without any major changes.
19
+
20
+ ## Hermes runtime debugging
21
+
22
+ To enable debugging on the Hermes runtime we need to do two things:
23
+
24
+ 1. Include source maps in JavaScript files
25
+
26
+ This part is done purely in JavaScript via the Babel plugin. The `makeWorklet`
27
+ function received an AST tree, which is aware of the modifications it made to
28
+ the code and therefore can generate the necessary source maps. It is important
29
+ that when we want to create a string from the AST we use the `generate` function
30
+ and enable source map generation so line mappings are not lost. Then when
31
+ transforming that code (ex. with `transformSync`) we have to pass the source
32
+ map as input so it can be updated.
33
+
34
+ Source map settings should always be set to `inline` so they are automatically
35
+ appended to the source code. The generated source map will be a base64 encoded
36
+ json.
37
+
38
+ A workletized function would look like this (after formattings):
39
+
40
+ ```js
41
+ function _f(number) {
42
+ console.log(_WORKLET, number);
43
+ }
44
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBYXNCLFNBQUNBLEVBQUQsQ0FBQ0EsTUFBRCxFQUFvQjtBQUV0Q0MsU0FBTyxDQUFDQyxHQUFSRCxDQUFZRSxRQUFaRixFQUFzQkQsTUFBdEJDO0FBRmtCIiwibmFtZXMiOlsibnVtYmVyIiwiY29uc29sZSIsImxvZyIsIl9XT1JLTEVUIl0sInNvdXJjZXMiOlsiL1VzZXJzL2thcm9sL0dpdC9yZWFjdC1uYXRpdmUtcmVhbmltYXRlZC9GYWJyaWNFeGFtcGxlL3NyYy9Xb3JrbGV0RXhhbXBsZS50c3giXSwic291cmNlc0NvbnRlbnQiOlsiLyogZ2xvYmFsIF9XT1JLTEVUICovXG5pbXBvcnQgeyBCdXR0b24sIFZpZXcsIFN0eWxlU2h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J9PlxuICAgICAgPEJ1dHRvbiBvblByZXNzPXtoYW5kbGVQcmVzczF9IHRpdGxlPVwicnVuT25VSSBkZW1vXCIgLz5cbiAgICAgIDxCdXR0b24gb25QcmVzcz17aGFuZGxlUHJlc3MyfSB0aXRsZT1cInJ1bk9uSlMgZGVtb1wiIC8+XG4gICAgPC9WaWV3PlxuICApO1xufVxuXG5jb25zdCBzdHlsZXMgPSBTdHlsZVNoZWV0LmNyZWF0ZSh7XG4gIGNvbnRhaW5lcjoge1xuICAgIGZsZXg6IDEsXG4gICAgYWxpZ25JdGVtczogJ2NlbnRlcicsXG4gICAganVzdGlmeUNvbnRlbnQ6ICdjZW50ZXInLFxuICB9LFxufSk7XG4iXX0=
45
+ ```
46
+
47
+ And the base64 string after decoding is:
48
+
49
+ ```json
50
+ {
51
+ "version": 3,
52
+ "mappings": "AAasB,SAACA,EAAD,CAACA,MAAD,EAAoB;AAEtCC,SAAO,CAACC,GAARD,CAAYE,QAAZF,EAAsBD,MAAtBC;AAFkB",
53
+ "names": ["number", "console", "log", "_WORKLET"],
54
+ "sources": [
55
+ "/Users/karol/Git/react-native-reanimated/FabricExample/src/WorkletExample.tsx"
56
+ ],
57
+ "sourcesContent": [
58
+ "/* global _WORKLET */\nimport { Button, View, StyleSheet } from 'react-native';\nimport {\n runOnJS,\n runOnUI,\n useDerivedValue,\n useSharedValue,\n} from 'react-native-reanimated';\n\nimport React from 'react';\n\nexport default function WorkletExample() {\n // runOnUI demo\n const someWorklet = (number: number) => {\n 'worklet';\n console.log(_WORKLET, number); // _WORKLET should be true\n };\n\n const handlePress1 = () => {\n runOnUI(someWorklet)(Math.random());\n };\n\n // runOnJS demo\n const x = useSharedValue(0);\n\n const someFunction = (number: number) => {\n console.log(_WORKLET, number); // _WORKLET should be false\n };\n\n useDerivedValue(() => {\n runOnJS(someFunction)(x.value);\n });\n\n const handlePress2 = () => {\n x.value = Math.random();\n };\n\n return (\n <View style={styles.container}>\n <Button onPress={handlePress1} title=\"runOnUI demo\" />\n <Button onPress={handlePress2} title=\"runOnJS demo\" />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n },\n});\n"
59
+ ]
60
+ }
61
+ ```
62
+
63
+ We run jest tests in release mode, because source maps will contain absolute
64
+ paths, which will be different on every machine and therefore would also alter
65
+ worklet hashes. Running in release mode prevents this.
66
+
67
+ 2. Enable debugging on the runtime object
68
+
69
+ This is done by creating an adapter (`HermesExecutorRuntimeAdapter` inside of
70
+ `ReanimatedHermesRuntime.cpp`) which holds the runtime and allows the debugger
71
+ to communicate with it. The adapter is managed by a `Connection` (`ConnectionDemux`)
72
+ object, but this is not important in our case. We just have to make a call
73
+ to `facebook::hermes::inspector::chrome::enableDebugging()` and pass the adapter
74
+ and runtime name as parameters.
75
+
76
+ It is important to also `disableDebugging()` before the runtime is destroyed.
77
+ Failing to do so will probably crash the app as the debugger will try to
78
+ connect to a non-existent runtime.
79
+
80
+ The runtime should also be destroyed before the Reanimated module, because
81
+ otherwise there might be weird BAD_ACCESS errors when the gc gets it
82
+ hand on the runtime.
83
+
84
+ ## Metro endpoint
85
+
86
+ Flipper and Chrome DevTools in general use the `localhost:8081/json` (where `8081`
87
+ is the port metro is running on) endpoint of metro to get the list of debuggable
88
+ targets (runtimes). For a normal React Native app the output would look something
89
+ like this:
90
+
91
+ ```json
92
+ [
93
+ {
94
+ "id": "0-1",
95
+ "description": "org.reactjs.native.example.FabricExample",
96
+ "title": "Hermes React Native",
97
+ "faviconUrl": "https://reactjs.org/favicon.ico",
98
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D1",
99
+ "type": "node",
100
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=0&page=1",
101
+ "vm": "Hermes"
102
+ },
103
+ {
104
+ "id": "0--1",
105
+ "description": "org.reactjs.native.example.FabricExample",
106
+ "title": "React Native Experimental (Improved Chrome Reloads)",
107
+ "faviconUrl": "https://reactjs.org/favicon.ico",
108
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-1",
109
+ "type": "node",
110
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=0&page=-1",
111
+ "vm": "don't use"
112
+ }
113
+ ]
114
+ ```
115
+
116
+ For an Android app with Reanimated it should include the Reanimated runtime like
117
+ this:
118
+
119
+ ```json
120
+ [
121
+ {
122
+ "id": "0-2",
123
+ "description": "com.fabricexample",
124
+ "title": "Reanimated Runtime",
125
+ "faviconUrl": "https://reactjs.org/favicon.ico",
126
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D3",
127
+ "type": "node",
128
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=2",
129
+ "vm": "Hermes"
130
+ },
131
+ {
132
+ "id": "0-1",
133
+ "description": "com.fabricexample",
134
+ "title": "Hermes React Native",
135
+ "faviconUrl": "https://reactjs.org/favicon.ico",
136
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D2",
137
+ "type": "node",
138
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=1",
139
+ "vm": "Hermes"
140
+ },
141
+ {
142
+ "id": "0--1",
143
+ "description": "com.fabricexample",
144
+ "title": "React Native Experimental (Improved Chrome Reloads)",
145
+ "faviconUrl": "https://reactjs.org/favicon.ico",
146
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-1",
147
+ "type": "node",
148
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=-1",
149
+ "vm": "don't use"
150
+ },
151
+ {
152
+ "id": "0--2",
153
+ "description": "com.fabricexample",
154
+ "title": "Reanimated Runtime Experimental (Improved Chrome Reloads)",
155
+ "faviconUrl": "https://reactjs.org/favicon.ico",
156
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-2",
157
+ "type": "node",
158
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=-2",
159
+ "vm": "don't use"
160
+ }
161
+ ]
162
+ ```
163
+
164
+ Runtimes with negative IDs are 'virtual' - they are just references to the real
165
+ runtimes but their IDs don't change after a reload. If we were to connect to
166
+ the normal runtime and reload the app it would crash, as the debugger would try
167
+ to communicate with a non-existent runtime. These 'virtual' runtimes are made
168
+ and managed by metro (PR: [facebook/metro#864](https://github.com/facebook/metro/pull/864)).
169
+
170
+ ## Known issues
171
+
172
+ **IFrame sandboxing**
173
+
174
+ Source maps always define a `sources` array, which contain names of files used
175
+ to generate the source map. For Chrome DevTools this is sufficient as it will
176
+ read files from disk, but the `IFrame` interface used by Flipper is sandboxed
177
+ and doesn't allow filesystem access. Therefore we also need to include the files
178
+ content in the `sourcesContent` array.
179
+
180
+ **Chrome version 105.0.5195.102 doesn't load source maps**
181
+
182
+ This version of Chrome introduced a regression into DevTools that broke source
183
+ maps loading for node.js apps. This issue is not caused by Reanimated in any
184
+ way and should be fixed by Chrome developers in later versions.
185
+
186
+ The issue was tracked here: https://bugs.chromium.org/p/chromium/issues/detail?id=1358497
187
+
188
+ **App reloads don't work**
189
+
190
+ On iOS the app will crash on every reload if a debugger is connected to the runtime.
191
+ On Android it will also crash but only after a few reloads.