react-native-reanimated 3.0.0-rc.7 → 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/android/src/main/cpp/LayoutAnimations.cpp +6 -16
- package/android/src/main/cpp/LayoutAnimations.h +4 -4
- package/android/src/main/cpp/NativeProxy.cpp +50 -63
- package/ios/native/NativeProxy.mm +26 -42
- package/lib/commonjs/createAnimatedComponent.js +7 -11
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -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 +24 -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 +1 -1
- package/plugin.js +31 -15
- package/src/createAnimatedComponent.tsx +8 -24
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +34 -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 +26 -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
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createMapperRegistry = createMapperRegistry;
|
|
7
|
+
exports.startMapper = startMapper;
|
|
8
|
+
exports.stopMapper = stopMapper;
|
|
9
|
+
|
|
10
|
+
var _threads = require("./threads");
|
|
11
|
+
|
|
12
|
+
function createMapperRegistry() {
|
|
13
|
+
'worklet';
|
|
14
|
+
|
|
15
|
+
const mappers = new Map();
|
|
16
|
+
let sortedMappers = [];
|
|
17
|
+
let frameRequested = false;
|
|
18
|
+
|
|
19
|
+
function updateMappersOrder() {
|
|
20
|
+
// sort mappers topologically
|
|
21
|
+
// the algorithm here takes adventage of a fact that the topological order
|
|
22
|
+
// of a transposed graph is a reverse topological order of the original graph
|
|
23
|
+
// The graph in our case consists of mappers and an edge between two mappers
|
|
24
|
+
// A and B exists if there is a shared value that's on A's output lists and on
|
|
25
|
+
// B's input list.
|
|
26
|
+
//
|
|
27
|
+
// We don't need however to calculate that graph as it is easier to work with
|
|
28
|
+
// the transposed version of it that can be calculated ad-hoc. For the transposed
|
|
29
|
+
// version to be traversed we use "pre" map that maps share value to mappers that
|
|
30
|
+
// output that shared value. Then we can infer all the outgoing edges for a given
|
|
31
|
+
// mapper simply by scanning it's input list and checking if any of the shared values
|
|
32
|
+
// from that list exists in the "pre" map. If they do, then we have an edge between
|
|
33
|
+
// that mapper and the mappers from the "pre" list for the given shared value.
|
|
34
|
+
//
|
|
35
|
+
// For topological sorting we use a dfs-based approach that requires the graph to
|
|
36
|
+
// be traversed in dfs order and each node after being processed lands at the
|
|
37
|
+
// beginning of the topological order list. Since we traverse a transposed graph,
|
|
38
|
+
// instead of reversing that order we can use a normal array and push processed
|
|
39
|
+
// mappers to the end. There is no need to reverse that array after we are done.
|
|
40
|
+
const pre = new Map(); // map from sv -> mapper that outputs that sv
|
|
41
|
+
|
|
42
|
+
mappers.forEach(mapper => {
|
|
43
|
+
if (mapper.outputs) {
|
|
44
|
+
for (const output of mapper.outputs) {
|
|
45
|
+
const preMappers = pre.get(output);
|
|
46
|
+
|
|
47
|
+
if (preMappers === undefined) {
|
|
48
|
+
pre.set(output, [mapper]);
|
|
49
|
+
} else {
|
|
50
|
+
preMappers.push(mapper);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const visited = new Set();
|
|
56
|
+
const newOrder = [];
|
|
57
|
+
|
|
58
|
+
function dfs(mapper) {
|
|
59
|
+
visited.add(mapper);
|
|
60
|
+
|
|
61
|
+
for (const input of mapper.inputs) {
|
|
62
|
+
const preMappers = pre.get(input);
|
|
63
|
+
|
|
64
|
+
if (preMappers) {
|
|
65
|
+
for (const preMapper of preMappers) {
|
|
66
|
+
if (!visited.has(preMapper)) {
|
|
67
|
+
dfs(preMapper);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
newOrder.push(mapper);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
mappers.forEach(mapper => {
|
|
77
|
+
if (!visited.has(mapper)) {
|
|
78
|
+
dfs(mapper);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
sortedMappers = newOrder;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function mapperFrame() {
|
|
85
|
+
frameRequested = false;
|
|
86
|
+
|
|
87
|
+
if (mappers.size !== sortedMappers.length) {
|
|
88
|
+
updateMappersOrder();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const mapper of sortedMappers) {
|
|
92
|
+
if (mapper.dirty) {
|
|
93
|
+
mapper.dirty = false;
|
|
94
|
+
mapper.worklet();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function maybeRequestUpdates() {
|
|
100
|
+
if (!frameRequested) {
|
|
101
|
+
requestAnimationFrame(mapperFrame);
|
|
102
|
+
frameRequested = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function extractInputs(inputs, resultArray) {
|
|
107
|
+
if (Array.isArray(inputs)) {
|
|
108
|
+
for (const input of inputs) {
|
|
109
|
+
input && extractInputs(input, resultArray);
|
|
110
|
+
}
|
|
111
|
+
} else if (inputs.addListener) {
|
|
112
|
+
resultArray.push(inputs);
|
|
113
|
+
} else if (typeof inputs === 'object') {
|
|
114
|
+
for (const element of Object.values(inputs)) {
|
|
115
|
+
element && extractInputs(element, resultArray);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return resultArray;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
start: (mapperID, worklet, inputs, outputs) => {
|
|
124
|
+
const mapper = {
|
|
125
|
+
id: mapperID,
|
|
126
|
+
dirty: true,
|
|
127
|
+
worklet,
|
|
128
|
+
inputs: extractInputs(inputs, []),
|
|
129
|
+
outputs
|
|
130
|
+
};
|
|
131
|
+
mappers.set(mapper.id, mapper);
|
|
132
|
+
sortedMappers = [];
|
|
133
|
+
|
|
134
|
+
for (const sv of mapper.inputs) {
|
|
135
|
+
sv.addListener(mapper.id, () => {
|
|
136
|
+
mapper.dirty = true;
|
|
137
|
+
maybeRequestUpdates();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
maybeRequestUpdates();
|
|
142
|
+
},
|
|
143
|
+
stop: mapperID => {
|
|
144
|
+
const mapper = mappers.get(mapperID);
|
|
145
|
+
|
|
146
|
+
if (mapper) {
|
|
147
|
+
mappers.delete(mapper.id);
|
|
148
|
+
sortedMappers = [];
|
|
149
|
+
|
|
150
|
+
for (const sv of mapper.inputs) {
|
|
151
|
+
sv.removeListener(mapper.id);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let MAPPER_ID = 9999;
|
|
159
|
+
|
|
160
|
+
function startMapper(worklet) {
|
|
161
|
+
let inputs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
162
|
+
let outputs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
163
|
+
const mapperID = MAPPER_ID += 1;
|
|
164
|
+
(0, _threads.runOnUI)(() => {
|
|
165
|
+
'worklet';
|
|
166
|
+
|
|
167
|
+
let mapperRegistry = global.__mapperRegistry;
|
|
168
|
+
|
|
169
|
+
if (mapperRegistry === undefined) {
|
|
170
|
+
mapperRegistry = global.__mapperRegistry = createMapperRegistry();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
mapperRegistry.start(mapperID, worklet, inputs, outputs);
|
|
174
|
+
})();
|
|
175
|
+
return mapperID;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function stopMapper(mapperID) {
|
|
179
|
+
(0, _threads.runOnUI)(() => {
|
|
180
|
+
'worklet';
|
|
181
|
+
|
|
182
|
+
const mapperRegistry = global.__mapperRegistry;
|
|
183
|
+
mapperRegistry === null || mapperRegistry === void 0 ? void 0 : mapperRegistry.stop(mapperID);
|
|
184
|
+
})();
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createMapperRegistry","mappers","Map","sortedMappers","frameRequested","updateMappersOrder","pre","forEach","mapper","outputs","output","preMappers","get","undefined","set","push","visited","Set","newOrder","dfs","add","input","inputs","preMapper","has","mapperFrame","size","length","dirty","worklet","maybeRequestUpdates","requestAnimationFrame","extractInputs","resultArray","Array","isArray","addListener","element","Object","values","start","mapperID","id","sv","stop","delete","removeListener","MAPPER_ID","startMapper","runOnUI","mapperRegistry","global","__mapperRegistry","stopMapper"],"sources":["mappers.ts"],"sourcesContent":["import { SharedValue } from './commonTypes';\nimport { runOnUI } from './threads';\n\nexport type Mapper = {\n id: number;\n dirty: boolean;\n worklet: () => void;\n inputs: SharedValue<any>[];\n outputs?: SharedValue<any>[];\n};\n\nexport function createMapperRegistry() {\n 'worklet';\n const mappers = new Map();\n let sortedMappers: Mapper[] = [];\n\n let frameRequested = false;\n\n function updateMappersOrder() {\n // sort mappers topologically\n // the algorithm here takes adventage of a fact that the topological order\n // of a transposed graph is a reverse topological order of the original graph\n // The graph in our case consists of mappers and an edge between two mappers\n // A and B exists if there is a shared value that's on A's output lists and on\n // B's input list.\n //\n // We don't need however to calculate that graph as it is easier to work with\n // the transposed version of it that can be calculated ad-hoc. For the transposed\n // version to be traversed we use \"pre\" map that maps share value to mappers that\n // output that shared value. Then we can infer all the outgoing edges for a given\n // mapper simply by scanning it's input list and checking if any of the shared values\n // from that list exists in the \"pre\" map. If they do, then we have an edge between\n // that mapper and the mappers from the \"pre\" list for the given shared value.\n //\n // For topological sorting we use a dfs-based approach that requires the graph to\n // be traversed in dfs order and each node after being processed lands at the\n // beginning of the topological order list. Since we traverse a transposed graph,\n // instead of reversing that order we can use a normal array and push processed\n // mappers to the end. There is no need to reverse that array after we are done.\n const pre = new Map(); // map from sv -> mapper that outputs that sv\n mappers.forEach((mapper) => {\n if (mapper.outputs) {\n for (const output of mapper.outputs) {\n const preMappers = pre.get(output);\n if (preMappers === undefined) {\n pre.set(output, [mapper]);\n } else {\n preMappers.push(mapper);\n }\n }\n }\n });\n const visited = new Set();\n const newOrder: Mapper[] = [];\n function dfs(mapper: Mapper) {\n visited.add(mapper);\n for (const input of mapper.inputs) {\n const preMappers = pre.get(input);\n if (preMappers) {\n for (const preMapper of preMappers) {\n if (!visited.has(preMapper)) {\n dfs(preMapper);\n }\n }\n }\n }\n newOrder.push(mapper);\n }\n mappers.forEach((mapper) => {\n if (!visited.has(mapper)) {\n dfs(mapper);\n }\n });\n sortedMappers = newOrder;\n }\n\n function mapperFrame() {\n frameRequested = false;\n if (mappers.size !== sortedMappers.length) {\n updateMappersOrder();\n }\n for (const mapper of sortedMappers) {\n if (mapper.dirty) {\n mapper.dirty = false;\n mapper.worklet();\n }\n }\n }\n\n function maybeRequestUpdates() {\n if (!frameRequested) {\n requestAnimationFrame(mapperFrame);\n frameRequested = true;\n }\n }\n\n function extractInputs(\n inputs: any,\n resultArray: SharedValue<any>[]\n ): SharedValue<any>[] {\n if (Array.isArray(inputs)) {\n for (const input of inputs) {\n input && extractInputs(input, resultArray);\n }\n } else if (inputs.addListener) {\n resultArray.push(inputs);\n } else if (typeof inputs === 'object') {\n for (const element of Object.values(inputs)) {\n element && extractInputs(element, resultArray);\n }\n }\n return resultArray;\n }\n\n return {\n start: (\n mapperID: number,\n worklet: () => void,\n inputs: SharedValue<any>[],\n outputs?: SharedValue<any>[]\n ) => {\n const mapper = {\n id: mapperID,\n dirty: true,\n worklet,\n inputs: extractInputs(inputs, []),\n outputs,\n };\n mappers.set(mapper.id, mapper);\n sortedMappers = [];\n for (const sv of mapper.inputs) {\n sv.addListener(mapper.id, () => {\n mapper.dirty = true;\n maybeRequestUpdates();\n });\n }\n maybeRequestUpdates();\n },\n stop: (mapperID: number) => {\n const mapper = mappers.get(mapperID);\n if (mapper) {\n mappers.delete(mapper.id);\n sortedMappers = [];\n for (const sv of mapper.inputs) {\n sv.removeListener(mapper.id);\n }\n }\n },\n };\n}\n\nlet MAPPER_ID = 9999;\n\nexport function startMapper(\n worklet: () => void,\n inputs: any[] = [],\n outputs: any[] = []\n): number {\n const mapperID = (MAPPER_ID += 1);\n\n runOnUI(() => {\n 'worklet';\n let mapperRegistry = global.__mapperRegistry;\n if (mapperRegistry === undefined) {\n mapperRegistry = global.__mapperRegistry = createMapperRegistry();\n }\n mapperRegistry.start(mapperID, worklet, inputs, outputs);\n })();\n\n return mapperID;\n}\n\nexport function stopMapper(mapperID: number): void {\n runOnUI(() => {\n 'worklet';\n const mapperRegistry = global.__mapperRegistry;\n mapperRegistry?.stop(mapperID);\n })();\n}\n"],"mappings":";;;;;;;;;AACA;;AAUO,SAASA,oBAAT,GAAgC;EACrC;;EACA,MAAMC,OAAO,GAAG,IAAIC,GAAJ,EAAhB;EACA,IAAIC,aAAuB,GAAG,EAA9B;EAEA,IAAIC,cAAc,GAAG,KAArB;;EAEA,SAASC,kBAAT,GAA8B;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAMC,GAAG,GAAG,IAAIJ,GAAJ,EAAZ,CArB4B,CAqBL;;IACvBD,OAAO,CAACM,OAAR,CAAiBC,MAAD,IAAY;MAC1B,IAAIA,MAAM,CAACC,OAAX,EAAoB;QAClB,KAAK,MAAMC,MAAX,IAAqBF,MAAM,CAACC,OAA5B,EAAqC;UACnC,MAAME,UAAU,GAAGL,GAAG,CAACM,GAAJ,CAAQF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|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.makeMutable = makeMutable;
|
|
7
|
+
exports.makeRemote = makeRemote;
|
|
8
|
+
exports.makeUIMutable = makeUIMutable;
|
|
9
|
+
Object.defineProperty(exports, "stopMapper", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _mappers.stopMapper;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var _NativeReanimated = _interopRequireDefault(require("./NativeReanimated"));
|
|
17
|
+
|
|
18
|
+
var _shareables = require("./shareables");
|
|
19
|
+
|
|
20
|
+
var _threads = require("./threads");
|
|
21
|
+
|
|
22
|
+
var _valueSetter = require("./valueSetter");
|
|
23
|
+
|
|
24
|
+
var _mappers = require("./mappers");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
function makeUIMutable(initial, syncDataHolder) {
|
|
29
|
+
'worklet';
|
|
30
|
+
|
|
31
|
+
const listeners = new Map();
|
|
32
|
+
let value = initial;
|
|
33
|
+
const self = {
|
|
34
|
+
set value(newValue) {
|
|
35
|
+
(0, _valueSetter.valueSetter)(self, newValue);
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
get value() {
|
|
39
|
+
return value;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* _value prop should only be accessed by the valueSetter implementation
|
|
44
|
+
* which may make the decision about updating the mutable value depending
|
|
45
|
+
* on the provided new value. All other places should only attempt to modify
|
|
46
|
+
* the mutable by assigning to value prop directly.
|
|
47
|
+
*/
|
|
48
|
+
set _value(newValue) {
|
|
49
|
+
value = newValue;
|
|
50
|
+
|
|
51
|
+
if (syncDataHolder) {
|
|
52
|
+
_updateDataSynchronously(syncDataHolder, (0, _shareables.makeShareableCloneOnUIRecursive)(newValue));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
listeners.forEach(listener => {
|
|
56
|
+
listener(newValue);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
get _value() {
|
|
61
|
+
return value;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
addListener: (id, listener) => {
|
|
65
|
+
listeners.set(id, listener);
|
|
66
|
+
},
|
|
67
|
+
removeListener: id => {
|
|
68
|
+
listeners.delete(id);
|
|
69
|
+
},
|
|
70
|
+
_animation: null
|
|
71
|
+
};
|
|
72
|
+
return self;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function makeMutable(initial) {
|
|
76
|
+
let oneWayReadsOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
77
|
+
let value = initial;
|
|
78
|
+
let syncDataHolder;
|
|
79
|
+
|
|
80
|
+
if (!oneWayReadsOnly && _NativeReanimated.default.native) {
|
|
81
|
+
// updates are always synchronous when running on web or in Jest environment
|
|
82
|
+
syncDataHolder = _NativeReanimated.default.makeSynchronizedDataHolder((0, _shareables.makeShareableCloneRecursive)(value));
|
|
83
|
+
(0, _shareables.registerShareableMapping)(syncDataHolder);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const handle = (0, _shareables.makeShareableCloneRecursive)({
|
|
87
|
+
__init: () => {
|
|
88
|
+
'worklet';
|
|
89
|
+
|
|
90
|
+
return makeUIMutable(initial, syncDataHolder);
|
|
91
|
+
}
|
|
92
|
+
}); // listeners can only work on JS thread on Web and jest environments
|
|
93
|
+
|
|
94
|
+
const listeners = _NativeReanimated.default.native ? undefined : new Map();
|
|
95
|
+
const mutable = {
|
|
96
|
+
set value(newValue) {
|
|
97
|
+
if (_NativeReanimated.default.native) {
|
|
98
|
+
(0, _threads.runOnUI)(() => {
|
|
99
|
+
'worklet';
|
|
100
|
+
|
|
101
|
+
mutable.value = newValue;
|
|
102
|
+
})();
|
|
103
|
+
} else {
|
|
104
|
+
(0, _valueSetter.valueSetter)(mutable, newValue);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
get value() {
|
|
109
|
+
if (syncDataHolder) {
|
|
110
|
+
return _NativeReanimated.default.getDataSynchronously(syncDataHolder);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return value;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
set _value(newValue) {
|
|
117
|
+
if (_NativeReanimated.default.native) {
|
|
118
|
+
throw new Error('Setting `_value` directly is only possible on the UI runtime');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
value = newValue;
|
|
122
|
+
listeners.forEach(listener => {
|
|
123
|
+
listener(newValue);
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
get _value() {
|
|
128
|
+
if (_NativeReanimated.default.native) {
|
|
129
|
+
throw new Error('Reading from `_value` directly is only possible on the UI runtime');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return value;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
modify: modifier => {
|
|
136
|
+
(0, _threads.runOnUI)(() => {
|
|
137
|
+
'worklet';
|
|
138
|
+
|
|
139
|
+
mutable.value = modifier(mutable.value);
|
|
140
|
+
})();
|
|
141
|
+
},
|
|
142
|
+
addListener: (id, listener) => {
|
|
143
|
+
if (_NativeReanimated.default.native) {
|
|
144
|
+
throw new Error('adding listeners is only possible on the UI runtime');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
listeners.set(id, listener);
|
|
148
|
+
},
|
|
149
|
+
removeListener: id => {
|
|
150
|
+
if (_NativeReanimated.default.native) {
|
|
151
|
+
throw new Error('removing listeners is only possible on the UI runtime');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
listeners.delete(id);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
(0, _shareables.registerShareableMapping)(mutable, handle);
|
|
158
|
+
return mutable;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function makeRemote() {
|
|
162
|
+
let initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
163
|
+
const handle = (0, _shareables.makeShareableCloneRecursive)({
|
|
164
|
+
__init: () => {
|
|
165
|
+
'worklet';
|
|
166
|
+
|
|
167
|
+
return initial;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
(0, _shareables.registerShareableMapping)(initial, handle);
|
|
171
|
+
return initial;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=mutables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["makeUIMutable","initial","syncDataHolder","listeners","Map","value","self","newValue","valueSetter","_value","_updateDataSynchronously","makeShareableCloneOnUIRecursive","forEach","listener","addListener","id","set","removeListener","delete","_animation","makeMutable","oneWayReadsOnly","NativeReanimatedModule","native","makeSynchronizedDataHolder","makeShareableCloneRecursive","registerShareableMapping","handle","__init","undefined","mutable","runOnUI","getDataSynchronously","Error","modify","modifier","makeRemote"],"sources":["mutables.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { SharedValue, ShareableSyncDataHolderRef } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n registerShareableMapping,\n} from './shareables';\nimport { runOnUI } from './threads';\nimport { valueSetter } from './valueSetter';\nexport { stopMapper } from './mappers';\n\nexport function makeUIMutable<T>(\n initial: T,\n syncDataHolder?: ShareableSyncDataHolderRef<T>\n) {\n 'worklet';\n\n const listeners = new Map();\n let value = initial;\n\n const self = {\n set value(newValue) {\n valueSetter(self, newValue);\n },\n get value() {\n return value;\n },\n /**\n * _value prop should only be accessed by the valueSetter implementation\n * which may make the decision about updating the mutable value depending\n * on the provided new value. All other places should only attempt to modify\n * the mutable by assigning to value prop directly.\n */\n set _value(newValue: T) {\n value = newValue;\n if (syncDataHolder) {\n _updateDataSynchronously(\n syncDataHolder,\n makeShareableCloneOnUIRecursive(newValue)\n );\n }\n listeners.forEach((listener) => {\n listener(newValue);\n });\n },\n get _value(): T {\n return value;\n },\n addListener: (id: number, listener: (newValue: T) => void) => {\n listeners.set(id, listener);\n },\n removeListener: (id: number) => {\n listeners.delete(id);\n },\n _animation: null,\n };\n return self;\n}\n\nexport function makeMutable<T>(\n initial: T,\n oneWayReadsOnly = false\n): SharedValue<T> {\n let value: T = initial;\n let syncDataHolder: ShareableSyncDataHolderRef<T> | undefined;\n if (!oneWayReadsOnly && NativeReanimatedModule.native) {\n // updates are always synchronous when running on web or in Jest environment\n syncDataHolder = NativeReanimatedModule.makeSynchronizedDataHolder(\n makeShareableCloneRecursive(value)\n );\n registerShareableMapping(syncDataHolder);\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return makeUIMutable(initial, syncDataHolder);\n },\n });\n // listeners can only work on JS thread on Web and jest environments\n const listeners = NativeReanimatedModule.native ? undefined : new Map();\n const mutable = {\n set value(newValue) {\n if (NativeReanimatedModule.native) {\n runOnUI(() => {\n 'worklet';\n mutable.value = newValue;\n })();\n } else {\n valueSetter(mutable, newValue);\n }\n },\n get value() {\n if (syncDataHolder) {\n return NativeReanimatedModule.getDataSynchronously(syncDataHolder);\n }\n return value;\n },\n set _value(newValue: T) {\n if (NativeReanimatedModule.native) {\n throw new Error(\n 'Setting `_value` directly is only possible on the UI runtime'\n );\n }\n value = newValue;\n listeners!.forEach((listener) => {\n listener(newValue);\n });\n },\n get _value(): T {\n if (NativeReanimatedModule.native) {\n throw new Error(\n 'Reading from `_value` directly is only possible on the UI runtime'\n );\n }\n return value;\n },\n modify: (modifier: (value: T) => T) => {\n runOnUI(() => {\n 'worklet';\n mutable.value = modifier(mutable.value);\n })();\n },\n addListener: (id: number, listener: (value: T) => void) => {\n if (NativeReanimatedModule.native) {\n throw new Error('adding listeners is only possible on the UI runtime');\n }\n listeners!.set(id, listener);\n },\n removeListener: (id: number) => {\n if (NativeReanimatedModule.native) {\n throw new Error(\n 'removing listeners is only possible on the UI runtime'\n );\n }\n listeners!.delete(id);\n },\n };\n registerShareableMapping(mutable, handle);\n return mutable;\n}\n\nexport function makeRemote<T extends object>(initial: T = {} as T): T {\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return initial;\n },\n });\n registerShareableMapping(initial, handle);\n return initial;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAEA;;AAKA;;AACA;;AACA;;;;AAEO,SAASA,aAAT,CACLC,OADK,EAELC,cAFK,EAGL;EACA;;EAEA,MAAMC,SAAS,GAAG,IAAIC,GAAJ,EAAlB;EACA,IAAIC,KAAK,GAAGJ,OAAZ;EAEA,MAAMK,IAAI,GAAG;IACX,IAAID,KAAJ,CAAUE,QAAV,EAAoB;MAClB,IAAAC,wBAAA,EAAYF,IAAZ,EAAkBC,QAAlB;IACD,CAHU;;IAIX,IAAIF,KAAJ,GAAY;MACV,OAAOA,KAAP;IACD,CANU;;IAOX;AACJ;AACA;AACA;AACA;AACA;IACI,IAAII,MAAJ,CAAWF,QAAX,EAAwB;MACtBF,KAAK,GAAGE,QAAR;;MACA,IAAIL,cAAJ,EAAoB;QAClBQ,wBAAwB,CACtBR,cADsB,EAEtB,IAAAS,2CAAA,EAAgCJ,QAAhC,CAFsB,CAAxB;MAID;;MACDJ,SAAS,CAACS,OAAV,CAAmBC,QAAD,IAAc;QAC9BA,QAAQ,CAACN,QAAD,CAAR;MACD,CAFD;IAGD,CAxBU;;IAyBX,IAAIE,MAAJ,GAAgB;MACd,OAAOJ,KAAP;IACD,CA3BU;;IA4BXS,WAAW,EAAE,CAACC,EAAD,EAAaF,QAAb,KAAiD;MAC5DV,SAAS,CAACa,GAAV,CAAcD,EAAd,EAAkBF,QAAlB;IACD,CA9BU;IA+BXI,cAAc,EAAGF,EAAD,IAAgB;MAC9BZ,SAAS,CAACe,MAAV,CAAiBH,EAAjB;IACD,CAjCU;IAkCXI,UAAU,EAAE;EAlCD,CAAb;EAoCA,OAAOb,IAAP;AACD;;AAEM,SAASc,WAAT,CACLnB,OADK,EAGW;EAAA,IADhBoB,eACgB,uEADE,KACF;EAChB,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= makeShareable;
|
|
7
|
+
exports.makeShareableCloneOnUIRecursive = makeShareableCloneOnUIRecursive;
|
|
8
|
+
exports.makeShareableCloneRecursive = makeShareableCloneRecursive;
|
|
9
|
+
exports.makeShareableShadowNodeWrapper = makeShareableShadowNodeWrapper;
|
|
10
|
+
exports.registerShareableMapping = registerShareableMapping;
|
|
11
|
+
|
|
12
|
+
var _NativeReanimated = _interopRequireDefault(require("./NativeReanimated"));
|
|
13
|
+
|
|
14
|
+
var _PlatformChecker = require("./PlatformChecker");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
// for web/chrome debugger/jest environments this file provides a stub implementation
|
|
19
|
+
// where no shareable references are used. Instead, the objects themselves are used
|
|
20
|
+
// instead of shareable references, because of the fact that we don't have to deal with
|
|
21
|
+
// runnning the code on separate VMs.
|
|
22
|
+
const USE_STUB_IMPLEMENTATION = (0, _PlatformChecker.shouldBeUseWeb)();
|
|
23
|
+
|
|
24
|
+
const _shareableCache = new WeakMap(); // the below symbol is used to represent a mapping from the value to itself
|
|
25
|
+
// this is used to allow for a converted shareable to be passed to makeShareableClone
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const _shareableFlag = Symbol('shareable flag');
|
|
29
|
+
|
|
30
|
+
function registerShareableMapping(shareable, shareableRef) {
|
|
31
|
+
if (USE_STUB_IMPLEMENTATION) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_shareableCache.set(shareable, shareableRef || _shareableFlag);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function makeShareableShadowNodeWrapper(shadowNodeWrapper) {
|
|
39
|
+
const adoptedSNW = _NativeReanimated.default.makeShareableClone(shadowNodeWrapper);
|
|
40
|
+
|
|
41
|
+
registerShareableMapping(shadowNodeWrapper, adoptedSNW);
|
|
42
|
+
return shadowNodeWrapper;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function makeShareableCloneRecursive(value) {
|
|
46
|
+
if (USE_STUB_IMPLEMENTATION) {
|
|
47
|
+
return value;
|
|
48
|
+
} // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const type = typeof value;
|
|
52
|
+
|
|
53
|
+
if ((type === 'object' || type === 'function') && value !== null) {
|
|
54
|
+
const cached = _shareableCache.get(value);
|
|
55
|
+
|
|
56
|
+
if (cached === _shareableFlag) {
|
|
57
|
+
return value;
|
|
58
|
+
} else if (cached !== undefined) {
|
|
59
|
+
return cached;
|
|
60
|
+
} else {
|
|
61
|
+
let toAdapt;
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
toAdapt = value.map(element => makeShareableCloneRecursive(element));
|
|
65
|
+
} else if (type === 'function' && value.__workletHash === undefined) {
|
|
66
|
+
// this is a remote function
|
|
67
|
+
toAdapt = value;
|
|
68
|
+
} else {
|
|
69
|
+
toAdapt = {};
|
|
70
|
+
|
|
71
|
+
for (const [key, element] of Object.entries(value)) {
|
|
72
|
+
toAdapt[key] = makeShareableCloneRecursive(element);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (__DEV__) {
|
|
77
|
+
// we freeze objects that are transformed to shareable. This should help
|
|
78
|
+
// detect issues when someone modifies data after it's been converted to
|
|
79
|
+
// shareable. Meaning that they may be doing a faulty assumption in their
|
|
80
|
+
// code expecting that the updates are going to automatically populate to
|
|
81
|
+
// the object sent to the UI thread. If the user really wants some objects
|
|
82
|
+
// to be mutable they should use share values instead.
|
|
83
|
+
Object.freeze(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const adopted = _NativeReanimated.default.makeShareableClone(toAdapt);
|
|
87
|
+
|
|
88
|
+
_shareableCache.set(value, adopted);
|
|
89
|
+
|
|
90
|
+
_shareableCache.set(adopted, _shareableFlag);
|
|
91
|
+
|
|
92
|
+
return adopted;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return _NativeReanimated.default.makeShareableClone(value);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function makeShareableCloneOnUIRecursive(value) {
|
|
100
|
+
'worklet';
|
|
101
|
+
|
|
102
|
+
if (USE_STUB_IMPLEMENTATION) {
|
|
103
|
+
// @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread
|
|
104
|
+
// see more details in the comment where USE_STUB_IMPLEMENTATION is defined.
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function cloneRecursive(value) {
|
|
109
|
+
const type = typeof value;
|
|
110
|
+
|
|
111
|
+
if ((type === 'object' || type === 'function') && value !== null) {
|
|
112
|
+
let toAdapt;
|
|
113
|
+
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
toAdapt = value.map(element => cloneRecursive(element));
|
|
116
|
+
} else {
|
|
117
|
+
toAdapt = {};
|
|
118
|
+
|
|
119
|
+
for (const [key, element] of Object.entries(value)) {
|
|
120
|
+
toAdapt[key] = cloneRecursive(element);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (__DEV__) {
|
|
125
|
+
// See the reasoning behind freezing in the other comment above.
|
|
126
|
+
Object.freeze(value);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return _makeShareableClone(toAdapt);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return _makeShareableClone(value);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return cloneRecursive(value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function makeShareable(value) {
|
|
139
|
+
if (USE_STUB_IMPLEMENTATION) {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const handle = makeShareableCloneRecursive({
|
|
144
|
+
__init: () => {
|
|
145
|
+
'worklet';
|
|
146
|
+
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
registerShareableMapping(value, handle);
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=shareables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["USE_STUB_IMPLEMENTATION","shouldBeUseWeb","_shareableCache","WeakMap","_shareableFlag","Symbol","registerShareableMapping","shareable","shareableRef","set","makeShareableShadowNodeWrapper","shadowNodeWrapper","adoptedSNW","NativeReanimatedModule","makeShareableClone","makeShareableCloneRecursive","value","type","cached","get","undefined","toAdapt","Array","isArray","map","element","__workletHash","key","Object","entries","__DEV__","freeze","adopted","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareable","handle","__init"],"sources":["shareables.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { ShareableRef } from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst USE_STUB_IMPLEMENTATION = shouldBeUseWeb();\n\nconst _shareableCache = new WeakMap<\n Record<string, unknown>,\n ShareableRef<any> | symbol\n>();\n// the below symbol is used to represent a mapping from the value to itself\n// this is used to allow for a converted shareable to be passed to makeShareableClone\nconst _shareableFlag = Symbol('shareable flag');\n\nexport function registerShareableMapping(\n shareable: any,\n shareableRef?: ShareableRef<any>\n): void {\n if (USE_STUB_IMPLEMENTATION) {\n return;\n }\n _shareableCache.set(shareable, shareableRef || _shareableFlag);\n}\n\nexport function makeShareableShadowNodeWrapper<T>(shadowNodeWrapper: T): T {\n const adoptedSNW =\n NativeReanimatedModule.makeShareableClone(shadowNodeWrapper);\n registerShareableMapping(shadowNodeWrapper, adoptedSNW);\n return shadowNodeWrapper;\n}\n\nexport function makeShareableCloneRecursive<T>(value: any): ShareableRef<T> {\n if (USE_STUB_IMPLEMENTATION) {\n return value;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n if ((type === 'object' || type === 'function') && value !== null) {\n const cached = _shareableCache.get(value);\n if (cached === _shareableFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) => makeShareableCloneRecursive(element));\n } else if (type === 'function' && value.__workletHash === undefined) {\n // this is a remote function\n toAdapt = value;\n } else {\n toAdapt = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = makeShareableCloneRecursive(element);\n }\n }\n if (__DEV__) {\n // we freeze objects that are transformed to shareable. This should help\n // detect issues when someone modifies data after it's been converted to\n // shareable. Meaning that they may be doing a faulty assumption in their\n // code expecting that the updates are going to automatically populate to\n // the object sent to the UI thread. If the user really wants some objects\n // to be mutable they should use share values instead.\n Object.freeze(value);\n }\n const adopted = NativeReanimatedModule.makeShareableClone(toAdapt);\n _shareableCache.set(value, adopted);\n _shareableCache.set(adopted, _shareableFlag);\n return adopted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(value);\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(value: T): ShareableRef<T> {\n 'worklet';\n if (USE_STUB_IMPLEMENTATION) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n function cloneRecursive<T>(value: T): ShareableRef<T> {\n const type = typeof value;\n if ((type === 'object' || type === 'function') && value !== null) {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) => cloneRecursive(element));\n } else {\n toAdapt = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n }\n if (__DEV__) {\n // See the reasoning behind freezing in the other comment above.\n Object.freeze(value);\n }\n return _makeShareableClone(toAdapt);\n }\n return _makeShareableClone(value);\n }\n return cloneRecursive(value);\n}\n\nexport function makeShareable<T>(value: T): T {\n if (USE_STUB_IMPLEMENTATION) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n registerShareableMapping(value, handle);\n return value;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;;;AAEA;AACA;AACA;AACA;AACA,MAAMA,uBAAuB,GAAG,IAAAC,+BAAA,GAAhC;;AAEA,MAAMC,eAAe,GAAG,IAAIC,OAAJ,EAAxB,C,CAIA;AACA;;;AACA,MAAMC,cAAc,GAAGC,MAAM,CAAC,gBAAD,CAA7B;;AAEO,SAASC,wBAAT,CACLC,SADK,EAELC,YAFK,EAGC;EACN,IAAIR,uBAAJ,EAA6B;IAC3B;EACD;;EACDE,eAAe,CAACO,GAAhB,CAAoBF,SAApB,EAA+BC,YAAY,IAAIJ,cAA/C;AACD;;AAEM,SAASM,8BAAT,CAA2CC,iBAA3C,EAAoE;EACzE,MAAMC,UAAU,GACdC,yBAAA,CAAuBC,kBAAvB,CAA0CH,iBAA1C,CADF;;EAEAL,wBAAwB,CAACK,iBAAD,EAAoBC,UAApB,CAAxB;EACA,OAAOD,iBAAP;AACD;;AAEM,SAASI,2BAAT,CAAwCC,KAAxC,EAAqE;EAC1E,IAAIhB,uBAAJ,EAA6B;IAC3B,OAAOgB,KAAP;EACD,CAHyE,CAI1E;;;EACA,MAAMC,IAAI,GAAG,OAAOD,KAApB;;EACA,IAAI,CAACC,IAAI,KAAK,QAAT,IAAqBA,IAAI,KAAK,UAA/B,KAA8CD,KAAK,KAAK,IAA5D,EAAkE;IAChE,MAAME,MAAM,GAAGhB,eAAe,CAACiB,GAAhB,CAAoBH,KAApB,CAAf;;IACA,IAAIE,MAAM,KAAKd,cAAf,EAA+B;MAC7B,OAAOY,KAAP;IACD,CAFD,MAEO,IAAIE,MAAM,KAAKE,SAAf,EAA0B;MAC/B,OAAOF,MAAP;IACD,CAFM,MAEA;MACL,IAAIG,OAAJ;;MACA,IAAIC,KAAK,CAACC,OAAN,CAAcP,KAAd,CAA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GL,KAAK,CAACQ,GAAN,CAAWC,OAAD,IAAaS,cAAc,CAACT,OAAD,CAArC,CAAV;MACD,CAFD,MAEO;QACLJ,OAAO,GAAG,EAAV;;QACA,KAAK,MAAM,CAACM,GAAD,EAAMF,OAAN,CAAX,IAA6BG,MAAM,CAACC,OAAP,CAAeb,KAAf,CAA7B,EAAoD;UAClDK,OAAO,CAACM,GAAD,CAAP,GAAeO,cAAc,CAACT,OAAD,CAA7B;QACD;MACF;;MACD,IAAIK,OAAJ,EAAa;QACX;QACAF,MAAM,CAACG,MAAP,CAAcf,KAAd;MACD;;MACD,OAAOmB,mBAAmB,CAACd,OAAD,CAA1B;IACD;;IACD,OAAOc,mBAAmB,CAACnB,KAAD,CAA1B;EACD;;EACD,OAAOkB,cAAc,CAAClB,KAAD,CAArB;AACD;;AAEM,SAASoB,aAAT,CAA0BpB,KAA1B,EAAuC;EAC5C,IAAIhB,uBAAJ,EAA6B;IAC3B,OAAOgB,KAAP;EACD;;EACD,MAAMqB,MAAM,GAAGtB,2BAA2B,CAAC;IACzCuB,MAAM,EAAE,MAAM;MACZ;;MACA,OAAOtB,KAAP;IACD;EAJwC,CAAD,CAA1C;EAMAV,wBAAwB,CAACU,KAAD,EAAQqB,MAAR,CAAxB;EACA,OAAOrB,KAAP;AACD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runOnJS = runOnJS;
|
|
7
|
+
exports.runOnUI = runOnUI;
|
|
8
|
+
|
|
9
|
+
var _NativeReanimated = _interopRequireDefault(require("./NativeReanimated"));
|
|
10
|
+
|
|
11
|
+
var _shareables = require("./shareables");
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
function runOnUI(worklet) {
|
|
16
|
+
if (__DEV__) {
|
|
17
|
+
if (worklet.__workletHash === undefined) {
|
|
18
|
+
throw new Error('runOnUI() can only be used on worklets');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return function () {
|
|
23
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24
|
+
args[_key] = arguments[_key];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_NativeReanimated.default.scheduleOnUI((0, _shareables.makeShareableCloneRecursive)(() => {
|
|
28
|
+
'worklet';
|
|
29
|
+
|
|
30
|
+
return worklet(...args);
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function runOnJS(fun) {
|
|
36
|
+
'worklet';
|
|
37
|
+
|
|
38
|
+
if (fun.__remoteFunction) {
|
|
39
|
+
// in development mode the function provided as `fun` throws an error message
|
|
40
|
+
// such that when someone accidently calls it directly on the UI runtime, they
|
|
41
|
+
// see that they should use `runOnJS` instead. To facilitate that we purt the
|
|
42
|
+
// reference to the original remote function in the `__remoteFunction` property.
|
|
43
|
+
fun = fun.__remoteFunction;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!_WORKLET) {
|
|
47
|
+
return fun;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return function () {
|
|
51
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
52
|
+
args[_key2] = arguments[_key2];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_scheduleOnJS(fun, args.length > 0 ? (0, _shareables.makeShareableCloneOnUIRecursive)(args) : undefined);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=threads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["runOnUI","worklet","__DEV__","__workletHash","undefined","Error","args","NativeReanimatedModule","scheduleOnUI","makeShareableCloneRecursive","runOnJS","fun","__remoteFunction","_WORKLET","_scheduleOnJS","length","makeShareableCloneOnUIRecursive"],"sources":["threads.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { ComplexWorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\n\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__) {\n if (worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n return worklet(...args);\n })\n );\n };\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n 'worklet';\n if (fun.__remoteFunction) {\n // in development mode the function provided as `fun` throws an error message\n // such that when someone accidently calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we purt the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = fun.__remoteFunction;\n }\n if (!_WORKLET) {\n return fun;\n }\n return (...args) => {\n _scheduleOnJS(\n fun,\n args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined\n );\n };\n}\n"],"mappings":";;;;;;;;AAAA;;AAEA;;;;AAKO,SAASA,OAAT,CACLC,OADK,EAEiB;EACtB,IAAIC,OAAJ,EAAa;IACX,IAAID,OAAO,CAACE,aAAR,KAA0BC,SAA9B,EAAyC;MACvC,MAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;IACD;EACF;;EACD,OAAO,YAAa;IAAA,kCAATC,IAAS;MAATA,IAAS;IAAA;;IAClBC,yBAAA,CAAuBC,YAAvB,CACE,IAAAC,uCAAA,EAA4B,MAAM;MAChC;;MACA,OAAOR,OAAO,CAAC,GAAGK,IAAJ,CAAd;IACD,CAHD,CADF;EAMD,CAPD;AAQD;;AAEM,SAASI,OAAT,CACLC,GADK,EAEiB;EACtB;;EACA,IAAIA,GAAG,CAACC,gBAAR,EAA0B;IACxB;IACA;IACA;IACA;IACAD,GAAG,GAAGA,GAAG,CAACC,gBAAV;EACD;;EACD,IAAI,CAACC,QAAL,EAAe;IACb,OAAOF,GAAP;EACD;;EACD,OAAO,YAAa;IAAA,mCAATL,IAAS;MAATA,IAAS;IAAA;;IAClBQ,aAAa,CACXH,GADW,EAEXL,IAAI,CAACS,MAAL,GAAc,CAAd,GAAkB,IAAAC,2CAAA,EAAgCV,IAAhC,CAAlB,GAA0DF,SAF/C,CAAb;EAID,CALD;AAMD"}
|