react-native-reanimated 3.0.0-rc.7 → 3.0.0-rc.9

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 (207) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
  4. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +168 -167
  6. package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
  8. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
  9. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +30 -0
  10. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +1 -1
  11. package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
  12. package/Common/cpp/SharedItems/Shareables.cpp +144 -0
  13. package/Common/cpp/SharedItems/Shareables.h +470 -0
  14. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
  15. package/Common/cpp/Tools/RuntimeDecorator.cpp +79 -50
  16. package/Common/cpp/Tools/RuntimeDecorator.h +13 -3
  17. package/Common/cpp/Tools/Scheduler.cpp +10 -0
  18. package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
  19. package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
  20. package/android/src/main/cpp/LayoutAnimations.h +4 -4
  21. package/android/src/main/cpp/NativeProxy.cpp +50 -63
  22. package/ios/LayoutReanimation/REAAnimationsManager.h +3 -1
  23. package/ios/LayoutReanimation/REAAnimationsManager.m +49 -16
  24. package/ios/LayoutReanimation/REAUIManager.mm +22 -62
  25. package/ios/native/NativeProxy.mm +26 -42
  26. package/lib/commonjs/createAnimatedComponent.js +7 -11
  27. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  28. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  29. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  30. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
  31. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  32. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
  33. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  34. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  35. package/lib/commonjs/reanimated2/commonTypes.js +7 -0
  36. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  37. package/lib/commonjs/reanimated2/component/FlatList.js +19 -3
  38. package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
  39. package/lib/commonjs/reanimated2/core.js +74 -240
  40. package/lib/commonjs/reanimated2/core.js.map +1 -1
  41. package/lib/commonjs/reanimated2/errors.js +66 -0
  42. package/lib/commonjs/reanimated2/errors.js.map +1 -0
  43. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  44. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
  45. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  46. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
  47. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  48. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
  49. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  50. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +23 -59
  51. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  52. package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
  53. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  54. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  55. package/lib/commonjs/reanimated2/initializers.js +157 -0
  56. package/lib/commonjs/reanimated2/initializers.js.map +1 -0
  57. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  58. package/lib/commonjs/reanimated2/jestUtils.js +8 -33
  59. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  60. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +14 -103
  61. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  62. package/lib/commonjs/reanimated2/js-reanimated/global.js +4 -7
  63. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  64. package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
  65. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  66. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  67. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  68. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +87 -0
  69. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  70. package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
  71. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  72. package/lib/commonjs/reanimated2/mappers.js +186 -0
  73. package/lib/commonjs/reanimated2/mappers.js.map +1 -0
  74. package/lib/commonjs/reanimated2/mock.js +26 -0
  75. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  76. package/lib/commonjs/reanimated2/mutables.js +173 -0
  77. package/lib/commonjs/reanimated2/mutables.js.map +1 -0
  78. package/lib/commonjs/reanimated2/shareables.js +159 -0
  79. package/lib/commonjs/reanimated2/shareables.js.map +1 -0
  80. package/lib/commonjs/reanimated2/threads.js +58 -0
  81. package/lib/commonjs/reanimated2/threads.js.map +1 -0
  82. package/lib/commonjs/reanimated2/time.js +55 -0
  83. package/lib/commonjs/reanimated2/time.js.map +1 -0
  84. package/lib/commonjs/reanimated2/valueSetter.js +81 -0
  85. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
  86. package/lib/module/createAnimatedComponent.js +7 -12
  87. package/lib/module/createAnimatedComponent.js.map +1 -1
  88. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  89. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  90. package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
  91. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  92. package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
  93. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  94. package/lib/module/reanimated2/animation/util.js.map +1 -1
  95. package/lib/module/reanimated2/commonTypes.js +7 -0
  96. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  97. package/lib/module/reanimated2/component/FlatList.js +18 -4
  98. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  99. package/lib/module/reanimated2/core.js +33 -226
  100. package/lib/module/reanimated2/core.js.map +1 -1
  101. package/lib/module/reanimated2/errors.js +58 -0
  102. package/lib/module/reanimated2/errors.js.map +1 -0
  103. package/lib/module/reanimated2/globals.d.js.map +1 -1
  104. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
  105. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  106. package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
  107. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  108. package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
  109. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  110. package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -62
  111. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  112. package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
  113. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  114. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  115. package/lib/module/reanimated2/initializers.js +143 -0
  116. package/lib/module/reanimated2/initializers.js.map +1 -0
  117. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  118. package/lib/module/reanimated2/jestUtils.js +8 -31
  119. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  120. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +14 -98
  121. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  122. package/lib/module/reanimated2/js-reanimated/global.js +4 -7
  123. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  124. package/lib/module/reanimated2/js-reanimated/index.js +5 -0
  125. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  126. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  127. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  128. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +82 -0
  129. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  130. package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
  131. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  132. package/lib/module/reanimated2/mappers.js +173 -0
  133. package/lib/module/reanimated2/mappers.js.map +1 -0
  134. package/lib/module/reanimated2/mock.js +26 -0
  135. package/lib/module/reanimated2/mock.js.map +1 -1
  136. package/lib/module/reanimated2/mutables.js +149 -0
  137. package/lib/module/reanimated2/mutables.js.map +1 -0
  138. package/lib/module/reanimated2/shareables.js +138 -0
  139. package/lib/module/reanimated2/shareables.js.map +1 -0
  140. package/lib/module/reanimated2/threads.js +45 -0
  141. package/lib/module/reanimated2/threads.js.map +1 -0
  142. package/lib/module/reanimated2/time.js +37 -0
  143. package/lib/module/reanimated2/time.js.map +1 -0
  144. package/lib/module/reanimated2/valueSetter.js +66 -0
  145. package/lib/module/reanimated2/valueSetter.js.map +1 -0
  146. package/package.json +3 -2
  147. package/plugin.js +112 -30
  148. package/src/createAnimatedComponent.tsx +8 -24
  149. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +43 -53
  150. package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
  151. package/src/reanimated2/WorkletEventHandler.ts +4 -11
  152. package/src/reanimated2/animation/util.ts +1 -0
  153. package/src/reanimated2/commonTypes.ts +29 -4
  154. package/src/reanimated2/component/FlatList.tsx +30 -5
  155. package/src/reanimated2/core.ts +68 -258
  156. package/src/reanimated2/errors.ts +57 -0
  157. package/src/reanimated2/globals.d.ts +48 -29
  158. package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
  159. package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
  160. package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
  161. package/src/reanimated2/hook/useAnimatedStyle.ts +26 -74
  162. package/src/reanimated2/hook/useSharedValue.ts +6 -3
  163. package/src/reanimated2/hook/utils.ts +1 -1
  164. package/src/reanimated2/initializers.ts +143 -0
  165. package/src/reanimated2/interpolateColor.ts +2 -2
  166. package/src/reanimated2/jestUtils.ts +14 -29
  167. package/src/reanimated2/js-reanimated/JSReanimated.ts +24 -94
  168. package/src/reanimated2/js-reanimated/global.ts +4 -7
  169. package/src/reanimated2/js-reanimated/index.ts +4 -0
  170. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
  171. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  172. package/src/reanimated2/layoutReanimation/animationsManager.ts +91 -0
  173. package/src/reanimated2/layoutReanimation/index.ts +1 -1
  174. package/src/reanimated2/mappers.ts +179 -0
  175. package/src/reanimated2/mock.ts +105 -0
  176. package/src/reanimated2/mutables.ts +151 -0
  177. package/src/reanimated2/shareables.ts +128 -0
  178. package/src/reanimated2/threads.ts +46 -0
  179. package/src/reanimated2/time.ts +30 -0
  180. package/src/reanimated2/valueSetter.ts +64 -0
  181. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
  182. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
  183. package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
  184. package/Common/cpp/Registries/MapperRegistry.h +0 -29
  185. package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
  186. package/Common/cpp/Registries/WorkletsCache.h +0 -24
  187. package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
  188. package/Common/cpp/SharedItems/FrozenObject.h +0 -36
  189. package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
  190. package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
  191. package/Common/cpp/SharedItems/MutableValue.h +0 -54
  192. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
  193. package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
  194. package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
  195. package/Common/cpp/SharedItems/RemoteObject.h +0 -35
  196. package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
  197. package/Common/cpp/SharedItems/ShareableValue.h +0 -63
  198. package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
  199. package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
  200. package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
  201. package/Common/cpp/Tools/Mapper.cpp +0 -86
  202. package/Common/cpp/Tools/Mapper.h +0 -51
  203. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
  204. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  205. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
  206. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  207. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
