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.
Files changed (177) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
  4. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +161 -165
  6. package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
  8. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
  9. package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
  10. package/Common/cpp/SharedItems/Shareables.cpp +142 -0
  11. package/Common/cpp/SharedItems/Shareables.h +455 -0
  12. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
  13. package/Common/cpp/Tools/RuntimeDecorator.cpp +54 -26
  14. package/Common/cpp/Tools/RuntimeDecorator.h +11 -2
  15. package/Common/cpp/Tools/Scheduler.cpp +10 -0
  16. package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
  17. package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
  18. package/android/src/main/cpp/LayoutAnimations.h +4 -4
  19. package/android/src/main/cpp/NativeProxy.cpp +50 -63
  20. package/ios/native/NativeProxy.mm +26 -42
  21. package/lib/commonjs/createAnimatedComponent.js +7 -11
  22. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  23. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  24. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  25. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
  26. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  27. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
  28. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  29. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  30. package/lib/commonjs/reanimated2/commonTypes.js +7 -0
  31. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  32. package/lib/commonjs/reanimated2/core.js +111 -209
  33. package/lib/commonjs/reanimated2/core.js.map +1 -1
  34. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  35. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
  36. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  37. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
  38. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  39. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
  40. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  41. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +24 -50
  42. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  43. package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
  44. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  45. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  46. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  47. package/lib/commonjs/reanimated2/jestUtils.js +8 -33
  48. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  49. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +16 -100
  50. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  51. package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
  52. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  53. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  54. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  55. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +91 -0
  56. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  57. package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
  58. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  59. package/lib/commonjs/reanimated2/mappers.js +186 -0
  60. package/lib/commonjs/reanimated2/mappers.js.map +1 -0
  61. package/lib/commonjs/reanimated2/mutables.js +173 -0
  62. package/lib/commonjs/reanimated2/mutables.js.map +1 -0
  63. package/lib/commonjs/reanimated2/shareables.js +153 -0
  64. package/lib/commonjs/reanimated2/shareables.js.map +1 -0
  65. package/lib/commonjs/reanimated2/threads.js +58 -0
  66. package/lib/commonjs/reanimated2/threads.js.map +1 -0
  67. package/lib/commonjs/reanimated2/time.js +55 -0
  68. package/lib/commonjs/reanimated2/time.js.map +1 -0
  69. package/lib/commonjs/reanimated2/valueSetter.js +81 -0
  70. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
  71. package/lib/module/createAnimatedComponent.js +7 -12
  72. package/lib/module/createAnimatedComponent.js.map +1 -1
  73. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  74. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  75. package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
  76. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  77. package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
  78. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  79. package/lib/module/reanimated2/animation/util.js.map +1 -1
  80. package/lib/module/reanimated2/commonTypes.js +7 -0
  81. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  82. package/lib/module/reanimated2/core.js +66 -188
  83. package/lib/module/reanimated2/core.js.map +1 -1
  84. package/lib/module/reanimated2/globals.d.js.map +1 -1
  85. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
  86. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  87. package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
  88. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  89. package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
  90. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  91. package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -52
  92. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  93. package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
  94. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  95. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  96. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  97. package/lib/module/reanimated2/jestUtils.js +8 -31
  98. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  99. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +16 -95
  100. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  101. package/lib/module/reanimated2/js-reanimated/index.js +5 -0
  102. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  103. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  104. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  105. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +84 -0
  106. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  107. package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
  108. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  109. package/lib/module/reanimated2/mappers.js +173 -0
  110. package/lib/module/reanimated2/mappers.js.map +1 -0
  111. package/lib/module/reanimated2/mutables.js +149 -0
  112. package/lib/module/reanimated2/mutables.js.map +1 -0
  113. package/lib/module/reanimated2/shareables.js +133 -0
  114. package/lib/module/reanimated2/shareables.js.map +1 -0
  115. package/lib/module/reanimated2/threads.js +45 -0
  116. package/lib/module/reanimated2/threads.js.map +1 -0
  117. package/lib/module/reanimated2/time.js +37 -0
  118. package/lib/module/reanimated2/time.js.map +1 -0
  119. package/lib/module/reanimated2/valueSetter.js +66 -0
  120. package/lib/module/reanimated2/valueSetter.js.map +1 -0
  121. package/package.json +1 -1
  122. package/plugin.js +31 -15
  123. package/src/createAnimatedComponent.tsx +8 -24
  124. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +34 -53
  125. package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
  126. package/src/reanimated2/WorkletEventHandler.ts +4 -11
  127. package/src/reanimated2/animation/util.ts +1 -0
  128. package/src/reanimated2/commonTypes.ts +29 -4
  129. package/src/reanimated2/core.ts +103 -230
  130. package/src/reanimated2/globals.d.ts +26 -26
  131. package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
  132. package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
  133. package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
  134. package/src/reanimated2/hook/useAnimatedStyle.ts +26 -64
  135. package/src/reanimated2/hook/useSharedValue.ts +6 -3
  136. package/src/reanimated2/hook/utils.ts +1 -1
  137. package/src/reanimated2/interpolateColor.ts +2 -2
  138. package/src/reanimated2/jestUtils.ts +14 -29
  139. package/src/reanimated2/js-reanimated/JSReanimated.ts +19 -93
  140. package/src/reanimated2/js-reanimated/index.ts +4 -0
  141. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
  142. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  143. package/src/reanimated2/layoutReanimation/animationsManager.ts +94 -0
  144. package/src/reanimated2/layoutReanimation/index.ts +1 -1
  145. package/src/reanimated2/mappers.ts +179 -0
  146. package/src/reanimated2/mutables.ts +151 -0
  147. package/src/reanimated2/shareables.ts +121 -0
  148. package/src/reanimated2/threads.ts +46 -0
  149. package/src/reanimated2/time.ts +30 -0
  150. package/src/reanimated2/valueSetter.ts +64 -0
  151. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
  152. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
  153. package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
  154. package/Common/cpp/Registries/MapperRegistry.h +0 -29
  155. package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
  156. package/Common/cpp/Registries/WorkletsCache.h +0 -24
  157. package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
  158. package/Common/cpp/SharedItems/FrozenObject.h +0 -36
  159. package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
  160. package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
  161. package/Common/cpp/SharedItems/MutableValue.h +0 -54
  162. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
  163. package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
  164. package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
  165. package/Common/cpp/SharedItems/RemoteObject.h +0 -35
  166. package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
  167. package/Common/cpp/SharedItems/ShareableValue.h +0 -63
  168. package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
  169. package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
  170. package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
  171. package/Common/cpp/Tools/Mapper.cpp +0 -86
  172. package/Common/cpp/Tools/Mapper.h +0 -51
  173. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
  174. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  175. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
  176. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  177. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
