react-native-worklets 0.3.0 → 0.4.0-bundle-mode-preview-1
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/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +532 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +88 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +40 -122
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +16 -40
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +2 -1
- package/Common/cpp/worklets/Resources/ValueUnpacker.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/Shareables.cpp +200 -24
- package/Common/cpp/worklets/SharedItems/Shareables.h +108 -7
- package/Common/cpp/worklets/Tools/JSLogger.cpp +56 -4
- package/Common/cpp/worklets/Tools/JSLogger.h +17 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +12 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +10 -2
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +3 -1
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +19 -1
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +12 -3
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +136 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +4 -4
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +1 -1
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +85 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +55 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +8 -4
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +70 -24
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +24 -4
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +53 -1
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +2 -1
- package/RNWorklets.podspec +9 -4
- package/android/CMakeLists.txt +14 -36
- package/android/build.gradle +16 -33
- package/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +149 -0
- package/android/src/{main/java → legacyBundling}/com/swmansion/worklets/WorkletsModule.java +17 -2
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +49 -8
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +17 -2
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +1 -1
- package/apple/worklets/apple/WorkletsMessageThread.mm +4 -0
- package/apple/worklets/apple/WorkletsModule.h +16 -1
- package/apple/worklets/apple/WorkletsModule.mm +29 -2
- package/bundleMode/index.d.ts +3 -0
- package/bundleMode/index.js +55 -0
- package/lib/module/PlatformChecker/PlatformChecker.js +8 -0
- package/lib/module/PlatformChecker/PlatformChecker.js.map +1 -0
- package/lib/module/PlatformChecker/index.js +17 -0
- package/lib/module/PlatformChecker/index.js.map +1 -0
- package/lib/module/WorkletsError.js +2 -1
- package/lib/module/WorkletsError.js.map +1 -1
- package/lib/module/WorkletsModule/JSWorklets.js +36 -4
- package/lib/module/WorkletsModule/JSWorklets.js.map +1 -1
- package/lib/module/WorkletsModule/NativeWorklets.js +35 -15
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -1
- package/lib/module/WorkletsModule/workletsModuleInstance.js +2 -2
- package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -1
- package/lib/module/bundleUnpacker.js +47 -0
- package/lib/module/bundleUnpacker.js.map +1 -0
- package/lib/module/callGuard.js +30 -0
- package/lib/module/callGuard.js.map +1 -0
- package/lib/module/errors.js +30 -11
- package/lib/module/errors.js.map +1 -1
- package/lib/module/index.js +10 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers.js +123 -103
- package/lib/module/initializers.js.map +1 -1
- package/lib/module/logger.js +15 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/module/privateGlobals.d.js +0 -1
- package/lib/module/privateGlobals.d.js.map +1 -1
- package/lib/module/publicGlobals.js +5 -0
- package/lib/module/publicGlobals.js.map +1 -0
- package/lib/module/runLoop/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/requestAnimationFrame.js +50 -0
- package/lib/module/runLoop/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runtimes.js +6 -10
- package/lib/module/runtimes.js.map +1 -1
- package/lib/module/shareableMappingCache.js +1 -3
- package/lib/module/shareableMappingCache.js.map +1 -1
- package/lib/module/shareables.js +116 -34
- package/lib/module/shareables.js.map +1 -1
- package/lib/module/specs/index.js +2 -2
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/threads.js +49 -54
- package/lib/module/threads.js.map +1 -1
- package/lib/module/valueUnpacker.js +3 -3
- package/lib/module/valueUnpacker.js.map +1 -1
- package/lib/module/workletRuntimeEntry.js +30 -0
- package/lib/module/workletRuntimeEntry.js.map +1 -0
- package/lib/typescript/PlatformChecker/PlatformChecker.d.ts +5 -0
- package/lib/typescript/PlatformChecker/PlatformChecker.d.ts.map +1 -0
- package/lib/typescript/PlatformChecker/index.d.ts +10 -0
- package/lib/typescript/PlatformChecker/index.d.ts.map +1 -0
- package/lib/typescript/WorkletsError.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/JSWorklets.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +1 -3
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +12 -2
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/bundleUnpacker.d.ts +7 -0
- package/lib/typescript/bundleUnpacker.d.ts.map +1 -0
- package/lib/typescript/callGuard.d.ts +4 -0
- package/lib/typescript/callGuard.d.ts.map +1 -0
- package/lib/typescript/errors.d.ts +13 -5
- package/lib/typescript/errors.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/initializers.d.ts +16 -5
- package/lib/typescript/initializers.d.ts.map +1 -1
- package/lib/typescript/logger.d.ts +5 -0
- package/lib/typescript/logger.d.ts.map +1 -0
- package/lib/typescript/publicGlobals.d.ts +22 -0
- package/lib/typescript/publicGlobals.d.ts.map +1 -0
- package/lib/typescript/runLoop/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts.map +1 -1
- package/lib/typescript/shareableMappingCache.d.ts.map +1 -1
- package/lib/typescript/shareables.d.ts +3 -2
- package/lib/typescript/shareables.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/lib/typescript/specs/index.d.ts +2 -2
- package/lib/typescript/specs/index.d.ts.map +1 -1
- package/lib/typescript/threads.d.ts.map +1 -1
- package/lib/typescript/workletRuntimeEntry.d.ts +14 -0
- package/lib/typescript/workletRuntimeEntry.d.ts.map +1 -0
- package/lib/typescript/workletTypes.d.ts +14 -3
- package/lib/typescript/workletTypes.d.ts.map +1 -1
- package/package.json +17 -8
- package/plugin/index.js +145 -52
- package/scripts/worklets_utils.rb +9 -0
- package/src/PlatformChecker/PlatformChecker.ts +7 -0
- package/src/PlatformChecker/index.ts +29 -0
- package/src/WorkletsError.ts +2 -1
- package/src/WorkletsModule/JSWorklets.ts +71 -4
- package/src/WorkletsModule/NativeWorklets.ts +83 -21
- package/src/WorkletsModule/workletsModuleInstance.ts +2 -2
- package/src/WorkletsModule/workletsModuleProxy.ts +49 -1
- package/src/bundleUnpacker.ts +75 -0
- package/src/callGuard.ts +33 -0
- package/src/errors.ts +35 -18
- package/src/index.ts +12 -12
- package/src/initializers.ts +143 -113
- package/src/logger.ts +16 -0
- package/src/privateGlobals.d.ts +22 -6
- package/src/publicGlobals.ts +26 -0
- package/src/runLoop/requestAnimationFrame.ts +67 -0
- package/src/runLoop/setImmediatePolyfill.ts +20 -0
- package/src/runLoop/setIntervalPolyfill.ts +38 -0
- package/src/runLoop/setTimeoutPolyfill.ts +40 -0
- package/src/runtimes.ts +6 -11
- package/src/shareableMappingCache.ts +1 -3
- package/src/shareables.ts +179 -65
- package/src/specs/NativeWorkletsModule.ts +1 -1
- package/src/specs/index.ts +5 -2
- package/src/threads.ts +75 -65
- package/src/valueUnpacker.ts +3 -3
- package/src/workletRuntimeEntry.ts +30 -0
- package/src/workletTypes.ts +22 -5
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +0 -139
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +0 -61
- package/android/src/paper/com/swmansion/worklets/NativeWorkletsModuleSpec.java +0 -26
- package/lib/module/PlatformChecker.js +0 -26
- package/lib/module/PlatformChecker.js.map +0 -1
- package/lib/module/animationFrameQueue/mockedRequestAnimationFrame.js.map +0 -1
- package/lib/module/animationFrameQueue/requestAnimationFrame.js +0 -36
- package/lib/module/animationFrameQueue/requestAnimationFrame.js.map +0 -1
- package/lib/module/logger/LogBox.js +0 -15
- package/lib/module/logger/LogBox.js.map +0 -1
- package/lib/module/logger/index.js +0 -5
- package/lib/module/logger/index.js.map +0 -1
- package/lib/module/logger/logger.js +0 -137
- package/lib/module/logger/logger.js.map +0 -1
- package/lib/typescript/PlatformChecker.d.ts +0 -6
- package/lib/typescript/PlatformChecker.d.ts.map +0 -1
- package/lib/typescript/animationFrameQueue/mockedRequestAnimationFrame.d.ts.map +0 -1
- package/lib/typescript/animationFrameQueue/requestAnimationFrame.d.ts.map +0 -1
- package/lib/typescript/logger/LogBox.d.ts +0 -32
- package/lib/typescript/logger/LogBox.d.ts.map +0 -1
- package/lib/typescript/logger/index.d.ts +0 -3
- package/lib/typescript/logger/index.d.ts.map +0 -1
- package/lib/typescript/logger/logger.d.ts +0 -52
- package/lib/typescript/logger/logger.d.ts.map +0 -1
- package/src/PlatformChecker.ts +0 -30
- package/src/animationFrameQueue/requestAnimationFrame.ts +0 -41
- package/src/logger/LogBox.ts +0 -55
- package/src/logger/index.ts +0 -3
- package/src/logger/logger.ts +0 -155
- /package/lib/module/{animationFrameQueue → runLoop}/mockedRequestAnimationFrame.js +0 -0
- /package/lib/typescript/{animationFrameQueue → runLoop}/mockedRequestAnimationFrame.d.ts +0 -0
- /package/lib/typescript/{animationFrameQueue → runLoop}/requestAnimationFrame.d.ts +0 -0
- /package/src/{animationFrameQueue → runLoop}/mockedRequestAnimationFrame.ts +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
package com.swmansion.worklets;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.OptIn;
|
|
4
|
+
import com.facebook.jni.HybridData;
|
|
5
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
6
|
+
import com.facebook.react.bridge.BundleConsumer;
|
|
7
|
+
import com.facebook.react.bridge.LifecycleEventListener;
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
+
import com.facebook.react.bridge.queue.MessageQueueThread;
|
|
11
|
+
import com.facebook.react.common.annotations.FrameworkAPI;
|
|
12
|
+
import com.facebook.react.fabric.BigStringBufferWrapper;
|
|
13
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
14
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
|
|
15
|
+
import com.facebook.soloader.SoLoader;
|
|
16
|
+
import com.swmansion.worklets.runloop.AnimationFrameCallback;
|
|
17
|
+
import com.swmansion.worklets.runloop.AnimationFrameQueue;
|
|
18
|
+
import java.util.Objects;
|
|
19
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
20
|
+
|
|
21
|
+
@SuppressWarnings("JavaJniMissingFunction")
|
|
22
|
+
@ReactModule(name = WorkletsModule.NAME)
|
|
23
|
+
public class WorkletsModule extends NativeWorkletsModuleSpec
|
|
24
|
+
implements LifecycleEventListener, BundleConsumer {
|
|
25
|
+
static {
|
|
26
|
+
SoLoader.loadLibrary("worklets");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@SuppressWarnings("unused")
|
|
31
|
+
private HybridData mHybridData;
|
|
32
|
+
|
|
33
|
+
@SuppressWarnings("unused")
|
|
34
|
+
protected HybridData getHybridData() {
|
|
35
|
+
return mHybridData;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private final WorkletsMessageQueueThread mMessageQueueThread = new WorkletsMessageQueueThread();
|
|
39
|
+
private final AndroidUIScheduler mAndroidUIScheduler;
|
|
40
|
+
private final AnimationFrameQueue mAnimationFrameQueue;
|
|
41
|
+
private boolean mSlowAnimationsEnabled;
|
|
42
|
+
private BigStringBufferWrapper mScriptWrapper = null;
|
|
43
|
+
private String mSourceURL = null;
|
|
44
|
+
|
|
45
|
+
@Override
|
|
46
|
+
public void setScriptWrapper(BigStringBufferWrapper scriptWrapper) {
|
|
47
|
+
mScriptWrapper = scriptWrapper;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public void setSourceURL(String sourceURL) {
|
|
52
|
+
mSourceURL = sourceURL;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't
|
|
57
|
+
* cost us much to add synchronization for extra safety.
|
|
58
|
+
*/
|
|
59
|
+
private final AtomicBoolean mInvalidated = new AtomicBoolean(false);
|
|
60
|
+
|
|
61
|
+
@OptIn(markerClass = FrameworkAPI.class)
|
|
62
|
+
private native HybridData initHybrid(
|
|
63
|
+
long jsContext,
|
|
64
|
+
MessageQueueThread messageQueueThread,
|
|
65
|
+
CallInvokerHolderImpl jsCallInvokerHolder,
|
|
66
|
+
AndroidUIScheduler androidUIScheduler,
|
|
67
|
+
BigStringBufferWrapper scriptWrapper,
|
|
68
|
+
String sourceURL);
|
|
69
|
+
|
|
70
|
+
public WorkletsModule(ReactApplicationContext reactContext) {
|
|
71
|
+
super(reactContext);
|
|
72
|
+
|
|
73
|
+
if (!BuildConfig.BUNDLE_MODE) {
|
|
74
|
+
reactContext.assertOnJSQueueThread();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
mAndroidUIScheduler = new AndroidUIScheduler(reactContext);
|
|
78
|
+
mAnimationFrameQueue = new AnimationFrameQueue(reactContext);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@OptIn(markerClass = FrameworkAPI.class)
|
|
82
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
83
|
+
public boolean installTurboModule() {
|
|
84
|
+
var context = getReactApplicationContext();
|
|
85
|
+
|
|
86
|
+
if (!BuildConfig.BUNDLE_MODE) {
|
|
87
|
+
context.assertOnNativeModulesQueueThread();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var jsContext = Objects.requireNonNull(context.getJavaScriptContextHolder()).get();
|
|
91
|
+
var jsCallInvokerHolder = JSCallInvokerResolver.getJSCallInvokerHolder(context);
|
|
92
|
+
|
|
93
|
+
mHybridData =
|
|
94
|
+
initHybrid(
|
|
95
|
+
jsContext,
|
|
96
|
+
mMessageQueueThread,
|
|
97
|
+
jsCallInvokerHolder,
|
|
98
|
+
mAndroidUIScheduler,
|
|
99
|
+
mScriptWrapper,
|
|
100
|
+
mSourceURL);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public void requestAnimationFrame(AnimationFrameCallback animationFrameCallback) {
|
|
105
|
+
mAnimationFrameQueue.requestAnimationFrame(animationFrameCallback);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @noinspection unused
|
|
110
|
+
*/
|
|
111
|
+
@DoNotStrip
|
|
112
|
+
public boolean isOnJSQueueThread() {
|
|
113
|
+
return getReactApplicationContext().isOnJSQueueThread();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public void toggleSlowAnimations() {
|
|
117
|
+
final int ANIMATIONS_DRAG_FACTOR = 10;
|
|
118
|
+
mSlowAnimationsEnabled = !mSlowAnimationsEnabled;
|
|
119
|
+
mAnimationFrameQueue.enableSlowAnimations(mSlowAnimationsEnabled, ANIMATIONS_DRAG_FACTOR);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public void invalidate() {
|
|
123
|
+
if (mInvalidated.getAndSet(true)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (mHybridData != null && mHybridData.isValid()) {
|
|
127
|
+
// We have to destroy extra runtimes when invalidate is called. If we clean
|
|
128
|
+
// it up later instead there's a chance the runtime will retain references
|
|
129
|
+
// to invalidated memory and will crash on its destruction.
|
|
130
|
+
invalidateCpp();
|
|
131
|
+
}
|
|
132
|
+
mAndroidUIScheduler.deactivate();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private native void invalidateCpp();
|
|
136
|
+
|
|
137
|
+
@Override
|
|
138
|
+
public void onHostResume() {
|
|
139
|
+
mAnimationFrameQueue.resume();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@Override
|
|
143
|
+
public void onHostPause() {
|
|
144
|
+
mAnimationFrameQueue.pause();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@Override
|
|
148
|
+
public void onHostDestroy() {}
|
|
149
|
+
}
|
|
@@ -52,7 +52,11 @@ public class WorkletsModule extends NativeWorkletsModuleSpec implements Lifecycl
|
|
|
52
52
|
|
|
53
53
|
public WorkletsModule(ReactApplicationContext reactContext) {
|
|
54
54
|
super(reactContext);
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
if (!BuildConfig.BUNDLE_MODE) {
|
|
57
|
+
reactContext.assertOnJSQueueThread();
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
mAndroidUIScheduler = new AndroidUIScheduler(reactContext);
|
|
57
61
|
mAnimationFrameQueue = new AnimationFrameQueue(reactContext);
|
|
58
62
|
}
|
|
@@ -61,7 +65,10 @@ public class WorkletsModule extends NativeWorkletsModuleSpec implements Lifecycl
|
|
|
61
65
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
62
66
|
public boolean installTurboModule() {
|
|
63
67
|
var context = getReactApplicationContext();
|
|
64
|
-
|
|
68
|
+
|
|
69
|
+
if (!BuildConfig.BUNDLE_MODE) {
|
|
70
|
+
context.assertOnNativeModulesQueueThread();
|
|
71
|
+
}
|
|
65
72
|
|
|
66
73
|
var jsContext = Objects.requireNonNull(context.getJavaScriptContextHolder()).get();
|
|
67
74
|
var jsCallInvokerHolder = JSCallInvokerResolver.getJSCallInvokerHolder(context);
|
|
@@ -75,6 +82,14 @@ public class WorkletsModule extends NativeWorkletsModuleSpec implements Lifecycl
|
|
|
75
82
|
mAnimationFrameQueue.requestAnimationFrame(animationFrameCallback);
|
|
76
83
|
}
|
|
77
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @noinspection unused
|
|
87
|
+
*/
|
|
88
|
+
@DoNotStrip
|
|
89
|
+
public boolean isOnJSQueueThread() {
|
|
90
|
+
return getReactApplicationContext().isOnJSQueueThread();
|
|
91
|
+
}
|
|
92
|
+
|
|
78
93
|
public void toggleSlowAnimations() {
|
|
79
94
|
final int ANIMATIONS_DRAG_FACTOR = 10;
|
|
80
95
|
mSlowAnimationsEnabled = !mSlowAnimationsEnabled;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
#include <
|
|
2
|
-
|
|
1
|
+
#include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
2
|
+
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
3
3
|
#include <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
|
|
4
4
|
#include <worklets/android/AnimationFrameCallback.h>
|
|
5
5
|
#include <worklets/android/WorkletsModule.h>
|
|
6
6
|
|
|
7
|
+
#include <memory>
|
|
7
8
|
#include <utility>
|
|
8
9
|
|
|
9
10
|
namespace worklets {
|
|
@@ -16,7 +17,9 @@ WorkletsModule::WorkletsModule(
|
|
|
16
17
|
jsi::Runtime *rnRuntime,
|
|
17
18
|
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
|
|
18
19
|
const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker,
|
|
19
|
-
const std::shared_ptr<UIScheduler> &uiScheduler
|
|
20
|
+
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
21
|
+
const std::shared_ptr<const BigStringBuffer> &script,
|
|
22
|
+
const std::string &sourceURL)
|
|
20
23
|
: javaPart_(jni::make_global(jThis)),
|
|
21
24
|
rnRuntime_(rnRuntime),
|
|
22
25
|
workletsModuleProxy_(std::make_shared<WorkletsModuleProxy>(
|
|
@@ -24,8 +27,18 @@ WorkletsModule::WorkletsModule(
|
|
|
24
27
|
std::make_shared<JMessageQueueThread>(messageQueueThread),
|
|
25
28
|
jsCallInvoker,
|
|
26
29
|
uiScheduler,
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
getIsOnJSQueueThread(),
|
|
31
|
+
getForwardedRequestAnimationFrame(),
|
|
32
|
+
script,
|
|
33
|
+
sourceURL)) {
|
|
34
|
+
auto jsiWorkletsModuleProxy =
|
|
35
|
+
workletsModuleProxy_->createJSIWorkletsModuleProxy();
|
|
36
|
+
auto optimizedJsiWorkletsModuleProxy = jsi_utils::optimizedFromHostObject(
|
|
37
|
+
*rnRuntime_,
|
|
38
|
+
std::static_pointer_cast<jsi::HostObject>(
|
|
39
|
+
std::move(jsiWorkletsModuleProxy)));
|
|
40
|
+
RNRuntimeWorkletDecorator::decorate(
|
|
41
|
+
*rnRuntime_, std::move(optimizedJsiWorkletsModuleProxy));
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
jni::local_ref<WorkletsModule::jhybriddata> WorkletsModule::initHybrid(
|
|
@@ -34,13 +47,33 @@ jni::local_ref<WorkletsModule::jhybriddata> WorkletsModule::initHybrid(
|
|
|
34
47
|
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
|
|
35
48
|
jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
|
|
36
49
|
jsCallInvokerHolder,
|
|
37
|
-
jni::alias_ref<worklets::AndroidUIScheduler::javaobject>
|
|
38
|
-
|
|
50
|
+
jni::alias_ref<worklets::AndroidUIScheduler::javaobject> androidUIScheduler
|
|
51
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
52
|
+
,
|
|
53
|
+
jni::alias_ref<facebook::react::BigStringBufferWrapper::javaobject>
|
|
54
|
+
scriptWrapper,
|
|
55
|
+
const std::string &sourceURL
|
|
56
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
57
|
+
) {
|
|
39
58
|
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
|
|
40
59
|
auto rnRuntime = reinterpret_cast<jsi::Runtime *>(jsContext);
|
|
41
60
|
auto uiScheduler = androidUIScheduler->cthis()->getUIScheduler();
|
|
61
|
+
|
|
62
|
+
std::shared_ptr<const BigStringBuffer> script = nullptr;
|
|
63
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
64
|
+
script = scriptWrapper->cthis()->getScript();
|
|
65
|
+
#else
|
|
66
|
+
const auto sourceURL = std::string{};
|
|
67
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
68
|
+
|
|
42
69
|
return makeCxxInstance(
|
|
43
|
-
jThis,
|
|
70
|
+
jThis,
|
|
71
|
+
rnRuntime,
|
|
72
|
+
messageQueueThread,
|
|
73
|
+
jsCallInvoker,
|
|
74
|
+
uiScheduler,
|
|
75
|
+
script,
|
|
76
|
+
sourceURL);
|
|
44
77
|
}
|
|
45
78
|
|
|
46
79
|
std::function<void(std::function<void(const double)>)>
|
|
@@ -57,6 +90,14 @@ WorkletsModule::getForwardedRequestAnimationFrame() {
|
|
|
57
90
|
};
|
|
58
91
|
}
|
|
59
92
|
|
|
93
|
+
std::function<bool()> WorkletsModule::getIsOnJSQueueThread() {
|
|
94
|
+
return [javaPart = javaPart_]() -> bool {
|
|
95
|
+
return javaPart->getClass()
|
|
96
|
+
->getMethod<jboolean()>("isOnJSQueueThread")
|
|
97
|
+
.operator()(javaPart);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
60
101
|
void WorkletsModule::invalidateCpp() {
|
|
61
102
|
javaPart_.reset();
|
|
62
103
|
workletsModuleProxy_.reset();
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
#include <ReactCommon/CallInvokerHolder.h>
|
|
4
4
|
#include <fbjni/fbjni.h>
|
|
5
5
|
#include <jsi/jsi.h>
|
|
6
|
+
#include <jsireact/JSIExecutor.h>
|
|
6
7
|
#include <react/jni/JMessageQueueThread.h>
|
|
8
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
9
|
+
#include <react/fabric/BigStringBufferWrapper.h>
|
|
10
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
7
11
|
|
|
8
12
|
#include <worklets/NativeModules/WorkletsModuleProxy.h>
|
|
9
13
|
#include <worklets/android/AndroidUIScheduler.h>
|
|
@@ -28,7 +32,14 @@ class WorkletsModule : public jni::HybridClass<WorkletsModule> {
|
|
|
28
32
|
jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
|
|
29
33
|
jsCallInvokerHolder,
|
|
30
34
|
jni::alias_ref<worklets::AndroidUIScheduler::javaobject>
|
|
31
|
-
androidUIScheduler
|
|
35
|
+
androidUIScheduler
|
|
36
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
37
|
+
,
|
|
38
|
+
jni::alias_ref<facebook::react::BigStringBufferWrapper::javaobject>
|
|
39
|
+
scriptWrapper,
|
|
40
|
+
const std::string &sourceURL
|
|
41
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
42
|
+
);
|
|
32
43
|
|
|
33
44
|
static void registerNatives();
|
|
34
45
|
|
|
@@ -42,7 +53,9 @@ class WorkletsModule : public jni::HybridClass<WorkletsModule> {
|
|
|
42
53
|
jsi::Runtime *rnRuntime,
|
|
43
54
|
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
|
|
44
55
|
const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker,
|
|
45
|
-
const std::shared_ptr<UIScheduler> &uiScheduler
|
|
56
|
+
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
57
|
+
const std::shared_ptr<const BigStringBuffer> &script,
|
|
58
|
+
const std::string &sourceURL);
|
|
46
59
|
|
|
47
60
|
void invalidateCpp();
|
|
48
61
|
|
|
@@ -54,6 +67,8 @@ class WorkletsModule : public jni::HybridClass<WorkletsModule> {
|
|
|
54
67
|
std::function<void(std::function<void(const double)>)>
|
|
55
68
|
getForwardedRequestAnimationFrame();
|
|
56
69
|
|
|
70
|
+
std::function<bool()> getIsOnJSQueueThread();
|
|
71
|
+
|
|
57
72
|
friend HybridBase;
|
|
58
73
|
jni::global_ref<WorkletsModule::javaobject> javaPart_;
|
|
59
74
|
jsi::Runtime *rnRuntime_;
|
|
@@ -40,7 +40,7 @@ public class WorkletsPackage extends BaseReactPackage implements ReactPackage {
|
|
|
40
40
|
reactModule.canOverrideExistingModule(),
|
|
41
41
|
reactModule.needsEagerInit(),
|
|
42
42
|
reactModule.isCxxModule(),
|
|
43
|
-
|
|
43
|
+
true));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return () -> reactModuleInfoMap;
|
|
@@ -22,7 +22,11 @@ struct WorkletsMessageThreadPublic {
|
|
|
22
22
|
// the app.
|
|
23
23
|
void WorkletsMessageThread::quitSynchronous()
|
|
24
24
|
{
|
|
25
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
26
|
+
// Nothing
|
|
27
|
+
#else
|
|
25
28
|
AssertJavaScriptQueue();
|
|
29
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
26
30
|
RCTMessageThread *rctThread = static_cast<RCTMessageThread *>(this);
|
|
27
31
|
WorkletsMessageThreadPublic *rctThreadPublic = reinterpret_cast<WorkletsMessageThreadPublic *>(rctThread);
|
|
28
32
|
rctThreadPublic->m_shutdown = true;
|
|
@@ -6,7 +6,22 @@
|
|
|
6
6
|
|
|
7
7
|
#import <worklets/NativeModules/WorkletsModuleProxy.h>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
#if __has_include(<React/RCTBundleConsumer.h>)
|
|
10
|
+
// Bundle mode
|
|
11
|
+
#import <React/NSBigStringBuffer.h>
|
|
12
|
+
#import <React/RCTBundleConsumer.h>
|
|
13
|
+
#endif // __has_include(<React/RCTBundleConsumer.h>)
|
|
14
|
+
|
|
15
|
+
@interface WorkletsModule : RCTEventEmitter <
|
|
16
|
+
NativeWorkletsModuleSpec,
|
|
17
|
+
RCTCallInvokerModule,
|
|
18
|
+
RCTInvalidating
|
|
19
|
+
#if __has_include(<React/RCTBundleConsumer.h>)
|
|
20
|
+
// Bundle mode
|
|
21
|
+
,
|
|
22
|
+
RCTBundleConsumer
|
|
23
|
+
#endif // __has_include(<React/RCTBundleConsumer.h>)
|
|
24
|
+
>
|
|
10
25
|
|
|
11
26
|
- (std::shared_ptr<worklets::WorkletsModuleProxy>)getWorkletsModuleProxy;
|
|
12
27
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
#import <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
1
2
|
#import <worklets/Tools/SingleInstanceChecker.h>
|
|
3
|
+
#import <worklets/Tools/WorkletsJSIUtils.h>
|
|
2
4
|
#import <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
|
|
3
5
|
#import <worklets/apple/AnimationFrameQueue.h>
|
|
4
6
|
#import <worklets/apple/AssertJavaScriptQueue.h>
|
|
@@ -6,6 +8,7 @@
|
|
|
6
8
|
#import <worklets/apple/IOSUIScheduler.h>
|
|
7
9
|
#import <worklets/apple/WorkletsMessageThread.h>
|
|
8
10
|
#import <worklets/apple/WorkletsModule.h>
|
|
11
|
+
#import <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
9
12
|
|
|
10
13
|
#import <React/RCTBridge+Private.h>
|
|
11
14
|
#import <React/RCTCallInvoker.h>
|
|
@@ -31,6 +34,12 @@ using worklets::WorkletsModuleProxy;
|
|
|
31
34
|
return workletsModuleProxy_;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
#if __has_include(<React/RCTBundleConsumer.h>)
|
|
38
|
+
// Bundle mode
|
|
39
|
+
@synthesize scriptBuffer = scriptBuffer_;
|
|
40
|
+
@synthesize sourceURL = sourceURL_;
|
|
41
|
+
#endif // __has_include(<React/RCTBundleConsumer.h>)
|
|
42
|
+
|
|
34
43
|
- (void)checkBridgeless
|
|
35
44
|
{
|
|
36
45
|
auto isBridgeless = ![self.bridge isKindOfClass:[RCTCxxBridge class]];
|
|
@@ -55,16 +64,34 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installTurboModule)
|
|
|
55
64
|
throw error;
|
|
56
65
|
});
|
|
57
66
|
|
|
67
|
+
std::string sourceURL = "";
|
|
68
|
+
std::shared_ptr<const BigStringBuffer> script = nullptr;
|
|
69
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
70
|
+
script = [scriptBuffer_ getBuffer];
|
|
71
|
+
sourceURL = [sourceURL_ UTF8String];
|
|
72
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
73
|
+
|
|
58
74
|
auto jsCallInvoker = _callInvoker.callInvoker;
|
|
59
75
|
auto uiScheduler = std::make_shared<worklets::IOSUIScheduler>();
|
|
76
|
+
auto isJavaScriptQueue = []() -> bool { return IsJavaScriptQueue(); };
|
|
60
77
|
animationFrameQueue_ = [AnimationFrameQueue new];
|
|
61
78
|
auto forwardedRequestAnimationFrame = std::function<void(std::function<void(const double)>)>(
|
|
62
79
|
[animationFrameQueue = animationFrameQueue_](std::function<void(const double)> callback) {
|
|
63
80
|
[animationFrameQueue requestAnimationFrame:callback];
|
|
64
81
|
});
|
|
65
82
|
workletsModuleProxy_ = std::make_shared<WorkletsModuleProxy>(
|
|
66
|
-
rnRuntime,
|
|
67
|
-
|
|
83
|
+
rnRuntime,
|
|
84
|
+
jsQueue,
|
|
85
|
+
jsCallInvoker,
|
|
86
|
+
uiScheduler,
|
|
87
|
+
std::move(isJavaScriptQueue),
|
|
88
|
+
std::move(forwardedRequestAnimationFrame),
|
|
89
|
+
script,
|
|
90
|
+
sourceURL);
|
|
91
|
+
auto jsiWorkletsModuleProxy = workletsModuleProxy_->createJSIWorkletsModuleProxy();
|
|
92
|
+
auto optimizedJsiWorkletsModuleProxy = worklets::jsi_utils::optimizedFromHostObject(
|
|
93
|
+
rnRuntime, std::static_pointer_cast<jsi::HostObject>(std::move(jsiWorkletsModuleProxy)));
|
|
94
|
+
RNRuntimeWorkletDecorator::decorate(rnRuntime, std::move(optimizedJsiWorkletsModuleProxy));
|
|
68
95
|
|
|
69
96
|
return @YES;
|
|
70
97
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const workletsPackageParentDir = path.resolve(__dirname, '../..');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
bundleModeMetroConfig: {
|
|
7
|
+
serializer: {
|
|
8
|
+
getModulesRunBeforeMainModule() {
|
|
9
|
+
return [
|
|
10
|
+
require.resolve('react-native-worklets/src/workletRuntimeEntry.ts'),
|
|
11
|
+
require.resolve(
|
|
12
|
+
'react-native-worklets/lib/module/workletRuntimeEntry.js'
|
|
13
|
+
),
|
|
14
|
+
];
|
|
15
|
+
},
|
|
16
|
+
createModuleIdFactory() {
|
|
17
|
+
let nextId = 0;
|
|
18
|
+
const idFileMap = new Map();
|
|
19
|
+
return (/** @type {string} */ moduleName) => {
|
|
20
|
+
if (idFileMap.has(moduleName)) {
|
|
21
|
+
return idFileMap.get(moduleName);
|
|
22
|
+
}
|
|
23
|
+
if (
|
|
24
|
+
moduleName.includes('react-native-worklets/__generatedWorklets/')
|
|
25
|
+
) {
|
|
26
|
+
const base = path.basename(moduleName, '.js');
|
|
27
|
+
const id = Number(base);
|
|
28
|
+
idFileMap.set(moduleName, id);
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
idFileMap.set(moduleName, nextId++);
|
|
32
|
+
return idFileMap.get(moduleName);
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
resolver: {
|
|
37
|
+
resolveRequest: (
|
|
38
|
+
/** @type {any} */ context,
|
|
39
|
+
/** @type {string} */ moduleName,
|
|
40
|
+
/** @type {any} */ platform
|
|
41
|
+
) => {
|
|
42
|
+
if (
|
|
43
|
+
moduleName.startsWith('react-native-worklets/__generatedWorklets/')
|
|
44
|
+
) {
|
|
45
|
+
const fullModuleName = path.join(
|
|
46
|
+
workletsPackageParentDir,
|
|
47
|
+
moduleName
|
|
48
|
+
);
|
|
49
|
+
return { type: 'sourceFile', filePath: fullModuleName };
|
|
50
|
+
}
|
|
51
|
+
return context.resolveRequest(context, moduleName, platform);
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
export const IS_JEST = !!process.env.JEST_WORKER_ID;
|
|
5
|
+
export const IS_WEB = Platform.OS === 'web';
|
|
6
|
+
export const IS_WINDOWS = Platform.OS === 'windows';
|
|
7
|
+
export const SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
|
|
8
|
+
//# sourceMappingURL=PlatformChecker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","IS_JEST","process","env","JEST_WORKER_ID","IS_WEB","OS","IS_WINDOWS","SHOULD_BE_USE_WEB"],"sourceRoot":"../../../src","sources":["PlatformChecker/PlatformChecker.ts"],"mappings":"AAAA,YAAY;;AACZ,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,OAAgB,GAAG,CAAC,CAACC,OAAO,CAACC,GAAG,CAACC,cAAc;AAC5D,OAAO,MAAMC,MAAe,GAAGL,QAAQ,CAACM,EAAE,KAAK,KAAK;AACpD,OAAO,MAAMC,UAAmB,GAAGP,QAAQ,CAACM,EAAE,KAAK,SAAS;AAC5D,OAAO,MAAME,iBAA0B,GAAGP,OAAO,IAAII,MAAM,IAAIE,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { IS_JEST as RN_IS_JEST, IS_WEB as RN_IS_WEB, IS_WINDOWS as RN_IS_WINDOWS, SHOULD_BE_USE_WEB as RN_SHOULD_BE_USE_WEB } from "./PlatformChecker.js";
|
|
4
|
+
let IS_JEST = false;
|
|
5
|
+
let IS_WEB = false;
|
|
6
|
+
let IS_WINDOWS = false;
|
|
7
|
+
let SHOULD_BE_USE_WEB = false;
|
|
8
|
+
if (!globalThis._WORKLET) {
|
|
9
|
+
IS_JEST = RN_IS_JEST;
|
|
10
|
+
IS_WEB = RN_IS_WEB;
|
|
11
|
+
IS_WINDOWS = RN_IS_WINDOWS;
|
|
12
|
+
SHOULD_BE_USE_WEB = RN_SHOULD_BE_USE_WEB;
|
|
13
|
+
}
|
|
14
|
+
export { IS_JEST, /** @knipIgnore */
|
|
15
|
+
IS_WEB, /** @knipIgnore */
|
|
16
|
+
IS_WINDOWS, SHOULD_BE_USE_WEB };
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["IS_JEST","RN_IS_JEST","IS_WEB","RN_IS_WEB","IS_WINDOWS","RN_IS_WINDOWS","SHOULD_BE_USE_WEB","RN_SHOULD_BE_USE_WEB","globalThis","_WORKLET"],"sourceRoot":"../../../src","sources":["PlatformChecker/index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SACEA,OAAO,IAAIC,UAAU,EACrBC,MAAM,IAAIC,SAAS,EACnBC,UAAU,IAAIC,aAAa,EAC3BC,iBAAiB,IAAIC,oBAAoB,QACpC,sBAAmB;AAE1B,IAAIP,OAAO,GAAG,KAAK;AACnB,IAAIE,MAAM,GAAG,KAAK;AAClB,IAAIE,UAAU,GAAG,KAAK;AACtB,IAAIE,iBAAiB,GAAG,KAAK;AAE7B,IAAI,CAACE,UAAU,CAACC,QAAQ,EAAE;EACxBT,OAAO,GAAGC,UAAU;EACpBC,MAAM,GAAGC,SAAS;EAClBC,UAAU,GAAGC,aAAa;EAC1BC,iBAAiB,GAAGC,oBAAoB;AAC1C;AAEA,SACEP,OAAO,EACP;AACAE,MAAM,EACN;AACAE,UAAU,EACVE,iBAAiB","ignoreList":[]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/* eslint-disable reanimated/use-worklets-error */
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
function WorkletsErrorConstructor(message) {
|
|
5
4
|
'worklet';
|
|
6
5
|
|
|
7
6
|
const prefix = '[Worklets]';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line reanimated/use-worklets-error
|
|
8
9
|
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
|
|
9
10
|
errorInstance.name = `WorkletsError`;
|
|
10
11
|
return errorInstance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["WorkletsErrorConstructor","message","prefix","errorInstance","Error","name","registerWorkletsError","globalThis","_WORKLET","WorkletsError"],"sourceRoot":"../../src","sources":["WorkletsError.ts"],"mappings":"AAAA
|
|
1
|
+
{"version":3,"names":["WorkletsErrorConstructor","message","prefix","errorInstance","Error","name","registerWorkletsError","globalThis","_WORKLET","WorkletsError"],"sourceRoot":"../../src","sources":["WorkletsError.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,wBAAwBA,CAACC,OAAgB,EAAiB;EACjE,SAAS;;EACT,MAAMC,MAAM,GAAG,YAAY;;EAE3B;EACA,MAAMC,aAAa,GAAG,IAAIC,KAAK,CAACH,OAAO,GAAG,GAAGC,MAAM,IAAID,OAAO,EAAE,GAAGC,MAAM,CAAC;EAC1EC,aAAa,CAACE,IAAI,GAAG,eAAe;EACpC,OAAOF,aAAa;AACtB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAAA,EAAG;EACtC,SAAS;;EACT,IAAIC,UAAU,CAACC,QAAQ,EAAE;IACvBD,UAAU,CAACE,aAAa,GACtBT,wBAAqD;EACzD;AACF;AAEA,OAAO,MAAMS,aAAa,GACxBT,wBAAqD;;AAEG","ignoreList":[]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/* eslint-disable reanimated/use-reanimated-error */
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { IS_JEST } from "../PlatformChecker/index.js";
|
|
4
|
+
import { mockedRequestAnimationFrame } from "../runLoop/mockedRequestAnimationFrame.js";
|
|
6
5
|
import { WorkletsError } from "../WorkletsError.js";
|
|
7
6
|
export function createJSWorkletsModule() {
|
|
8
7
|
return new JSWorklets();
|
|
@@ -11,7 +10,7 @@ export function createJSWorkletsModule() {
|
|
|
11
10
|
// In Node.js environments (like when static rendering with Expo Router)
|
|
12
11
|
// requestAnimationFrame is unavailable, so we use our mock.
|
|
13
12
|
// It also has to be mocked for Jest purposes (see `initializeUIRuntime`).
|
|
14
|
-
const requestAnimationFrameImpl =
|
|
13
|
+
const requestAnimationFrameImpl = IS_JEST || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
15
14
|
class JSWorklets {
|
|
16
15
|
makeShareableClone() {
|
|
17
16
|
throw new WorkletsError('makeShareableClone should never be called in JSWorklets.');
|
|
@@ -34,6 +33,36 @@ class JSWorklets {
|
|
|
34
33
|
makeShareableNull() {
|
|
35
34
|
throw new WorkletsError('makeShareableNull should never be called in JSWorklets.');
|
|
36
35
|
}
|
|
36
|
+
makeShareableTurboModuleLike() {
|
|
37
|
+
throw new WorkletsError('makeShareableTurboModuleLike should never be called in JSWorklets.');
|
|
38
|
+
}
|
|
39
|
+
makeShareableObject() {
|
|
40
|
+
throw new WorkletsError('makeShareableObject should never be called in JSWorklets.');
|
|
41
|
+
}
|
|
42
|
+
makeShareableMap() {
|
|
43
|
+
throw new WorkletsError('makeShareableMap should never be called in JSWorklets.');
|
|
44
|
+
}
|
|
45
|
+
makeShareableSet() {
|
|
46
|
+
throw new WorkletsError('makeShareableSet should never be called in JSWorklets.');
|
|
47
|
+
}
|
|
48
|
+
makeShareableImport() {
|
|
49
|
+
throw new WorkletsError('makeShareableImport should never be called in JSWorklets.');
|
|
50
|
+
}
|
|
51
|
+
makeShareableHostObject() {
|
|
52
|
+
throw new WorkletsError('makeShareableHostObject should never be called in JSWorklets.');
|
|
53
|
+
}
|
|
54
|
+
makeShareableArray() {
|
|
55
|
+
throw new WorkletsError('makeShareableArray should never be called in JSWorklets.');
|
|
56
|
+
}
|
|
57
|
+
makeShareableInitializer() {
|
|
58
|
+
throw new WorkletsError('makeShareableInitializer should never be called in JSWorklets.');
|
|
59
|
+
}
|
|
60
|
+
makeShareableFunction(_func) {
|
|
61
|
+
throw new WorkletsError('makeShareableRemoteFunction should never be called in JSWorklets.');
|
|
62
|
+
}
|
|
63
|
+
makeShareableWorklet() {
|
|
64
|
+
throw new WorkletsError('makeShareableWorklet should never be called in JSWorklets.');
|
|
65
|
+
}
|
|
37
66
|
scheduleOnUI(worklet) {
|
|
38
67
|
// TODO: `requestAnimationFrame` should be used exclusively in Reanimated
|
|
39
68
|
|
|
@@ -50,5 +79,8 @@ class JSWorklets {
|
|
|
50
79
|
scheduleOnRuntime() {
|
|
51
80
|
throw new WorkletsError('scheduleOnRuntime is not available in JSWorklets.');
|
|
52
81
|
}
|
|
82
|
+
reportFatalErrorOnJS() {
|
|
83
|
+
throw new WorkletsError('reportFatalErrorOnJS should never be called in JSWorklets.');
|
|
84
|
+
}
|
|
53
85
|
}
|
|
54
86
|
//# sourceMappingURL=JSWorklets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["IS_JEST","mockedRequestAnimationFrame","WorkletsError","createJSWorkletsModule","JSWorklets","requestAnimationFrameImpl","globalThis","requestAnimationFrame","makeShareableClone","makeShareableString","makeShareableNumber","makeShareableBoolean","makeShareableBigInt","makeShareableUndefined","makeShareableNull","makeShareableTurboModuleLike","makeShareableObject","makeShareableMap","makeShareableSet","makeShareableImport","makeShareableHostObject","makeShareableArray","makeShareableInitializer","makeShareableFunction","_func","makeShareableWorklet","scheduleOnUI","worklet","executeOnUIRuntimeSync","_shareable","createWorkletRuntime","_name","_initializer","scheduleOnRuntime","reportFatalErrorOnJS"],"sourceRoot":"../../../src","sources":["WorkletsModule/JSWorklets.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,OAAO,QAAQ,6BAAoB;AAC5C,SAASC,2BAA2B,QAAQ,2CAAwC;AACpF,SAASC,aAAa,QAAQ,qBAAkB;AAIhD,OAAO,SAASC,sBAAsBA,CAAA,EAAoB;EACxD,OAAO,IAAIC,UAAU,CAAC,CAAC;AACzB;;AAEA;AACA;AACA;AACA,MAAMC,yBAAyB,GAC7BL,OAAO,IAAI,CAACM,UAAU,CAACC,qBAAqB,GACxCN,2BAA2B,GAC3BK,UAAU,CAACC,qBAAqB;AAEtC,MAAMH,UAAU,CAA4B;EAC1CI,kBAAkBA,CAAA,EAAiC;IACjD,MAAM,IAAIN,aAAa,CACrB,0DACF,CAAC;EACH;EAEAO,mBAAmBA,CAAA,EAAyB;IAC1C,MAAM,IAAIP,aAAa,CACrB,2DACF,CAAC;EACH;EAEAQ,mBAAmBA,CAAA,EAAyB;IAC1C,MAAM,IAAIR,aAAa,CACrB,2DACF,CAAC;EACH;EAEAS,oBAAoBA,CAAA,EAA0B;IAC5C,MAAM,IAAIT,aAAa,CACrB,4DACF,CAAC;EACH;EAEAU,mBAAmBA,CAAA,EAAyB;IAC1C,MAAM,IAAIV,aAAa,CACrB,2DACF,CAAC;EACH;EAEAW,sBAAsBA,CAAA,EAA4B;IAChD,MAAM,IAAIX,aAAa,CACrB,8DACF,CAAC;EACH;EAEAY,iBAAiBA,CAAA,EAAuB;IACtC,MAAM,IAAIZ,aAAa,CACrB,yDACF,CAAC;EACH;EAEAa,4BAA4BA,CAAA,EAAsC;IAChE,MAAM,IAAIb,aAAa,CACrB,oEACF,CAAC;EACH;EAEAc,mBAAmBA,CAAA,EAAsC;IACvD,MAAM,IAAId,aAAa,CACrB,2DACF,CAAC;EACH;EAEAe,gBAAgBA,CAAA,EAAU;IACxB,MAAM,IAAIf,aAAa,CACrB,wDACF,CAAC;EACH;EAEAgB,gBAAgBA,CAAA,EAAU;IACxB,MAAM,IAAIhB,aAAa,CACrB,wDACF,CAAC;EACH;EAEAiB,mBAAmBA,CAAA,EAAU;IAC3B,MAAM,IAAIjB,aAAa,CACrB,2DACF,CAAC;EACH;EAEAkB,uBAAuBA,CAAA,EAAsC;IAC3D,MAAM,IAAIlB,aAAa,CACrB,+DACF,CAAC;EACH;EAEAmB,kBAAkBA,CAAA,EAA4B;IAC5C,MAAM,IAAInB,aAAa,CACrB,0DACF,CAAC;EACH;EAEAoB,wBAAwBA,CAAA,EAAyB;IAC/C,MAAM,IAAIpB,aAAa,CACrB,gEACF,CAAC;EACH;EAEAqB,qBAAqBA,CACnBC,KAAkC,EACX;IACvB,MAAM,IAAItB,aAAa,CACrB,mEACF,CAAC;EACH;EAEAuB,oBAAoBA,CAAA,EAAyB;IAC3C,MAAM,IAAIvB,aAAa,CACrB,4DACF,CAAC;EACH;EAEAwB,YAAYA,CAASC,OAA6B,EAAE;IAClD;;IAEA;IACA;IACAtB,yBAAyB,CAACsB,OAAO,CAAC;EACpC;EAEAC,sBAAsBA,CAAOC,UAA2B,EAAK;IAC3D,MAAM,IAAI3B,aAAa,CACrB,0DACF,CAAC;EACH;EAEA4B,oBAAoBA,CAClBC,KAAa,EACbC,YAAsC,EACtB;IAChB,MAAM,IAAI9B,aAAa,CACrB,sDACF,CAAC;EACH;EAEA+B,iBAAiBA,CAAA,EAAG;IAClB,MAAM,IAAI/B,aAAa,CACrB,mDACF,CAAC;EACH;EAEAgC,oBAAoBA,CAAA,EAAU;IAC5B,MAAM,IAAIhC,aAAa,CACrB,4DACF,CAAC;EACH;AACF","ignoreList":[]}
|