@@ -19,84 +19,37 @@
19
19
 
20
20
  #include "EventHandlerRegistry.h"
21
21
  #include "FeaturesConfig.h"
22
- #include "FrozenObject.h"
23
- #include "JSIStoreValueUser.h"
24
- #include "Mapper.h"
25
- #include "MapperRegistry.h"
26
- #include "MutableValue.h"
27
22
  #include "ReanimatedHiddenHeaders.h"
28
23
  #include "RuntimeDecorator.h"
29
- #include "ShareableValue.h"
24
+ #include "Shareables.h"
30
25
  #include "WorkletEventHandler.h"
31
26
 
32
27
  using namespace facebook;
33
28
 
34
29
  namespace reanimated {
35
30
 
36
- void extractMutables(
37
- jsi::Runtime &rt,
38
- std::shared_ptr<ShareableValue> sv,
39
- std::vector<std::shared_ptr<MutableValue>> &res) {
40
- switch (sv->type) {
41
- case ValueType::MutableValueType: {
42
- auto &mutableValue = ValueWrapper::asMutableValue(sv->valueContainer);
43
- res.push_back(mutableValue);
44
- break;
45
- }
46
- case ValueType::FrozenArrayType:
47
- for (auto &it : ValueWrapper::asFrozenArray(sv->valueContainer)) {
48
- extractMutables(rt, it, res);
49
- }
50
- break;
51
- case ValueType::RemoteObjectType:
52
- case ValueType::FrozenObjectType:
53
- for (auto &it : ValueWrapper::asFrozenObject(sv->valueContainer)->map) {
54
- extractMutables(rt, it.second, res);
55
- }
56
- break;
57
- default:
58
- break;
59
- }
60
- }
61
-
62
- std::vector<std::shared_ptr<MutableValue>> extractMutablesFromArray(
63
- jsi::Runtime &rt,
64
- const jsi::Array &array,
65
- NativeReanimatedModule *module) {
66
- std::vector<std::shared_ptr<MutableValue>> res;
67
- for (size_t i = 0, size = array.size(rt); i < size; i++) {
68
- auto shareable =
69
- ShareableValue::adapt(rt, array.getValueAtIndex(rt, i), module);
70
- extractMutables(rt, shareable, res);
71
- }
72
- return res;
73
- }
74
-
75
31
  NativeReanimatedModule::NativeReanimatedModule(
76
- std::shared_ptr<CallInvoker> jsInvoker,
77
- std::shared_ptr<Scheduler> scheduler,
78
- std::shared_ptr<jsi::Runtime> rt,
79
- std::shared_ptr<ErrorHandler> errorHandler,
32
+ const std::shared_ptr<CallInvoker> &jsInvoker,
33
+ const std::shared_ptr<Scheduler> &scheduler,
34
+ const std::shared_ptr<jsi::Runtime> &rt,
35
+ const std::shared_ptr<ErrorHandler> &errorHandler,
80
36
  #ifdef RCT_NEW_ARCH_ENABLED
81
37
  // nothing
82
38
  #else
83
39
  std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)>
84
40
  propObtainer,
85
41
  #endif
86
- std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy,
87
42
  PlatformDepMethodsHolder platformDepMethodsHolder)