@@ -0,0 +1,173 @@
1
+ import { runOnUI } from './threads';
2
+ export function createMapperRegistry() {
3
+ 'worklet';
4
+
5
+ const mappers = new Map();
6
+ let sortedMappers = [];
7
+ let frameRequested = false;
8
+
9
+ function updateMappersOrder() {
10
+ // sort mappers topologically
11
+ // the algorithm here takes adventage of a fact that the topological order
12
+ // of a transposed graph is a reverse topological order of the original graph
13
+ // The graph in our case consists of mappers and an edge between two mappers
14
+ // A and B exists if there is a shared value that's on A's output lists and on
15
+ // B's input list.
16
+ //
17
+ // We don't need however to calculate that graph as it is easier to work with
18
+ // the transposed version of it that can be calculated ad-hoc. For the transposed
19
+ // version to be traversed we use "pre" map that maps share value to mappers that
20
+ // output that shared value. Then we can infer all the outgoing edges for a given
21
+ // mapper simply by scanning it's input list and checking if any of the shared values
22
+ // from that list exists in the "pre" map. If they do, then we have an edge between
23
+ // that mapper and the mappers from the "pre" list for the given shared value.
24
+ //
25
+ // For topological sorting we use a dfs-based approach that requires the graph to
26
+ // be traversed in dfs order and each node after being processed lands at the
27
+ // beginning of the topological order list. Since we traverse a transposed graph,
28
+ // instead of reversing that order we can use a normal array and push processed
29
+ // mappers to the end. There is no need to reverse that array after we are done.
30
+ const pre = new Map(); // map from sv -> mapper that outputs that sv
31
+
32
+ mappers.forEach(mapper => {
33
+ if (mapper.outputs) {
34
+ for (const output of mapper.outputs) {
35
+ const preMappers = pre.get(output);
36
+
37
+ if (preMappers === undefined) {
38
+ pre.set(output, [mapper]);
39
+ } else {
40
+ preMappers.push(mapper);
41
+ }
42
+ }
43
+ }
44
+ });
45
+ const visited = new Set();
46
+ const newOrder = [];
47
+
48
+ function dfs(mapper) {
49
+ visited.add(mapper);
50
+
51
+ for (const input of mapper.inputs) {
52
+ const preMappers = pre.get(input);
53
+
54
+ if (preMappers) {
55
+ for (const preMapper of preMappers) {
56
+ if (!visited.has(preMapper)) {
57
+ dfs(preMapper);
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ newOrder.push(mapper);
64
+ }
65
+
66
+ mappers.forEach(mapper => {
67
+ if (!visited.has(mapper)) {
68
+ dfs(mapper);
69
+ }
70
+ });
71
+ sortedMappers = newOrder;
72
+ }
73
+
74
+ function mapperFrame() {
75
+ frameRequested = false;
76
+
77
+ if (mappers.size !== sortedMappers.length) {
78
+ updateMappersOrder();
79
+ }
80
+
81
+ for (const mapper of sortedMappers) {
82
+ if (mapper.dirty) {
83
+ mapper.dirty = false;
84
+ mapper.worklet();
85
+ }
86
+ }
87
+ }
88
+
89
+ function maybeRequestUpdates() {
90
+ if (!frameRequested) {
91
+ requestAnimationFrame(mapperFrame);
92
+ frameRequested = true;
93
+ }
94
+ }
95
+
96
+ function extractInputs(inputs, resultArray) {
97
+ if (Array.isArray(inputs)) {
98
+ for (const input of inputs) {
99
+ input && extractInputs(input, resultArray);
100
+ }
101
+ } else if (inputs.addListener) {
102
+ resultArray.push(inputs);
103
+ } else if (typeof inputs === 'object') {
104
+ for (const element of Object.values(inputs)) {
105
+ element && extractInputs(element, resultArray);
106
+ }
107
+ }
108
+
109
+ return resultArray;
110
+ }
111
+
112
+ return {
113
+ start: (mapperID, worklet, inputs, outputs) => {
114
+ const mapper = {
115
+ id: mapperID,
116
+ dirty: true,
117
+ worklet,
118
+ inputs: extractInputs(inputs, []),
119
+ outputs
120
+ };
121
+ mappers.set(mapper.id, mapper);
122
+ sortedMappers = [];
123
+
124
+ for (const sv of mapper.inputs) {
125
+ sv.addListener(mapper.id, () => {
126
+ mapper.dirty = true;
127
+ maybeRequestUpdates();
128
+ });
129
+ }
130
+
131
+ maybeRequestUpdates();
132
+ },
133
+ stop: mapperID => {
134
+ const mapper = mappers.get(mapperID);
135
+
136
+ if (mapper) {
137
+ mappers.delete(mapper.id);
138
+ sortedMappers = [];
139
+
140
+ for (const sv of mapper.inputs) {
141
+ sv.removeListener(mapper.id);
142
+ }
143
+ }
144
+ }
145
+ };
146
+ }
147
+ let MAPPER_ID = 9999;
148
+ export function startMapper(worklet) {
149
+ let inputs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
150
+ let outputs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
151
+ const mapperID = MAPPER_ID += 1;
152
+ runOnUI(() => {
153
+ 'worklet';
154
+
155
+ let mapperRegistry = global.__mapperRegistry;
156
+
157
+ if (mapperRegistry === undefined) {
158
+ mapperRegistry = global.__mapperRegistry = createMapperRegistry();
159
+ }
160
+
161
+ mapperRegistry.start(mapperID, worklet, inputs, outputs);
162
+ })();
163
+ return mapperID;
164
+ }
165
+ export function stopMapper(mapperID) {
166
+ runOnUI(() => {
167
+ 'worklet';
168
+
169
+ const mapperRegistry = global.__mapperRegistry;
170
+ mapperRegistry === null || mapperRegistry === void 0 ? void 0 : mapperRegistry.stop(mapperID);
171
+ })();
172
+ }
173
+ //# sourceMappingURL=mappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["runOnUI","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","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,SAASA,OAAT,QAAwB,WAAxB;AAUA,OAAO,SAASC,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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,cAAc,CAAEL,IAAhB,CAAqBH,QAArB;EACD,CAJM,CAAP;AAKD"}
@@ -0,0 +1,149 @@
1
+ import NativeReanimatedModule from './NativeReanimated';
2
+ import { makeShareableCloneOnUIRecursive, makeShareableCloneRecursive, registerShareableMapping } from './shareables';
3
+ import { runOnUI } from './threads';
4
+ import { valueSetter } from './valueSetter';
5
+ export { stopMapper } from './mappers';
6
+ export function makeUIMutable(initial, syncDataHolder) {
7
+ 'worklet';
8
+
9
+ const listeners = new Map();
10
+ let value = initial;
11
+ const self = {
12
+ set value(newValue) {
13
+ valueSetter(self, newValue);
14
+ },
15
+
16
+ get value() {
17
+ return value;
18
+ },
19
+
20
+ /**
21
+ * _value prop should only be accessed by the valueSetter implementation
22
+ * which may make the decision about updating the mutable value depending
23
+ * on the provided new value. All other places should only attempt to modify
24
+ * the mutable by assigning to value prop directly.
25
+ */
26
+ set _value(newValue) {
27
+ value = newValue;
28
+
29
+ if (syncDataHolder) {
30
+ _updateDataSynchronously(syncDataHolder, makeShareableCloneOnUIRecursive(newValue));
31
+ }
32
+
33
+ listeners.forEach(listener => {
34
+ listener(newValue);
35
+ });
36
+ },
37
+
38
+ get _value() {
39
+ return value;
40
+ },
41
+
42
+ addListener: (id, listener) => {
43
+ listeners.set(id, listener);
44
+ },
45
+ removeListener: id => {
46
+ listeners.delete(id);
47
+ },
48
+ _animation: null
49
+ };
50
+ return self;
51
+ }
52
+ export function makeMutable(initial) {
53
+ let oneWayReadsOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
54
+ let value = initial;
55
+ let syncDataHolder;
56
+
57
+ if (!oneWayReadsOnly && NativeReanimatedModule.native) {
58
+ // updates are always synchronous when running on web or in Jest environment
59
+ syncDataHolder = NativeReanimatedModule.makeSynchronizedDataHolder(makeShareableCloneRecursive(value));
60
+ registerShareableMapping(syncDataHolder);
61
+ }
62
+
63
+ const handle = makeShareableCloneRecursive({
64
+ __init: () => {
65
+ 'worklet';
66
+
67
+ return makeUIMutable(initial, syncDataHolder);
68
+ }
69
+ }); // listeners can only work on JS thread on Web and jest environments
70
+
71
+ const listeners = NativeReanimatedModule.native ? undefined : new Map();
72
+ const mutable = {
73
+ set value(newValue) {
74
+ if (NativeReanimatedModule.native) {
75
+ runOnUI(() => {
76
+ 'worklet';
77
+
78
+ mutable.value = newValue;
79
+ })();
80
+ } else {
81
+ valueSetter(mutable, newValue);
82
+ }
83
+ },
84
+
85
+ get value() {
86
+ if (syncDataHolder) {
87
+ return NativeReanimatedModule.getDataSynchronously(syncDataHolder);
88
+ }
89
+
90
+ return value;
91
+ },
92
+
93
+ set _value(newValue) {
94
+ if (NativeReanimatedModule.native) {
95
+ throw new Error('Setting `_value` directly is only possible on the UI runtime');
96
+ }
97
+
98
+ value = newValue;
99
+ listeners.forEach(listener => {
100
+ listener(newValue);
101
+ });
102
+ },
103
+
104
+ get _value() {
105
+ if (NativeReanimatedModule.native) {
106
+ throw new Error('Reading from `_value` directly is only possible on the UI runtime');
107
+ }
108
+
109
+ return value;
110
+ },
111
+
112
+ modify: modifier => {
113
+ runOnUI(() => {
114
+ 'worklet';
115
+
116
+ mutable.value = modifier(mutable.value);
117
+ })();
118
+ },
119
+ addListener: (id, listener) => {
120
+ if (NativeReanimatedModule.native) {
121
+ throw new Error('adding listeners is only possible on the UI runtime');
122
+ }
123
+
124
+ listeners.set(id, listener);
125
+ },
126
+ removeListener: id => {
127
+ if (NativeReanimatedModule.native) {
128
+ throw new Error('removing listeners is only possible on the UI runtime');
129
+ }
130
+
131
+ listeners.delete(id);
132
+ }
133
+ };
134
+ registerShareableMapping(mutable, handle);
135
+ return mutable;
136
+ }
137
+ export function makeRemote() {
138
+ let initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
139
+ const handle = makeShareableCloneRecursive({
140
+ __init: () => {
141
+ 'worklet';
142
+
143
+ return initial;
144
+ }
145
+ });
146
+ registerShareableMapping(initial, handle);
147
+ return initial;
148
+ }
149
+ //# sourceMappingURL=mutables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeReanimatedModule","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","registerShareableMapping","runOnUI","valueSetter","stopMapper","makeUIMutable","initial","syncDataHolder","listeners","Map","value","self","newValue","_value","_updateDataSynchronously","forEach","listener","addListener","id","set","removeListener","delete","_animation","makeMutable","oneWayReadsOnly","native","makeSynchronizedDataHolder","handle","__init","undefined","mutable","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,OAAOA,sBAAP,MAAmC,oBAAnC;AAEA,SACEC,+BADF,EAEEC,2BAFF,EAGEC,wBAHF,QAIO,cAJP;AAKA,SAASC,OAAT,QAAwB,WAAxB;AACA,SAASC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MAAM,EAAGC,QAAD,IAA+B;MACrChC,OAAO,CAAC,MAAM;QACZ;;QACA4B,OAAO,CAACpB,KAAR,GAAgBwB,QAAQ,CAACJ,OAAO,CAACpB,KAAT,CAAxB;MACD,CAHM,CAAP;IAID,CAzCa;IA0CdO,WAAW,EAAE,CAACC,EAAD,EAAaF,QAAb,KAA8C;MACzD,IAAIlB,sBAAsB,CAAC2B,MAA3B,EAAmC;QACjC,MAAM,IAAIO,KAAJ,CAAU,qDAAV,CAAN;MACD;;MACDxB,SAAS,CAAEW,GAAX,CAAeD,EAAf,EAAmBF,QAAnB;IACD,CA/Ca;IAgDdI,cAAc,EAAGF,EAAD,IAAgB;MAC9B,IAAIpB,sBAAsB,CAAC2B,MAA3B,EAAmC;QACjC,MAAM,IAAIO,KAAJ,CACJ,uDADI,CAAN;MAGD;;MACDxB,SAAS,CAAEa,MAAX,CAAkBH,EAAlB;IACD;EAvDa,CAAhB;EAyDAjB,wBAAwB,CAAC6B,OAAD,EAAUH,MAAV,CAAxB;EACA,OAAOG,OAAP;AACD;AAED,OAAO,SAASK,UAAT,GAA+D;EAAA,IAAzB7B,OAAyB,uEAAZ,EAAY;EACpE,MAAMqB,MAAM,GAAG3B,2BAA2B,CAAC;IACzC4B,MAAM,EAAE,MAAM;MACZ;;MACA,OAAOtB,OAAP;IACD;EAJwC,CAAD,CAA1C;EAMAL,wBAAwB,CAACK,OAAD,EAAUqB,MAAV,CAAxB;EACA,OAAOrB,OAAP;AACD"}
@@ -0,0 +1,133 @@
1
+ import NativeReanimatedModule from './NativeReanimated';
2
+ import { shouldBeUseWeb } from './PlatformChecker'; // for web/chrome debugger/jest environments this file provides a stub implementation
3
+ // where no shareable references are used. Instead, the objects themselves are used
4
+ // instead of shareable references, because of the fact that we don't have to deal with
5
+ // runnning the code on separate VMs.
6
+
7
+ const USE_STUB_IMPLEMENTATION = shouldBeUseWeb();
8
+
9
+ const _shareableCache = new WeakMap(); // the below symbol is used to represent a mapping from the value to itself
10
+ // this is used to allow for a converted shareable to be passed to makeShareableClone
11
+
12
+
13
+ const _shareableFlag = Symbol('shareable flag');
14
+
15
+ export function registerShareableMapping(shareable, shareableRef) {
16
+ if (USE_STUB_IMPLEMENTATION) {
17
+ return;
18
+ }
19
+
20
+ _shareableCache.set(shareable, shareableRef || _shareableFlag);
21
+ }
22
+ export function makeShareableShadowNodeWrapper(shadowNodeWrapper) {
23
+ const adoptedSNW = NativeReanimatedModule.makeShareableClone(shadowNodeWrapper);
24
+ registerShareableMapping(shadowNodeWrapper, adoptedSNW);
25
+ return shadowNodeWrapper;
26
+ }
27
+ export function makeShareableCloneRecursive(value) {
28
+ if (USE_STUB_IMPLEMENTATION) {
29
+ return value;
30
+ } // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread
31
+
32
+
33
+ const type = typeof value;
34
+
35
+ if ((type === 'object' || type === 'function') && value !== null) {
36
+ const cached = _shareableCache.get(value);
37
+
38
+ if (cached === _shareableFlag) {
39
+ return value;
40
+ } else if (cached !== undefined) {
41
+ return cached;
42
+ } else {
43
+ let toAdapt;
44
+
45
+ if (Array.isArray(value)) {
46
+ toAdapt = value.map(element => makeShareableCloneRecursive(element));
47
+ } else if (type === 'function' && value.__workletHash === undefined) {
48
+ // this is a remote function
49
+ toAdapt = value;
50
+ } else {
51
+ toAdapt = {};
52
+
53
+ for (const [key, element] of Object.entries(value)) {
54
+ toAdapt[key] = makeShareableCloneRecursive(element);
55
+ }
56
+ }
57
+
58
+ if (__DEV__) {
59
+ // we freeze objects that are transformed to shareable. This should help
60
+ // detect issues when someone modifies data after it's been converted to
61
+ // shareable. Meaning that they may be doing a faulty assumption in their
62
+ // code expecting that the updates are going to automatically populate to
63
+ // the object sent to the UI thread. If the user really wants some objects
64
+ // to be mutable they should use share values instead.
65
+ Object.freeze(value);
66
+ }
67
+
68
+ const adopted = NativeReanimatedModule.makeShareableClone(toAdapt);
69
+
70
+ _shareableCache.set(value, adopted);
71
+
72
+ _shareableCache.set(adopted, _shareableFlag);
73
+
74
+ return adopted;
75
+ }
76
+ }
77
+
78
+ return NativeReanimatedModule.makeShareableClone(value);
79
+ }
80
+ export function makeShareableCloneOnUIRecursive(value) {
81
+ 'worklet';
82
+
83
+ if (USE_STUB_IMPLEMENTATION) {
84
+ // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread
85
+ // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.
86
+ return value;
87
+ }
88
+
89
+ function cloneRecursive(value) {
90
+ const type = typeof value;
91
+
92
+ if ((type === 'object' || type === 'function') && value !== null) {
93
+ let toAdapt;
94
+
95
+ if (Array.isArray(value)) {
96
+ toAdapt = value.map(element => cloneRecursive(element));
97
+ } else {
98
+ toAdapt = {};
99
+
100
+ for (const [key, element] of Object.entries(value)) {
101
+ toAdapt[key] = cloneRecursive(element);
102
+ }
103
+ }
104
+
105
+ if (__DEV__) {
106
+ // See the reasoning behind freezing in the other comment above.
107
+ Object.freeze(value);
108
+ }
109
+
110
+ return _makeShareableClone(toAdapt);
111
+ }
112
+
113
+ return _makeShareableClone(value);
114
+ }
115
+
116
+ return cloneRecursive(value);
117
+ }
118
+ export function makeShareable(value) {
119
+ if (USE_STUB_IMPLEMENTATION) {
120
+ return value;
121
+ }
122
+
123
+ const handle = makeShareableCloneRecursive({
124
+ __init: () => {
125
+ 'worklet';
126
+
127
+ return value;
128
+ }
129
+ });
130
+ registerShareableMapping(value, handle);
131
+ return value;
132
+ }
133
+ //# sourceMappingURL=shareables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeReanimatedModule","shouldBeUseWeb","USE_STUB_IMPLEMENTATION","_shareableCache","WeakMap","_shareableFlag","Symbol","registerShareableMapping","shareable","shareableRef","set","makeShareableShadowNodeWrapper","shadowNodeWrapper","adoptedSNW","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,OAAOA,sBAAP,MAAmC,oBAAnC;AAEA,SAASC,cAAT,QAA+B,mBAA/B,C,CAEA;AACA;AACA;AACA;;AACA,MAAMC,uBAAuB,GAAGD,cAAc,EAA9C;;AAEA,MAAME,eAAe,GAAG,IAAIC,OAAJ,EAAxB,C,CAIA;AACA;;;AACA,MAAMC,cAAc,GAAGC,MAAM,CAAC,gBAAD,CAA7B;;AAEA,OAAO,SAASC,wBAAT,CACLC,SADK,EAELC,YAFK,EAGC;E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d,OAAD,CAA1B;IACD;;IACD,OAAOc,mBAAmB,CAACnB,KAAD,CAA1B;EACD;;EACD,OAAOkB,cAAc,CAAClB,KAAD,CAArB;AACD;AAED,OAAO,SAASoB,aAAT,CAA0BpB,KAA1B,EAAuC;EAC5C,IAAId,uBAAJ,EAA6B;IAC3B,OAAOc,KAAP;EACD;;EACD,MAAMqB,MAAM,GAAGtB,2BAA2B,CAAC;IACzCuB,MAAM,EAAE,MAAM;MACZ;;MACA,OAAOtB,KAAP;IACD;EAJwC,CAAD,CAA1C;EAMAT,wBAAwB,CAACS,KAAD,EAAQqB,MAAR,CAAxB;EACA,OAAOrB,KAAP;AACD"}
@@ -0,0 +1,45 @@
1
+ import NativeReanimatedModule from './NativeReanimated';
2
+ import { makeShareableCloneOnUIRecursive, makeShareableCloneRecursive } from './shareables';
3
+ export function runOnUI(worklet) {
4
+ if (__DEV__) {
5
+ if (worklet.__workletHash === undefined) {
6
+ throw new Error('runOnUI() can only be used on worklets');
7
+ }
8
+ }
9
+
10
+ return function () {
11
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
+ args[_key] = arguments[_key];
13
+ }
14
+
15
+ NativeReanimatedModule.scheduleOnUI(makeShareableCloneRecursive(() => {
16
+ 'worklet';
17
+
18
+ return worklet(...args);
19
+ }));
20
+ };
21
+ }
22
+ export function runOnJS(fun) {
23
+ 'worklet';
24
+
25
+ if (fun.__remoteFunction) {
26
+ // in development mode the function provided as `fun` throws an error message
27
+ // such that when someone accidently calls it directly on the UI runtime, they
28
+ // see that they should use `runOnJS` instead. To facilitate that we purt the
29
+ // reference to the original remote function in the `__remoteFunction` property.
30
+ fun = fun.__remoteFunction;
31
+ }
32
+
33
+ if (!_WORKLET) {
34
+ return fun;
35
+ }
36
+
37
+ return function () {
38
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
39
+ args[_key2] = arguments[_key2];
40
+ }
41
+
42
+ _scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined);
43
+ };
44
+ }
45
+ //# sourceMappingURL=threads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeReanimatedModule","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","runOnUI","worklet","__DEV__","__workletHash","undefined","Error","args","scheduleOnUI","runOnJS","fun","__remoteFunction","_WORKLET","_scheduleOnJS","length"],"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,OAAOA,sBAAP,MAAmC,oBAAnC;AAEA,SACEC,+BADF,EAEEC,2BAFF,QAGO,cAHP;AAKA,OAAO,SAASC,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;;IAClBT,sBAAsB,CAACU,YAAvB,CACER,2BAA2B,CAAC,MAAM;MAChC;;MACA,OAAOE,OAAO,CAAC,GAAGK,IAAJ,CAAd;IACD,CAH0B,CAD7B;EAMD,CAPD;AAQD;AAED,OAAO,SAASE,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,mCAATH,IAAS;MAATA,IAAS;IAAA;;IAClBM,aAAa,CACXH,GADW,EAEXH,IAAI,CAACO,MAAL,GAAc,CAAd,GAAkBf,+BAA+B,CAACQ,IAAD,CAAjD,GAA0DF,SAF/C,CAAb;EAID,CALD;AAMD"}
@@ -0,0 +1,37 @@
1
+ import NativeReanimatedModule from './NativeReanimated';
2
+ import { Platform } from 'react-native';
3
+ import { nativeShouldBeMock } from './PlatformChecker';
4
+ export { stopMapper } from './mappers';
5
+
6
+ let _getTimestamp;
7
+
8
+ if (nativeShouldBeMock()) {
9
+ _getTimestamp = () => {
10
+ return NativeReanimatedModule.getTimestamp();
11
+ };
12
+ } else {
13
+ _getTimestamp = () => {
14
+ 'worklet';
15
+
16
+ if (_frameTimestamp) {
17
+ return _frameTimestamp;
18
+ }
19
+
20
+ if (_eventTimestamp) {
21
+ return _eventTimestamp;
22
+ }
23
+
24
+ return _getCurrentTime();
25
+ };
26
+ }
27
+
28
+ export function getTimestamp() {
29
+ 'worklet';
30
+
31
+ if (Platform.OS === 'web') {
32
+ return NativeReanimatedModule.getTimestamp();
33
+ }
34
+
35
+ return _getTimestamp();
36
+ }
37
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeReanimatedModule","Platform","nativeShouldBeMock","stopMapper","_getTimestamp","getTimestamp","_frameTimestamp","_eventTimestamp","_getCurrentTime","OS"],"sources":["time.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { Platform } from 'react-native';\nimport { nativeShouldBeMock } from './PlatformChecker';\nexport { stopMapper } from './mappers';\n\nlet _getTimestamp: () => number;\nif (nativeShouldBeMock()) {\n _getTimestamp = () => {\n return NativeReanimatedModule.getTimestamp();\n };\n} else {\n _getTimestamp = () => {\n 'worklet';\n if (_frameTimestamp) {\n return _frameTimestamp;\n }\n if (_eventTimestamp) {\n return _eventTimestamp;\n }\n return _getCurrentTime();\n };\n}\n\nexport function getTimestamp(): number {\n 'worklet';\n if (Platform.OS === 'web') {\n return NativeReanimatedModule.getTimestamp();\n }\n return _getTimestamp();\n}\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,oBAAnC;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,kBAAT,QAAmC,mBAAnC;AACA,SAASC,UAAT,QAA2B,WAA3B;;AAEA,IAAIC,aAAJ;;AACA,IAAIF,kBAAkB,EAAtB,EAA0B;EACxBE,aAAa,GAAG,MAAM;IACpB,OAAOJ,sBAAsB,CAACK,YAAvB,EAAP;EACD,CAFD;AAGD,CAJD,MAIO;EACLD,aAAa,GAAG,MAAM;IACpB;;IACA,IAAIE,eAAJ,EAAqB;MACnB,OAAOA,eAAP;IACD;;IACD,IAAIC,eAAJ,EAAqB;MACnB,OAAOA,eAAP;IACD;;IACD,OAAOC,eAAe,EAAtB;EACD,CATD;AAUD;;AAED,OAAO,SAASH,YAAT,GAAgC;EACrC;;EACA,IAAIJ,QAAQ,CAACQ,EAAT,KAAgB,KAApB,EAA2B;IACzB,OAAOT,sBAAsB,CAACK,YAAvB,EAAP;EACD;;EACD,OAAOD,aAAa,EAApB;AACD"}