react-native-worklets 0.11.2 → 0.11.4
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/RunLoop/AsyncQueueImpl.cpp +32 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +24 -6
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +24 -6
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/package.json +1 -1
- package/plugin/index.js +6 -4
- package/src/debug/jsVersion.ts +1 -1
|
@@ -9,11 +9,40 @@
|
|
|
9
9
|
#include <thread>
|
|
10
10
|
#include <utility>
|
|
11
11
|
|
|
12
|
+
#if __APPLE__
|
|
13
|
+
extern "C" {
|
|
14
|
+
void *objc_autoreleasePoolPush(void);
|
|
15
|
+
void objc_autoreleasePoolPop(void *pool);
|
|
16
|
+
}
|
|
17
|
+
#endif // __APPLE__
|
|
18
|
+
|
|
12
19
|
namespace worklets {
|
|
13
20
|
|
|
14
21
|
using namespace facebook;
|
|
15
22
|
|
|
23
|
+
#if __APPLE__
|
|
24
|
+
namespace {
|
|
25
|
+
|
|
26
|
+
class ScopedAutoreleasePool {
|
|
27
|
+
public:
|
|
28
|
+
ScopedAutoreleasePool() : pool_(objc_autoreleasePoolPush()) {}
|
|
29
|
+
~ScopedAutoreleasePool() {
|
|
30
|
+
objc_autoreleasePoolPop(pool_);
|
|
31
|
+
}
|
|
32
|
+
ScopedAutoreleasePool(const ScopedAutoreleasePool &) = delete;
|
|
33
|
+
ScopedAutoreleasePool &operator=(const ScopedAutoreleasePool &) = delete;
|
|
34
|
+
|
|
35
|
+
private:
|
|
36
|
+
void *const pool_;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
} // namespace
|
|
40
|
+
#endif // __APPLE__
|
|
41
|
+
|
|
16
42
|
void AsyncQueueImpl::runLoop(const std::shared_ptr<AsyncQueueState> &state) {
|
|
43
|
+
#if __APPLE__
|
|
44
|
+
const ScopedAutoreleasePool threadAutoreleasePool;
|
|
45
|
+
#endif // __APPLE__
|
|
17
46
|
while (state->running) {
|
|
18
47
|
std::unique_lock<std::mutex> lock(state->mutex);
|
|
19
48
|
state->cv.wait(lock, [state] { return !state->queue.empty() || !state->running; });
|
|
@@ -26,6 +55,9 @@ void AsyncQueueImpl::runLoop(const std::shared_ptr<AsyncQueueState> &state) {
|
|
|
26
55
|
auto job = std::move(state->queue.front());
|
|
27
56
|
state->queue.pop();
|
|
28
57
|
lock.unlock();
|
|
58
|
+
#if __APPLE__
|
|
59
|
+
const ScopedAutoreleasePool autoreleasePool;
|
|
60
|
+
#endif // __APPLE__
|
|
29
61
|
job();
|
|
30
62
|
}
|
|
31
63
|
}
|
|
@@ -14,7 +14,6 @@ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
|
14
14
|
import com.facebook.soloader.SoLoader
|
|
15
15
|
import com.swmansion.worklets.runloop.AnimationFrameCallback
|
|
16
16
|
import com.swmansion.worklets.runloop.AnimationFrameQueue
|
|
17
|
-
import java.util.concurrent.atomic.AtomicBoolean
|
|
18
17
|
|
|
19
18
|
@Suppress("KotlinJniMissingFunction")
|
|
20
19
|
@ReactModule(name = WorkletsModule.NAME)
|
|
@@ -50,7 +49,8 @@ class WorkletsModule(
|
|
|
50
49
|
* Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't
|
|
51
50
|
* cost us much to add synchronization for extra safety.
|
|
52
51
|
*/
|
|
53
|
-
private val
|
|
52
|
+
private val mInvalidationLock = Any()
|
|
53
|
+
private var mInvalidated = false
|
|
54
54
|
|
|
55
55
|
@OptIn(FrameworkAPI::class)
|
|
56
56
|
private external fun initHybrid(
|
|
@@ -161,9 +161,17 @@ class WorkletsModule(
|
|
|
161
161
|
return mSlowAnimationsEnabled
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
override fun initialize() {
|
|
165
|
+
reactApplicationContext.addLifecycleEventListener(this)
|
|
166
|
+
}
|
|
167
|
+
|
|
164
168
|
override fun invalidate() {
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
synchronized(mInvalidationLock) {
|
|
170
|
+
if (mInvalidated) {
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
mInvalidated = true
|
|
174
|
+
reactApplicationContext.removeLifecycleEventListener(this)
|
|
167
175
|
}
|
|
168
176
|
if (mHybridData != null && mHybridData!!.isValid) {
|
|
169
177
|
invalidateCpp()
|
|
@@ -176,11 +184,21 @@ class WorkletsModule(
|
|
|
176
184
|
private external fun startCpp()
|
|
177
185
|
|
|
178
186
|
override fun onHostResume() {
|
|
179
|
-
|
|
187
|
+
synchronized(mInvalidationLock) {
|
|
188
|
+
if (mInvalidated) {
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
mAnimationFrameQueue.resume()
|
|
192
|
+
}
|
|
180
193
|
}
|
|
181
194
|
|
|
182
195
|
override fun onHostPause() {
|
|
183
|
-
|
|
196
|
+
synchronized(mInvalidationLock) {
|
|
197
|
+
if (mInvalidated) {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
mAnimationFrameQueue.pause()
|
|
201
|
+
}
|
|
184
202
|
}
|
|
185
203
|
|
|
186
204
|
override fun onHostDestroy() {}
|
|
@@ -11,7 +11,6 @@ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
|
11
11
|
import com.facebook.soloader.SoLoader
|
|
12
12
|
import com.swmansion.worklets.runloop.AnimationFrameCallback
|
|
13
13
|
import com.swmansion.worklets.runloop.AnimationFrameQueue
|
|
14
|
-
import java.util.concurrent.atomic.AtomicBoolean
|
|
15
14
|
|
|
16
15
|
@Suppress("KotlinJniMissingFunction")
|
|
17
16
|
@ReactModule(name = WorkletsModule.NAME)
|
|
@@ -46,7 +45,8 @@ class WorkletsModule(
|
|
|
46
45
|
* Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't
|
|
47
46
|
* cost us much to add synchronization for extra safety.
|
|
48
47
|
*/
|
|
49
|
-
private val
|
|
48
|
+
private val mInvalidationLock = Any()
|
|
49
|
+
private var mInvalidated = false
|
|
50
50
|
|
|
51
51
|
@OptIn(FrameworkAPI::class)
|
|
52
52
|
private external fun initHybrid(
|
|
@@ -117,9 +117,17 @@ class WorkletsModule(
|
|
|
117
117
|
return mSlowAnimationsEnabled
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
override fun initialize() {
|
|
121
|
+
reactApplicationContext.addLifecycleEventListener(this)
|
|
122
|
+
}
|
|
123
|
+
|
|
120
124
|
override fun invalidate() {
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
synchronized(mInvalidationLock) {
|
|
126
|
+
if (mInvalidated) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
mInvalidated = true
|
|
130
|
+
reactApplicationContext.removeLifecycleEventListener(this)
|
|
123
131
|
}
|
|
124
132
|
if (mHybridData != null && mHybridData!!.isValid) {
|
|
125
133
|
invalidateCpp()
|
|
@@ -132,11 +140,21 @@ class WorkletsModule(
|
|
|
132
140
|
private external fun startCpp()
|
|
133
141
|
|
|
134
142
|
override fun onHostResume() {
|
|
135
|
-
|
|
143
|
+
synchronized(mInvalidationLock) {
|
|
144
|
+
if (mInvalidated) {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
mAnimationFrameQueue.resume()
|
|
148
|
+
}
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
override fun onHostPause() {
|
|
139
|
-
|
|
152
|
+
synchronized(mInvalidationLock) {
|
|
153
|
+
if (mInvalidated) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
mAnimationFrameQueue.pause()
|
|
157
|
+
}
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
override fun onHostDestroy() {}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* version used to build the native part of the library in runtime. Remember to
|
|
4
4
|
* keep this in sync with the version declared in `package.json`
|
|
5
5
|
*/
|
|
6
|
-
export declare const jsVersion = "0.11.
|
|
6
|
+
export declare const jsVersion = "0.11.4";
|
|
7
7
|
//# sourceMappingURL=jsVersion.d.ts.map
|
package/package.json
CHANGED
package/plugin/index.js
CHANGED
|
@@ -424,6 +424,7 @@ var require_globals = __commonJS({
|
|
|
424
424
|
exports2.isGeneratedWorkletFile = isGeneratedWorkletFile;
|
|
425
425
|
exports2.initializeGlobals = initializeGlobals;
|
|
426
426
|
exports2.addCustomGlobals = addCustomGlobals;
|
|
427
|
+
var assert_1 = require("assert");
|
|
427
428
|
var path_1 = __importDefault(require("path"));
|
|
428
429
|
var autoworkletization_12 = require_autoworkletization();
|
|
429
430
|
var types_12 = require_types();
|
|
@@ -565,7 +566,8 @@ var require_globals = __commonJS({
|
|
|
565
566
|
addCustomGlobals(state);
|
|
566
567
|
}
|
|
567
568
|
const userImportForwarding = state.opts.importForwarding;
|
|
568
|
-
state.
|
|
569
|
+
(0, assert_1.strict)(state.importForwarding === void 0, "state.importForwarding should be undefined at this point");
|
|
570
|
+
state.importForwarding = {
|
|
569
571
|
relativePaths: [
|
|
570
572
|
...defaultAllowedPaths,
|
|
571
573
|
...(_a = userImportForwarding === null || userImportForwarding === void 0 ? void 0 : userImportForwarding.relativePaths) !== null && _a !== void 0 ? _a : []
|
|
@@ -624,7 +626,7 @@ var require_imports = __commonJS({
|
|
|
624
626
|
var _a;
|
|
625
627
|
if (nodePath.get("callee").isIdentifier({ name: "require" }) && ((_a = nodePath.get("arguments")[0]) === null || _a === void 0 ? void 0 : _a.isStringLiteral())) {
|
|
626
628
|
const requiredModule = nodePath.get("arguments")[0];
|
|
627
|
-
if (requiredModule.node.value.startsWith(".") && canForwardRelativeImport(state.file.opts.filename || "", state.
|
|
629
|
+
if (requiredModule.node.value.startsWith(".") && canForwardRelativeImport(state.file.opts.filename || "", state.importForwarding.relativePaths)) {
|
|
628
630
|
requiredModule.replaceWith(createImportPathLiteral(requiredModule.node.value, state));
|
|
629
631
|
}
|
|
630
632
|
}
|
|
@@ -721,13 +723,13 @@ var require_closure = __commonJS({
|
|
|
721
723
|
scope = scope.parent;
|
|
722
724
|
}
|
|
723
725
|
if (state.opts.bundleMode && (0, imports_1.isImport)(binding)) {
|
|
724
|
-
if ((0, imports_1.isImportRelative)(binding) && (0, imports_1.canForwardRelativeImport)(state.filename, state.
|
|
726
|
+
if ((0, imports_1.isImportRelative)(binding) && (0, imports_1.canForwardRelativeImport)(state.filename, state.importForwarding.relativePaths)) {
|
|
725
727
|
capturedNames.add(name);
|
|
726
728
|
relativeBindingsToImport.add(binding);
|
|
727
729
|
return;
|
|
728
730
|
}
|
|
729
731
|
const source = binding.path.parentPath.node.source.value;
|
|
730
|
-
if ((0, imports_1.canForwardModuleImport)(source, state.
|
|
732
|
+
if ((0, imports_1.canForwardModuleImport)(source, state.importForwarding.moduleNames)) {
|
|
731
733
|
capturedNames.add(name);
|
|
732
734
|
moduleBindingsToImport.add(binding);
|
|
733
735
|
return;
|
package/src/debug/jsVersion.ts
CHANGED