88
43
  : NativeReanimatedModuleSpec(jsInvoker),
89
44
  RuntimeManager(rt, errorHandler, scheduler, RuntimeType::UI),
90
- layoutAnimationsProxy_(layoutAnimationsProxy),
91
- mapperRegistry(std::make_shared<MapperRegistry>()),
92
- eventHandlerRegistry(std::make_shared<EventHandlerRegistry>()),
45
+ eventHandlerRegistry(std::make_unique<EventHandlerRegistry>()),
93
46
  requestRender(platformDepMethodsHolder.requestRender),
94
47
  #ifdef RCT_NEW_ARCH_ENABLED
95
48
  // nothing
96
49
  #else
97
50
  propObtainer(propObtainer),
98
51
  #endif
99
- animatedSensorModule(platformDepMethodsHolder, this),
52
+ animatedSensorModule(platformDepMethodsHolder),
100
53
  #ifdef RCT_NEW_ARCH_ENABLED
101
54
  synchronouslyUpdateUIPropsFunction(
102
55
  platformDepMethodsHolder.synchronouslyUpdateUIPropsFunction)
@@ -105,12 +58,58 @@ NativeReanimatedModule::NativeReanimatedModule(
105
58
  platformDepMethodsHolder.configurePropsFunction)
106
59
  #endif
