react-native-reanimated 3.0.0-rc.6 → 3.0.0-rc.8
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.
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +161 -165
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
- package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
- package/Common/cpp/SharedItems/Shareables.cpp +142 -0
- package/Common/cpp/SharedItems/Shareables.h +455 -0
- package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +54 -26
- package/Common/cpp/Tools/RuntimeDecorator.h +11 -2
- package/Common/cpp/Tools/Scheduler.cpp +10 -0
- package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
- package/RNReanimated.podspec +2 -1
- package/android/CMakeLists.txt +1 -1
- package/android/build.gradle +9 -4
- package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
- package/android/src/main/cpp/LayoutAnimations.h +4 -4
- package/android/src/main/cpp/NativeProxy.cpp +60 -63
- package/ios/REAModule.mm +11 -5
- package/ios/native/NativeProxy.mm +26 -42
- package/ios/native/REAInitializer.mm +9 -0
- package/lib/commonjs/createAnimatedComponent.js +7 -11
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +51 -25
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
- package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js +7 -0
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +111 -209
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +24 -50
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
- package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +8 -33
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +16 -100
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
- package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +91 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
- package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/mappers.js +186 -0
- package/lib/commonjs/reanimated2/mappers.js.map +1 -0
- package/lib/commonjs/reanimated2/mutables.js +173 -0
- package/lib/commonjs/reanimated2/mutables.js.map +1 -0
- package/lib/commonjs/reanimated2/shareables.js +153 -0
- package/lib/commonjs/reanimated2/shareables.js.map +1 -0
- package/lib/commonjs/reanimated2/threads.js +58 -0
- package/lib/commonjs/reanimated2/threads.js.map +1 -0
- package/lib/commonjs/reanimated2/time.js +55 -0
- package/lib/commonjs/reanimated2/time.js.map +1 -0
- package/lib/commonjs/reanimated2/valueSetter.js +81 -0
- package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
- package/lib/module/createAnimatedComponent.js +7 -12
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +49 -25
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
- package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
- package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +7 -0
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/core.js +66 -188
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -52
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
- package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +8 -31
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +16 -95
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +5 -0
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +84 -0
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
- package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/mappers.js +173 -0
- package/lib/module/reanimated2/mappers.js.map +1 -0
- package/lib/module/reanimated2/mutables.js +149 -0
- package/lib/module/reanimated2/mutables.js.map +1 -0
- package/lib/module/reanimated2/shareables.js +133 -0
- package/lib/module/reanimated2/shareables.js.map +1 -0
- package/lib/module/reanimated2/threads.js +45 -0
- package/lib/module/reanimated2/threads.js.map +1 -0
- package/lib/module/reanimated2/time.js +37 -0
- package/lib/module/reanimated2/time.js.map +1 -0
- package/lib/module/reanimated2/valueSetter.js +66 -0
- package/lib/module/reanimated2/valueSetter.js.map +1 -0
- package/package.json +2 -2
- package/plugin.js +31 -15
- package/scripts/reanimated_utils.rb +3 -2
- package/src/createAnimatedComponent.tsx +8 -24
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +62 -53
- package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
- package/src/reanimated2/WorkletEventHandler.ts +4 -11
- package/src/reanimated2/animation/util.ts +1 -0
- package/src/reanimated2/commonTypes.ts +29 -4
- package/src/reanimated2/core.ts +103 -230
- package/src/reanimated2/globals.d.ts +28 -26
- package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
- package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
- package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
- package/src/reanimated2/hook/useAnimatedStyle.ts +26 -64
- package/src/reanimated2/hook/useSharedValue.ts +6 -3
- package/src/reanimated2/hook/utils.ts +1 -1
- package/src/reanimated2/interpolateColor.ts +2 -2
- package/src/reanimated2/jestUtils.ts +14 -29
- package/src/reanimated2/js-reanimated/JSReanimated.ts +19 -93
- package/src/reanimated2/js-reanimated/index.ts +4 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/animationsManager.ts +94 -0
- package/src/reanimated2/layoutReanimation/index.ts +1 -1
- package/src/reanimated2/mappers.ts +179 -0
- package/src/reanimated2/mutables.ts +151 -0
- package/src/reanimated2/shareables.ts +121 -0
- package/src/reanimated2/threads.ts +46 -0
- package/src/reanimated2/time.ts +30 -0
- package/src/reanimated2/valueSetter.ts +64 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
- package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
- package/Common/cpp/Registries/MapperRegistry.h +0 -29
- package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
- package/Common/cpp/Registries/WorkletsCache.h +0 -24
- package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
- package/Common/cpp/SharedItems/FrozenObject.h +0 -36
- package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
- package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
- package/Common/cpp/SharedItems/MutableValue.h +0 -54
- package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
- package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
- package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
- package/Common/cpp/SharedItems/RemoteObject.h +0 -35
- package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
- package/Common/cpp/SharedItems/ShareableValue.h +0 -63
- package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
- package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
- package/Common/cpp/Tools/Mapper.cpp +0 -86
- package/Common/cpp/Tools/Mapper.h +0 -51
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
#include "AnimatedSensorModule.h"
|
|
15
15
|
#include "ErrorHandler.h"
|
|
16
|
-
#include "
|
|
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
|
-
|
|
54
|
-
override;
|
|
46
|
+
~NativeReanimatedModule();
|
|
55
47
|
|
|
56
|
-
|
|
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
|
-
|
|
50
|
+
void installCoreFunctions(
|
|
61
51
|
jsi::Runtime &rt,
|
|
62
|
-
const jsi::Value &
|
|
63
|
-
const jsi::Value &
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
const jsi::Value &workletMaker,
|
|
53
|
+
const jsi::Value &layoutAnimationStartFunction) 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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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::
|
|
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;
|
|
@@ -12,61 +12,50 @@ static jsi::Value SPEC_PREFIX(installCoreFunctions)(
|
|
|
12
12
|
const jsi::Value *args,
|
|
13
13
|
size_t count) {
|
|
14
14
|
static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
15
|
-
->installCoreFunctions(rt, std::move(args[0]));
|
|
15
|
+
->installCoreFunctions(rt, std::move(args[0]), std::move(args[1]));
|
|
16
16
|
return jsi::Value::undefined();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// SharedValue
|
|
20
20
|
|
|
21
|
-
static jsi::Value SPEC_PREFIX(
|
|
21
|
+
static jsi::Value SPEC_PREFIX(makeShareableClone)(
|
|
22
22
|
jsi::Runtime &rt,
|
|
23
23
|
TurboModule &turboModule,
|
|
24
24
|
const jsi::Value *args,
|
|
25
25
|
size_t count) {
|
|
26
26
|
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
27
|
-
->
|
|
27
|
+
->makeShareableClone(rt, std::move(args[0]));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
jsi::Runtime &rt,
|
|
32
|
-
TurboModule &turboModule,
|
|
33
|
-
const jsi::Value *args,
|
|
34
|
-
size_t count) {
|
|
35
|
-
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
36
|
-
->makeMutable(rt, std::move(args[0]));
|
|
37
|
-
}
|
|
30
|
+
// Sync methods
|
|
38
31
|
|
|
39
|
-
static jsi::Value SPEC_PREFIX(
|
|
32
|
+
static jsi::Value SPEC_PREFIX(makeSynchronizedDataHolder)(
|
|
40
33
|
jsi::Runtime &rt,
|
|
41
34
|
TurboModule &turboModule,
|
|
42
35
|
const jsi::Value *args,
|
|
43
36
|
size_t count) {
|
|
44
37
|
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
45
|
-
->
|
|
38
|
+
->makeSynchronizedDataHolder(rt, std::move(args[0]));
|
|
46
39
|
}
|
|
47
40
|
|
|
48
|
-
static jsi::Value SPEC_PREFIX(
|
|
41
|
+
static jsi::Value SPEC_PREFIX(getDataSynchronously)(
|
|
49
42
|
jsi::Runtime &rt,
|
|
50
43
|
TurboModule &turboModule,
|
|
51
44
|
const jsi::Value *args,
|
|
52
45
|
size_t count) {
|
|
53
46
|
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
54
|
-
->
|
|
55
|
-
rt,
|
|
56
|
-
std::move(args[0]),
|
|
57
|
-
std::move(args[1]),
|
|
58
|
-
std::move(args[2]),
|
|
59
|
-
std::move(args[3]),
|
|
60
|
-
std::move(args[4]));
|
|
47
|
+
->getDataSynchronously(rt, std::move(args[0]));
|
|
61
48
|
}
|
|
62
49
|
|
|
63
|
-
|
|
50
|
+
// scheduler
|
|
51
|
+
|
|
52
|
+
static jsi::Value SPEC_PREFIX(scheduleOnUI)(
|
|
64
53
|
jsi::Runtime &rt,
|
|
65
54
|
TurboModule &turboModule,
|
|
66
55
|
const jsi::Value *args,
|
|
67
56
|
size_t count) {
|
|
68
57
|
static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
69
|
-
->
|
|
58
|
+
->scheduleOnUI(rt, std::move(args[0]));
|
|
70
59
|
return jsi::Value::undefined();
|
|
71
60
|
}
|
|
72
61
|
|
|
@@ -166,25 +155,24 @@ static jsi::Value SPEC_PREFIX(configureLayoutAnimation)(
|
|
|
166
155
|
size_t count) {
|
|
167
156
|
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
|
|
168
157
|
->configureLayoutAnimation(
|
|
169
|
-
rt,
|
|
170
|
-
std::move(args[0]),
|
|
171
|
-
std::move(args[1]),
|
|
172
|
-
std::move(args[2]),
|
|
173
|
-
std::move(args[3]));
|
|
158
|
+
rt, std::move(args[0]), std::move(args[1]), std::move(args[2]));
|
|
174
159
|
}
|
|
175
160
|
|
|
176
161
|
NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
|
|
177
162
|
std::shared_ptr<CallInvoker> jsInvoker)
|
|
178
163
|
: TurboModule("NativeReanimated", jsInvoker) {
|
|
179
164
|
methodMap_["installCoreFunctions"] =
|
|
180
|
-
MethodMetadata{
|
|
165
|
+
MethodMetadata{2, SPEC_PREFIX(installCoreFunctions)};
|
|
166
|
+
|
|
167
|
+
methodMap_["makeShareableClone"] =
|
|
168
|
+
MethodMetadata{1, SPEC_PREFIX(makeShareableClone)};
|
|
181
169
|
|
|
182
|
-
methodMap_["
|
|
183
|
-
|
|
184
|
-
methodMap_["
|
|
170
|
+
methodMap_["makeSynchronizedDataHolder"] =
|
|
171
|
+
MethodMetadata{1, SPEC_PREFIX(makeSynchronizedDataHolder)};
|
|
172
|
+
methodMap_["getDataSynchronously"] =
|
|
173
|
+
MethodMetadata{1, SPEC_PREFIX(getDataSynchronously)};
|
|
185
174
|
|
|
186
|
-
methodMap_["
|
|
187
|
-
methodMap_["stopMapper"] = MethodMetadata{1, SPEC_PREFIX(stopMapper)};
|
|
175
|
+
methodMap_["scheduleOnUI"] = MethodMetadata{1, SPEC_PREFIX(scheduleOnUI)};
|
|
188
176
|
|
|
189
177
|
methodMap_["registerEventHandler"] =
|
|
190
178
|
MethodMetadata{2, SPEC_PREFIX(registerEventHandler)};
|
|
@@ -24,24 +24,24 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
|
|
|
24
24
|
public:
|
|
25
25
|
virtual void installCoreFunctions(
|
|
26
26
|
jsi::Runtime &rt,
|
|
27
|
-
const jsi::Value &
|
|
27
|
+
const jsi::Value &valueUnpacker,
|
|
28
|
+
const jsi::Value &layoutAnimationStartFunction) = 0;
|
|
28
29
|
|
|
29
30
|
// SharedValue
|
|
30
|
-
virtual jsi::Value
|
|
31
|
+
virtual jsi::Value makeShareableClone(
|
|
31
32
|
jsi::Runtime &rt,
|
|
32
33
|
const jsi::Value &value) = 0;
|
|
33
|
-
virtual jsi::Value makeMutable(jsi::Runtime &rt, const jsi::Value &value) = 0;
|
|
34
|
-
virtual jsi::Value makeRemote(jsi::Runtime &rt, const jsi::Value &value) = 0;
|
|
35
34
|
|
|
36
|
-
//
|
|
37
|
-
virtual jsi::Value
|
|
35
|
+
// Synchronized data objects
|
|
36
|
+
virtual jsi::Value makeSynchronizedDataHolder(
|
|
38
37
|
jsi::Runtime &rt,
|
|
39
|
-
const jsi::Value &
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const jsi::Value &
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const jsi::Value &initialShareable) = 0;
|
|
39
|
+
virtual jsi::Value getDataSynchronously(
|
|
40
|
+
jsi::Runtime &rt,
|
|
41
|
+
const jsi::Value &synchronizedDataHolderRef) = 0;
|
|
42
|
+
|
|
43
|
+
// Scheduling
|
|
44
|
+
virtual void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) = 0;
|
|
45
45
|
|
|
46
46
|
// events
|
|
47
47
|
virtual jsi::Value registerEventHandler(
|
|
@@ -91,8 +91,7 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
|
|
|
91
91
|
jsi::Runtime &rt,
|
|
92
92
|
const jsi::Value &viewTag,
|
|
93
93
|
const jsi::Value &type,
|
|
94
|
-
const jsi::Value &config
|
|
95
|
-
const jsi::Value &viewSharedValue) = 0;
|
|
94
|
+
const jsi::Value &config) = 0;
|
|
96
95
|
};
|
|
97
96
|
|
|
98
97
|
} // namespace reanimated
|
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
#include <jsi/jsi.h>
|
|
4
4
|
#include <memory>
|
|
5
5
|
#include "ErrorHandler.h"
|
|
6
|
-
#include "JSIStoreValueUser.h"
|
|
7
6
|
#include "RuntimeDecorator.h"
|
|
8
7
|
#include "Scheduler.h"
|
|
9
|
-
#include "ShareableValue.h"
|
|
10
|
-
#include "WorkletsCache.h"
|
|
11
8
|
|
|
12
9
|
namespace reanimated {
|
|
13
10
|
|
|
@@ -23,24 +20,10 @@ class RuntimeManager {
|
|
|
23
20
|
std::shared_ptr<ErrorHandler> errorHandler,
|
|
24
21
|
std::shared_ptr<Scheduler> scheduler,
|
|
25
22
|
RuntimeType runtimeType = RuntimeType::Worklet)
|
|
26
|
-
: runtime(runtime),
|
|
27
|
-
errorHandler(errorHandler),
|
|
28
|
-
scheduler(scheduler),
|
|
29
|
-
workletsCache(std::make_unique<WorkletsCache>()),
|
|
30
|
-
storeUserData(std::make_shared<StaticStoreUser>()) {
|
|
23
|
+
: runtime(runtime), errorHandler(errorHandler), scheduler(scheduler) {
|
|
31
24
|
RuntimeDecorator::registerRuntime(this->runtime.get(), runtimeType);
|
|
32
25
|
}
|
|
33
26
|
|
|
34
|
-
virtual ~RuntimeManager() {
|
|
35
|
-
clearStore();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public:
|
|
39
|
-
/**
|
|
40
|
-
Holds the jsi::Function worklet that is responsible for updating values in
|
|
41
|
-
JS. Can be null.
|
|
42
|
-
*/
|
|
43
|
-
std::shared_ptr<ShareableValue> valueSetter;
|
|
44
27
|
/**
|
|
45
28
|
Holds the jsi::Runtime this RuntimeManager is managing.
|
|
46
29
|
*/
|
|
@@ -54,22 +37,6 @@ class RuntimeManager {
|
|
|
54
37
|
React-JS Thread.
|
|
55
38
|
*/
|
|
56
39
|
std::shared_ptr<Scheduler> scheduler;
|
|
57
|
-
/**
|
|
58
|
-
Holds a list of adapted Worklets which are cached to avoid unneccessary
|
|
59
|
-
recreation.
|
|
60
|
-
*/
|
|
61
|
-
std::unique_ptr<WorkletsCache> workletsCache;
|
|
62
|
-
/**
|
|
63
|
-
Holds the JSI-Value Store where JSI::Values are cached on a
|
|
64
|
-
per-RuntimeManager basis.
|
|
65
|
-
*/
|
|
66
|
-
std::shared_ptr<StaticStoreUser> storeUserData;
|
|
67
|
-
|
|
68
|
-
private:
|
|
69
|
-
void clearStore() {
|
|
70
|
-
const std::lock_guard<std::recursive_mutex> lock(storeUserData->storeMutex);
|
|
71
|
-
storeUserData->store.clear();
|
|
72
|
-
}
|
|
73
40
|
};
|
|
74
41
|
|
|
75
42
|
} // namespace reanimated
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#include "Shareables.h"
|
|
2
|
+
|
|
3
|
+
using namespace facebook;
|
|
4
|
+
|
|
5
|
+
namespace reanimated {
|
|
6
|
+
|
|
7
|
+
CoreFunction::CoreFunction(
|
|
8
|
+
JSRuntimeHelper *runtimeHelper,
|
|
9
|
+
const jsi::Value &workletValue)
|
|
10
|
+
: runtimeHelper_(runtimeHelper) {
|
|
11
|
+
jsi::Runtime &rt = *runtimeHelper->rnRuntime();
|
|
12
|
+
auto workletObject = workletValue.asObject(rt);
|
|
13
|
+
rnFunction_ = std::make_unique<jsi::Function>(workletObject.asFunction(rt));
|
|
14
|
+
functionBody_ =
|
|
15
|
+
workletObject.getProperty(rt, "asString").asString(rt).utf8(rt);
|
|
16
|
+
location_ = workletObject.getProperty(rt, "__location").asString(rt).utf8(rt);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
std::unique_ptr<jsi::Function> &CoreFunction::getFunction(jsi::Runtime &rt) {
|
|
20
|
+
if (runtimeHelper_->isUIRuntime(rt)) {
|
|
21
|
+
if (uiFunction_ == nullptr) {
|
|
22
|
+
// maybe need to initialize UI Function
|
|
23
|
+
// the newline before closing paren is needed because the last line can be
|
|
24
|
+
// an inline comment (specifically this happens when we attach source maps
|
|
25
|
+
// at the end) in which case the paren won't be parsed
|
|
26
|
+
auto codeBuffer = std::make_shared<const jsi::StringBuffer>(
|
|
27
|
+
"(" + functionBody_ + "\n)");
|
|
28
|
+
uiFunction_ = std::make_unique<jsi::Function>(
|
|
29
|
+
rt.evaluateJavaScript(codeBuffer, location_)
|
|
30
|
+
.asObject(rt)
|
|
31
|
+
.asFunction(rt));
|
|
32
|
+
}
|
|
33
|
+
return uiFunction_;
|
|
34
|
+
} else {
|
|
35
|
+
// running on the main RN runtime
|
|
36
|
+
return rnFunction_;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
std::shared_ptr<Shareable> extractShareableOrThrow(
|
|
41
|
+
jsi::Runtime &rt,
|
|
42
|
+
const jsi::Value &maybeShareableValue,
|
|
43
|
+
const char *errorMessage) {
|
|
44
|
+
if (maybeShareableValue.isObject()) {
|
|
45
|
+
auto object = maybeShareableValue.asObject(rt);
|
|
46
|
+
if (object.isHostObject<ShareableJSRef>(rt)) {
|
|
47
|
+
return object.getHostObject<ShareableJSRef>(rt)->value();
|
|
48
|
+
}
|
|
49
|
+
} else if (maybeShareableValue.isUndefined()) {
|
|
50
|
+
return Shareable::undefined();
|
|
51
|
+
}
|
|
52
|
+
throw std::runtime_error(
|
|
53
|
+
errorMessage != nullptr
|
|
54
|
+
? errorMessage
|
|
55
|
+
: "expecting the object to be of type ShareableJSRef");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Shareable::~Shareable() {}
|
|
59
|
+
|
|
60
|
+
#if HAS_JS_WEAK_OBJECTS
|
|
61
|
+
|
|
62
|
+
jsi::Value RetainingShareable::getJSValue(jsi::Runtime &rt) {
|
|
63
|
+
jsi::Value value;
|
|
64
|
+
if (runtimeHelper_->isRNRuntime(rt)) {
|
|
65
|
+
// TODO: it is suboptimal to generate new object every time getJS is called
|
|
66
|
+
// on host runtime – the objects we are generating already exists and we
|
|
67
|
+
// should possibly just grab a hold of such object and use it here instead
|
|
68
|
+
// of creating a new JS representation. As far as I understand the only
|
|
69
|
+
// case where it can be realistically called this way is when a shared
|
|
70
|
+
// value is created and then accessed on the same runtime
|
|
71
|
+
return toJSValue(rt);
|
|
72
|
+
} else if (remoteValue_ == nullptr) {
|
|
73
|
+
value = toJSValue(rt);
|
|
74
|
+
remoteValue_ = std::make_unique<jsi::WeakObject>(rt, value.asObject(rt));
|
|
75
|
+
} else {
|
|
76
|
+
value = remoteValue_->lock(rt);
|
|
77
|
+
if (value.isUndefined()) {
|
|
78
|
+
value = toJSValue(rt);
|
|
79
|
+
remoteValue_ = std::make_unique<jsi::WeakObject>(rt, value.asObject(rt));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
RetainingShareable::~RetainingShareable() {
|
|
86
|
+
if (runtimeHelper_->uiRuntimeDestroyed) {
|
|
87
|
+
// The below use of unique_ptr.release prevents the smart pointer from
|
|
88
|
+
// calling the destructor of the kept object. This effectively results in
|
|
89
|
+
// leaking some memory. We do this on purpose, as sometimes we would keep
|
|
90
|
+
// references to JSI objects past the lifetime of its runtime (e.g., shared
|
|
91
|
+
// values references from the RN VM holds reference to JSI objects on the
|
|
92
|
+
// UI runtime). When the UI runtime is terminated, the orphaned JSI objects
|
|
93
|
+
// would crash the app when their destructors are called, because they
|
|
94
|
+
// call into a memory that's managed by the terminated runtime. We accept
|
|
95
|
+
// the tradeoff of leaking memory here, as it has a limited impact. This
|
|
96
|
+
// scenario can only occur when the React instance is torn down which
|
|
97
|
+
// happens in development mode during app reloads, or in production when the
|
|
98
|
+
// app is being shut down gracefully by the system. An alternative solution
|
|
99
|
+
// would require us to keep track of all JSI values that are in use which
|
|
100
|
+
// would require additional data structure and compute spent on bookkeeping
|
|
101
|
+
// that only for the sake of destroying the values in time before the
|
|
102
|
+
// runtime is terminated. Note that the underlying memory that jsi::Value
|
|
103
|
+
// refers to is managed by the VM and gets freed along with the runtime.
|
|
104
|
+
remoteValue_.release();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#endif // HAS_JS_WEAK_OBJECTS
|
|
109
|
+
|
|
110
|
+
ShareableArray::ShareableArray(
|
|
111
|
+
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
112
|
+
jsi::Runtime &rt,
|
|
113
|
+
const jsi::Array &array)
|
|
114
|
+
: RetainingShareable(runtimeHelper, rt, ArrayType) {
|
|
115
|
+
auto size = array.size(rt);
|
|
116
|
+
data_.reserve(size);
|
|
117
|
+
for (size_t i = 0; i < size; i++) {
|
|
118
|
+
data_.push_back(extractShareableOrThrow(rt, array.getValueAtIndex(rt, i)));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
ShareableObject::ShareableObject(
|
|
123
|
+
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
124
|
+
jsi::Runtime &rt,
|
|
125
|
+
const jsi::Object &object)
|
|
126
|
+
: RetainingShareable(runtimeHelper, rt, ObjectType) {
|
|
127
|
+
auto propertyNames = object.getPropertyNames(rt);
|
|
128
|
+
auto size = propertyNames.size(rt);
|
|
129
|
+
data_.reserve(size);
|
|
130
|
+
for (size_t i = 0; i < size; i++) {
|
|
131
|
+
auto key = propertyNames.getValueAtIndex(rt, i).asString(rt);
|
|
132
|
+
auto value = extractShareableOrThrow(rt, object.getProperty(rt, key));
|
|
133
|
+
data_.emplace_back(key.utf8(rt), value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
std::shared_ptr<Shareable> Shareable::undefined() {
|
|
138
|
+
static auto undefined = std::make_shared<ShareableScalar>();
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
} /* namespace reanimated */
|