107
60
  {
108
- auto requestAnimationFrame = [=](FrameCallback callback) {
109
- frameCallbacks.push_back(callback);
61
+ auto requestAnimationFrame = [=](jsi::Runtime &rt, const jsi::Value &fn) {
62
+ auto jsFunction = std::make_shared<jsi::Value>(rt, fn);
63
+ frameCallbacks.push_back([=](double timestamp) {
64
+ runtimeHelper->runOnUIGuarded(*jsFunction, jsi::Value(timestamp));
65
+ });
110
66
  maybeRequestRender();
111
67
  };
112
68
 
113
- this->layoutAnimationsProxy_ = layoutAnimationsProxy;
69
+ auto scheduleOnJS = [this](
70
+ jsi::Runtime &rt,
71
+ const jsi::Value &remoteFun,
72
+ const jsi::Value &argsValue) {
73
+ auto shareableRemoteFun = extractShareableOrThrow<ShareableRemoteFunction>(
74
+ rt,
75
+ remoteFun,
76
+ "Incompatible object passed to scheduleOnJS. It is only allowed to schedule functions defined on the React Native JS runtime this way.");
77
+ auto shareableArgs = argsValue.isUndefined()
78
+ ? nullptr
79
+ : extractShareableOrThrow(rt, argsValue);
80
+ auto jsRuntime = this->runtimeHelper->rnRuntime();
81
+ this->scheduler->scheduleOnJS([=] {
82
+ jsi::Runtime &rt = *jsRuntime;
83
+ auto remoteFun = shareableRemoteFun->getJSValue(rt);
84
+ if (shareableArgs == nullptr) {
85
+ // fast path for remote function w/o arguments
86
+ remoteFun.asObject(rt).asFunction(rt).call(rt);
87
+ } else {
88
+ auto argsArray = shareableArgs->getJSValue(rt).asObject(rt).asArray(rt);
89
+ auto argsSize = argsArray.size(rt);
90
+ // number of arguments is typically relatively small so it is ok to
91
+ // to use VLAs here, hence disabling the lint rule
92
+ jsi::Value args[argsSize]; // NOLINT(runtime/arrays)
93
+ for (size_t i = 0; i < argsSize; i++) {
94
+ args[i] = argsArray.getValueAtIndex(rt, i);
95
+ }
96
+ remoteFun.asObject(rt).asFunction(rt).call(rt, args, argsSize);
97
+ }
98
+ });
99
+ };
100
+
101
+ auto makeShareableClone = [this](jsi::Runtime &rt, const jsi::Value &value) {
102
+ return this->makeShareableClone(rt, value);
103
+ };
104
+
105
+ auto updateDataSynchronously =
106
+ [this](
107
+ jsi::Runtime &rt,
108
+ const jsi::Value &synchronizedDataHolderRef,
109
+ const jsi::Value &newData) {
110
+ return this->updateDataSynchronously(
111
+ rt, synchronizedDataHolderRef, newData);
112
+ };
114
113
 
115
114
  #ifdef RCT_NEW_ARCH_ENABLED
116
115
  auto updateProps = [this](
@@ -151,11 +150,15 @@ NativeReanimatedModule::NativeReanimatedModule(
151
150
  platformDepMethodsHolder.scrollToFunction,
152
151
  #endif
153
152
  requestAnimationFrame,
153
+ scheduleOnJS,
154
+ makeShareableClone,
155
+ updateDataSynchronously,
154
156
  platformDepMethodsHolder.getCurrentTime,
155
157
  platformDepMethodsHolder.registerSensor,
156
158
  platformDepMethodsHolder.unregisterSensor,
157
159
  platformDepMethodsHolder.setGestureStateFunction,
158
- layoutAnimationsProxy);
160
+ platformDepMethodsHolder.progressLayoutAnimation,
161
+ platformDepMethodsHolder.endLayoutAnimation);
159
162
  onRenderCallback = [this](double timestampMs) {
160
163
  this->renderRequested = false;
161
164
  this->onRender(timestampMs);
@@ -174,87 +177,111 @@ NativeReanimatedModule::NativeReanimatedModule(
174
177
 
175
178
  void NativeReanimatedModule::installCoreFunctions(
176
179
  jsi::Runtime &rt,
177
- const jsi::Value &valueSetter) {
178
- this->valueSetter = ShareableValue::adapt(rt, valueSetter, this);
180
+ const jsi::Value &callGuard,
181
+ const jsi::Value &valueUnpacker) {
182
+ if (!runtimeHelper) {
183
+ // initialize runtimeHelper here if not already present. We expect only one
184
+ // instace of the helper to exists.
185
+ runtimeHelper =
186
+ std::make_shared<JSRuntimeHelper>(&rt, this->runtime.get(), scheduler);
187
+ }
188
+ runtimeHelper->callGuard =
189
+ std::make_unique<CoreFunction>(runtimeHelper.get(), callGuard);
190
+ runtimeHelper->valueUnpacker =
191
+ std::make_unique<CoreFunction>(runtimeHelper.get(), valueUnpacker);
192
+ }
193
+
194
+ NativeReanimatedModule::~NativeReanimatedModule() {
195
+ if (runtimeHelper) {
196
+ runtimeHelper->callGuard = nullptr;
197
+ runtimeHelper->valueUnpacker = nullptr;
198
+ // event handler registry and frame callbacks store some JSI values from UI
199
+ // runtime, so they have to go away before we tear down the runtime
200
+ eventHandlerRegistry.reset();
201
+ frameCallbacks.clear();
202
+ runtime.reset();
203
+ // make sure uiRuntimeDestroyed is set after the runtime is deallocated
204
+ runtimeHelper->uiRuntimeDestroyed = true;
205
+ }
179
206
  }
180
207
 
181
- jsi::Value NativeReanimatedModule::makeShareable(
208
+ void NativeReanimatedModule::scheduleOnUI(
182
209
  jsi::Runtime &rt,
183
- const jsi::Value &value) {
184
- return ShareableValue::adapt(rt, value, this)->getValue(rt);
210
+ const jsi::Value &worklet) {
211
+ auto shareableWorklet = extractShareableOrThrow(rt, worklet);
212
+ assert(
213
+ shareableWorklet->valueType() == Shareable::WorkletType &&
214
+ "only worklets can be scheduled to run on UI");
215
+ scheduler->scheduleOnUI([=] {
216
+ jsi::Runtime &rt = *runtimeHelper->uiRuntime();
217
+ auto workletValue = shareableWorklet->getJSValue(rt);
218
+ runtimeHelper->runOnUIGuarded(workletValue);
219
+ });
185
220
  }
186
221
 
187
- jsi::Value NativeReanimatedModule::makeMutable(
222
+ jsi::Value NativeReanimatedModule::makeSynchronizedDataHolder(
188
223
  jsi::Runtime &rt,
189
- const jsi::Value &value) {
190
- return ShareableValue::adapt(rt, value, this, ValueType::MutableValueType)
191
- ->getValue(rt);
224
+ const jsi::Value &initialShareable) {
225
+ auto dataHolder = std::make_shared<ShareableSynchronizedDataHolder>(
226
+ runtimeHelper, rt, initialShareable);
227
+ return dataHolder->getJSValue(rt);
192
228
  }
193
229
 
194
- jsi::Value NativeReanimatedModule::makeRemote(
230
+ void NativeReanimatedModule::updateDataSynchronously(
195
231
  jsi::Runtime &rt,
196
- const jsi::Value &value) {
197
- return ShareableValue::adapt(rt, value, this, ValueType::RemoteObjectType)
198
- ->getValue(rt);
232
+ const jsi::Value &synchronizedDataHolderRef,
233
+ const jsi::Value &newData) {
234
+ auto dataHolder = extractShareableOrThrow<ShareableSynchronizedDataHolder>(
235
+ rt, synchronizedDataHolderRef);
236
+ dataHolder->set(rt, newData);
199
237
  }
200
238
 
201
- jsi::Value NativeReanimatedModule::startMapper(
239
+ jsi::Value NativeReanimatedModule::getDataSynchronously(
202
240
  jsi::Runtime &rt,
203
- const jsi::Value &worklet,
204
- const jsi::Value &inputs,
205
- const jsi::Value &outputs,
206
- const jsi::Value &updater,
207
- const jsi::Value &viewDescriptors) {
208
- static unsigned long MAPPER_ID = 1;
209
-
210
- unsigned long newMapperId = MAPPER_ID++;
211
- auto mapperShareable = ShareableValue::adapt(rt, worklet, this);
212
- auto inputMutables =
213
- extractMutablesFromArray(rt, inputs.asObject(rt).asArray(rt), this);
214
- auto outputMutables =
215
- extractMutablesFromArray(rt, outputs.asObject(rt).asArray(rt), this);
216
-
217
- int optimalizationLvl = 0;
218
- auto optimalization =
219
- updater.asObject(rt).getProperty(rt, "__optimalization");
220
- if (optimalization.isNumber()) {
221
- optimalizationLvl = optimalization.asNumber();
222
- }
223
- auto updaterSV = ShareableValue::adapt(rt, updater, this);
224
- auto viewDescriptorsSV = ShareableValue::adapt(rt, viewDescriptors, this);
225
-
226
- scheduler->scheduleOnUI([=] {
227
- auto mapperFunction =
228
- mapperShareable->getValue(*runtime).asObject(*runtime).asFunction(
229
- *runtime);
230
- std::shared_ptr<jsi::Function> mapperFunctionPointer =
231
- std::make_shared<jsi::Function>(std::move(mapperFunction));
232
-
233
- std::shared_ptr<Mapper> mapperPointer = std::make_shared<Mapper>(
234
- this,
235
- newMapperId,
236
- mapperFunctionPointer,
237
- inputMutables,
238
- outputMutables);
239
- if (optimalizationLvl > 0) {
240
- mapperPointer->enableFastMode(
241
- optimalizationLvl, updaterSV, viewDescriptorsSV);
242
- }
243
- mapperRegistry->startMapper(mapperPointer);
244
- maybeRequestRender();
245
- });
246
-
247
- return jsi::Value(static_cast<double>(newMapperId));
241
+ const jsi::Value &synchronizedDataHolderRef) {
242
+ auto dataHolder = extractShareableOrThrow<ShareableSynchronizedDataHolder>(
243
+ rt, synchronizedDataHolderRef);
244
+ return dataHolder->get(rt);
248
245
  }
249
246
 
250
- void NativeReanimatedModule::stopMapper(
247
+ jsi::Value NativeReanimatedModule::makeShareableClone(
251
248
  jsi::Runtime &rt,
252
- const jsi::Value &mapperId) {
253
- unsigned long id = mapperId.asNumber();
254
- scheduler->scheduleOnUI([=] {
255
- mapperRegistry->stopMapper(id);
256
- maybeRequestRender();
257
- });
249
+ const jsi::Value &value) {
250
+ std::shared_ptr<Shareable> shareable;
251
+ if (value.isObject()) {
252
+ auto object = value.asObject(rt);
253
+ if (!object.getProperty(rt, "__workletHash").isUndefined()) {
254
+ shareable = std::make_shared<ShareableWorklet>(runtimeHelper, rt, object);
255
+ } else if (!object.getProperty(rt, "__init").isUndefined()) {
256
+ shareable = std::make_shared<ShareableHandle>(runtimeHelper, rt, object);
257
+ } else if (object.isFunction(rt)) {
258
+ shareable = std::make_shared<ShareableRemoteFunction>(
259
+ runtimeHelper, rt, object.asFunction(rt));
260
+ } else if (object.isArray(rt)) {
261
+ shareable = std::make_shared<ShareableArray>(
262
+ runtimeHelper, rt, object.asArray(rt));
263
+ #ifdef RCT_NEW_ARCH_ENABLED
264
+ } else if (object.isHostObject<ShadowNodeWrapper>(rt)) {
265
+ shareable = std::make_shared<ShareableShadowNodeWrapper>(
266
+ runtimeHelper, rt, object);
267
+ #endif
268
+ } else {
269
+ shareable = std::make_shared<ShareableObject>(runtimeHelper, rt, object);
270
+ }
271
+ } else if (value.isString()) {
272
+ shareable = std::make_shared<ShareableString>(rt, value.asString(rt));
273
+ } else if (value.isUndefined()) {
274
+ shareable = std::make_shared<ShareableScalar>();
275
+ } else if (value.isNull()) {
276
+ shareable = std::make_shared<ShareableScalar>(nullptr);
277
+ } else if (value.isBool()) {
278
+ shareable = std::make_shared<ShareableScalar>(value.getBool());
279
+ } else if (value.isNumber()) {
280
+ shareable = std::make_shared<ShareableScalar>(value.getNumber());
281
+ } else {
282
+ throw std::runtime_error("attempted to convert an unsupported value type");
283
+ }
284
+ return ShareableJSRef::newHostObject(rt, shareable);
258
285
  }
259
286
 
260
287
  jsi::Value NativeReanimatedModule::registerEventHandler(
@@ -265,12 +292,12 @@ jsi::Value NativeReanimatedModule::registerEventHandler(
265
292
 
266
293
  unsigned long newRegistrationId = EVENT_HANDLER_ID++;
267
294
  auto eventName = eventHash.asString(rt).utf8(rt);
268
- auto handlerShareable = ShareableValue::adapt(rt, worklet, this);
295
+ auto handlerShareable = extractShareableOrThrow(rt, worklet);
269
296
 
270
297
  scheduler->scheduleOnUI([=] {
298
+ jsi::Runtime &rt = *runtimeHelper->uiRuntime();
271
299
  auto handlerFunction =
272
- handlerShareable->getValue(*runtime).asObject(*runtime).asFunction(
273
- *runtime);
300
+ handlerShareable->getJSValue(rt).asObject(rt).asFunction(rt);
274
301
  auto handler = std::make_shared<WorkletEventHandler>(
275
302
  newRegistrationId, eventName, std::move(handlerFunction));
276
303
  eventHandlerRegistry->registerEventHandler(handler);
@@ -342,13 +369,11 @@ jsi::Value NativeReanimatedModule::configureLayoutAnimation(
342
369
  jsi::Runtime &rt,
343
370
  const jsi::Value &viewTag,
344
371
  const jsi::Value &type,
345
- const jsi::Value &config,
346
- const jsi::Value &viewSharedValue) {
347
- layoutAnimationsProxy_->configureAnimation(
372
+ const jsi::Value &config) {
373
+ layoutAnimationsManager_.configureAnimation(
348
374
  viewTag.asNumber(),
349
375
  type.asString(rt).utf8(rt),
350
- ShareableValue::adapt(rt, config, this),
351
- ShareableValue::adapt(rt, viewSharedValue, this));
376
+ extractShareableOrThrow(rt, config));
352
377
  return jsi::Value::undefined();
353
378
  }
354
379
 
@@ -366,10 +391,6 @@ void NativeReanimatedModule::onEvent(
366
391
  #else
367
392
  eventHandlerRegistry->processEvent(*runtime, eventName, eventAsString);
368
393
  #endif
369
- mapperRegistry->execute(*runtime);
370
- if (mapperRegistry->needRunOnRender()) {
371
- maybeRequestRender();
372
- }
373
394
  } catch (std::exception &e) {
374
395
  std::string str = e.what();
375
396
  this->errorHandler->setError(str);
@@ -400,11 +421,6 @@ void NativeReanimatedModule::onRender(double timestampMs) {
400
421
  for (auto &callback : callbacks) {
401
422
  callback(timestampMs);
402
423
  }
403
- mapperRegistry->execute(*runtime);
404
-
405
- if (mapperRegistry->needRunOnRender()) {
406
- maybeRequestRender();
407
- }
408
424
  } catch (std::exception &e) {
409
425
  std::string str = e.what();
410
426
  this->errorHandler->setError(str);
@@ -420,9 +436,9 @@ jsi::Value NativeReanimatedModule::registerSensor(
420
436
  jsi::Runtime &rt,
421
437
  const jsi::Value &sensorType,
422
438
  const jsi::Value &interval,
423
- const jsi::Value &sensorDataContainer) {
439
+ const jsi::Value &sensorDataHandler) {
424
440
  return animatedSensorModule.registerSensor(
425
- rt, sensorType, interval, sensorDataContainer);
441
+ rt, runtimeHelper, sensorType, interval, sensorDataHandler);
426
442
  }
427
443
 
428
444
  void NativeReanimatedModule::unregisterSensor(
@@ -645,30 +661,15 @@ void NativeReanimatedModule::setNewestShadowNodesRegistry(
645
661
 
646
662
  jsi::Value NativeReanimatedModule::subscribeForKeyboardEvents(
647
663
  jsi::Runtime &rt,
648
- const jsi::Value &keyboardEventContainer) {
649
- jsi::Object keyboardEventObj = keyboardEventContainer.getObject(rt);
650
- std::unordered_map<std::string, std::shared_ptr<ShareableValue>>
651
- sharedProperties;
652
- std::shared_ptr<ShareableValue> keyboardStateShared = ShareableValue::adapt(
653
- rt, keyboardEventObj.getProperty(rt, "state"), this);
654
- std::shared_ptr<ShareableValue> heightShared = ShareableValue::adapt(
655
- rt, keyboardEventObj.getProperty(rt, "height"), this);
656
-
657
- auto keyboardEventDataUpdater =
658
- [this, &rt, keyboardStateShared, heightShared](
659
- int keyboardState, int height) {
660
- auto &keyboardStateValue =
661
- ValueWrapper::asMutableValue(keyboardStateShared->valueContainer);
662
- keyboardStateValue->setValue(rt, jsi::Value(keyboardState));
663
-
664
- auto &heightMutableValue =
665
- ValueWrapper::asMutableValue(heightShared->valueContainer);
666
- heightMutableValue->setValue(rt, jsi::Value(height));
667
-
668
- this->mapperRegistry->execute(*this->runtime);
669
- };
670
-
671
- return subscribeForKeyboardEventsFunction(keyboardEventDataUpdater);
664
+ const jsi::Value &handlerWorklet) {
665
+ auto shareableHandler = extractShareableOrThrow(rt, handlerWorklet);
666
+ auto uiRuntime = runtimeHelper->uiRuntime();
667
+ return subscribeForKeyboardEventsFunction([=](int keyboardState, int height) {
668
+ jsi::Runtime &rt = *uiRuntime;
669
+ auto handler = shareableHandler->getJSValue(rt);
670
+ handler.asObject(rt).asFunction(rt).call(
671
+ rt, jsi::Value(keyboardState), jsi::Value(height));
672
+ });
672
673
  }
673
674
 
674
675
  void NativeReanimatedModule::unsubscribeFromKeyboardEvents(
@@ -13,7 +13,7 @@
13
13
 
14
14
  #include "AnimatedSensorModule.h"
15
15
  #include "ErrorHandler.h"
16
- #include "LayoutAnimationsProxy.h"
16
+ #include "LayoutAnimationsManager.h"
17
17
  #include "NativeReanimatedModuleSpec.h"
18
18
  #include "PlatformDepMethodsHolder.h"
19
19
  #include "RuntimeDecorator.h"
@@ -25,46 +25,48 @@ namespace reanimated {
25
25
 
26
26
  using FrameCallback = std::function<void(double)>;
27
27
 
28
- class ShareableValue;
29
- class MutableValue;
30
- class MapperRegistry;
31
28
  class EventHandlerRegistry;
32
29
 
33
30
  class NativeReanimatedModule : public NativeReanimatedModuleSpec,
34
31
  public RuntimeManager {
35
- friend ShareableValue;
36
- friend MutableValue;
37
-
38
32
  public:
39
33
  NativeReanimatedModule(
40
- std::shared_ptr<CallInvoker> jsInvoker,
41
- std::shared_ptr<Scheduler> scheduler,
42
- std::shared_ptr<jsi::Runtime> rt,
43
- std::shared_ptr<ErrorHandler> errorHandler,
34
+ const std::shared_ptr<CallInvoker> &jsInvoker,
35
+ const std::shared_ptr<Scheduler> &scheduler,
36
+ const std::shared_ptr<jsi::Runtime> &rt,
37
+ const std::shared_ptr<ErrorHandler> &errorHandler,
44
38
  #ifdef RCT_NEW_ARCH_ENABLED
45
39
  // nothing
46
40
  #else
47
41
  std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)>
48
42
  propObtainer,
49
43
  #endif
50
- std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy,
51
44
  PlatformDepMethodsHolder platformDepMethodsHolder);
52
45
 
53
- void installCoreFunctions(jsi::Runtime &rt, const jsi::Value &valueSetter)
54
- override;
46
+ ~NativeReanimatedModule();
55
47
 
56
- jsi::Value makeShareable(jsi::Runtime &rt, const jsi::Value &value) override;
57
- jsi::Value makeMutable(jsi::Runtime &rt, const jsi::Value &value) override;
58
- jsi::Value makeRemote(jsi::Runtime &rt, const jsi::Value &value) override;
48
+ std::shared_ptr<JSRuntimeHelper> runtimeHelper;
59
49
 
60
- jsi::Value startMapper(
50
+ void installCoreFunctions(
61
51
  jsi::Runtime &rt,
62
- const jsi::Value &worklet,
63
- const jsi::Value &inputs,
64
- const jsi::Value &outputs,
65
- const jsi::Value &updater,
66
- const jsi::Value &viewDescriptors) override;
67
- void stopMapper(jsi::Runtime &rt, const jsi::Value &mapperId) override;
52
+ const jsi::Value &callGuard,
53
+ const jsi::Value &valueUnpacker) override;
54
+
55
+ jsi::Value makeShareableClone(jsi::Runtime &rt, const jsi::Value &value)
56
+ override;
57
+
58
+ jsi::Value makeSynchronizedDataHolder(
59
+ jsi::Runtime &rt,
60
+ const jsi::Value &initialShareable) override;
61
+ jsi::Value getDataSynchronously(
62
+ jsi::Runtime &rt,
63
+ const jsi::Value &synchronizedDataHolderRef) override;
64
+ void updateDataSynchronously(
65
+ jsi::Runtime &rt,
66
+ const jsi::Value &synchronizedDataHolderRef,
67
+ const jsi::Value &newData);
68
+
69
+ void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) override;
68
70
 
69
71
  jsi::Value registerEventHandler(
70
72
  jsi::Runtime &rt,
@@ -86,6 +88,11 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
86
88
  jsi::Runtime &rt,
87
89
  const jsi::Value &uiProps,
88
90
  const jsi::Value &nativeProps) override;
91
+ jsi::Value configureLayoutAnimation(
92
+ jsi::Runtime &rt,
93
+ const jsi::Value &viewTag,
94
+ const jsi::Value &type,
95
+ const jsi::Value &config) override;
89
96
 
90
97
  void onRender(double timestampMs);
91
98
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -144,23 +151,17 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
144
151
  jsi::Runtime &rt,
145
152
  const jsi::Value &listenerId) override;
146
153
 
147
- jsi::Value configureLayoutAnimation(
148
- jsi::Runtime &rt,
149
- const jsi::Value &viewTag,
150
- const jsi::Value &type,
151
- const jsi::Value &config,
152
- const jsi::Value &viewSharedValue) override;
154
+ inline LayoutAnimationsManager &layoutAnimationsManager() {
155
+ return layoutAnimationsManager_;
156
+ }
153
157
 
154
158
  private:
155
159
  #ifdef RCT_NEW_ARCH_ENABLED
156
160
  bool isThereAnyLayoutProp(jsi::Runtime &rt, const jsi::Value &props);
157
161
  #endif // RCT_NEW_ARCH_ENABLED
158
162
 
159
- std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy_;
160
- std::shared_ptr<MapperRegistry> mapperRegistry;
161
- std::shared_ptr<EventHandlerRegistry> eventHandlerRegistry;
163
+ std::unique_ptr<EventHandlerRegistry> eventHandlerRegistry;
162
164
  std::function<void(FrameCallback &, jsi::Runtime &)> requestRender;
163
- std::shared_ptr<jsi::Value> dummyEvent;
164
165
  std::vector<FrameCallback> frameCallbacks;
165
166
  bool renderRequested = false;
166
167
  std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)>
@@ -187,6 +188,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
187
188
  #endif
188
189
 
189
190
  std::unordered_set<std::string> nativePropNames_; // filled by configureProps
191
+ LayoutAnimationsManager layoutAnimationsManager_;
190
192
 
191
193
  KeyboardEventSubscribeFunction subscribeForKeyboardEventsFunction;
192
194
  KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction;