react-native-worklets 0.0.1-alpha → 0.1.0

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 (246) hide show
  1. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +71 -0
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
  3. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +131 -0
  4. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +82 -0
  5. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +72 -0
  6. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +44 -0
  7. package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  8. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -0
  9. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  10. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -0
  11. package/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -0
  12. package/Common/cpp/worklets/SharedItems/Shareables.h +345 -0
  13. package/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -0
  14. package/Common/cpp/worklets/Tools/AsyncQueue.h +35 -0
  15. package/Common/cpp/worklets/Tools/Defs.h +10 -0
  16. package/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  17. package/Common/cpp/worklets/Tools/JSISerializer.h +47 -0
  18. package/Common/cpp/worklets/Tools/JSLogger.cpp +16 -0
  19. package/Common/cpp/worklets/Tools/JSLogger.h +20 -0
  20. package/Common/cpp/worklets/Tools/JSScheduler.cpp +10 -0
  21. package/Common/cpp/worklets/Tools/JSScheduler.h +29 -0
  22. package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  23. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -0
  24. package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  25. package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
  26. package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
  27. package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  28. package/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  29. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +26 -0
  30. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +199 -0
  31. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +20 -0
  32. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -0
  33. package/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  34. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +19 -0
  35. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +16 -0
  36. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +108 -0
  37. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +127 -0
  38. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +183 -0
  39. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -0
  40. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  41. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +179 -0
  42. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -0
  43. package/LICENSE +20 -0
  44. package/README.md +27 -0
  45. package/RNWorklets.podspec +70 -0
  46. package/android/CMakeLists.txt +56 -0
  47. package/android/build.gradle +313 -0
  48. package/android/gradle.properties +5 -0
  49. package/android/proguard-rules.pro +3 -0
  50. package/android/spotless.gradle +9 -0
  51. package/android/src/main/AndroidManifest.xml +2 -0
  52. package/android/src/main/cpp/worklets/CMakeLists.txt +85 -0
  53. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +63 -0
  54. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +41 -0
  55. package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +32 -0
  56. package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +29 -0
  57. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +83 -0
  58. package/android/src/main/cpp/worklets/android/WorkletsModule.h +63 -0
  59. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +13 -0
  60. package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.java +60 -0
  61. package/android/src/main/java/com/swmansion/worklets/AnimationFrameQueue/AnimationFrameCallback.java +20 -0
  62. package/android/src/main/java/com/swmansion/worklets/AnimationFrameQueue/AnimationFrameQueue.java +113 -0
  63. package/android/src/main/java/com/swmansion/worklets/JSCallInvokerResolver.java +27 -0
  64. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThread.java +16 -0
  65. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThreadBase.java +72 -0
  66. package/android/src/main/java/com/swmansion/worklets/WorkletsModule.java +106 -0
  67. package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +49 -0
  68. package/android/src/paper/com/swmansion/worklets/NativeWorkletsModuleSpec.java +26 -0
  69. package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
  70. package/apple/worklets/apple/AnimationFrameQueue.mm +81 -0
  71. package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
  72. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +16 -0
  73. package/apple/worklets/apple/IOSUIScheduler.h +14 -0
  74. package/apple/worklets/apple/IOSUIScheduler.mm +24 -0
  75. package/apple/worklets/apple/PlatformLogger.mm +31 -0
  76. package/apple/worklets/apple/SlowAnimations.h +8 -0
  77. package/apple/worklets/apple/SlowAnimations.mm +47 -0
  78. package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
  79. package/apple/worklets/apple/WorkletsMessageThread.h +16 -0
  80. package/apple/worklets/apple/WorkletsMessageThread.mm +32 -0
  81. package/apple/worklets/apple/WorkletsModule.h +10 -0
  82. package/apple/worklets/apple/WorkletsModule.mm +85 -0
  83. package/lib/module/PlatformChecker.js +35 -0
  84. package/lib/module/PlatformChecker.js.map +1 -0
  85. package/lib/module/WorkletsError.js +13 -0
  86. package/lib/module/WorkletsError.js.map +1 -0
  87. package/lib/module/WorkletsModule/JSWorklets.js +36 -0
  88. package/lib/module/WorkletsModule/JSWorklets.js.map +1 -0
  89. package/lib/module/WorkletsModule/NativeWorklets.js +39 -0
  90. package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
  91. package/lib/module/WorkletsModule/index.js +4 -0
  92. package/lib/module/WorkletsModule/index.js.map +1 -0
  93. package/lib/module/WorkletsModule/workletsModuleInstance.js +7 -0
  94. package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -0
  95. package/lib/module/WorkletsModule/workletsModuleInstance.web.js +5 -0
  96. package/lib/module/WorkletsModule/workletsModuleInstance.web.js.map +1 -0
  97. package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
  98. package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
  99. package/lib/module/animationFrameQueue/mockedRequestAnimationFrame.js +10 -0
  100. package/lib/module/animationFrameQueue/mockedRequestAnimationFrame.js.map +1 -0
  101. package/lib/module/animationFrameQueue/requestAnimationFrame.js +36 -0
  102. package/lib/module/animationFrameQueue/requestAnimationFrame.js.map +1 -0
  103. package/lib/module/errors.js +78 -0
  104. package/lib/module/errors.js.map +1 -0
  105. package/lib/module/index.js +17 -0
  106. package/lib/module/index.js.map +1 -0
  107. package/lib/module/initializers.js +158 -0
  108. package/lib/module/initializers.js.map +1 -0
  109. package/lib/module/logger/LogBox.js +15 -0
  110. package/lib/module/logger/LogBox.js.map +1 -0
  111. package/lib/module/logger/index.js +5 -0
  112. package/lib/module/logger/index.js.map +1 -0
  113. package/lib/module/logger/logger.js +137 -0
  114. package/lib/module/logger/logger.js.map +1 -0
  115. package/lib/module/privateGlobals.d.js +8 -0
  116. package/lib/module/privateGlobals.d.js.map +1 -0
  117. package/lib/module/runtimes.js +63 -0
  118. package/lib/module/runtimes.js.map +1 -0
  119. package/lib/module/shareableMappingCache.js +39 -0
  120. package/lib/module/shareableMappingCache.js.map +1 -0
  121. package/lib/module/shareables.js +417 -0
  122. package/lib/module/shareables.js.map +1 -0
  123. package/lib/module/specs/NativeWorkletsModule.js +5 -0
  124. package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
  125. package/lib/module/specs/index.js +5 -0
  126. package/lib/module/specs/index.js.map +1 -0
  127. package/lib/module/threads.js +204 -0
  128. package/lib/module/threads.js.map +1 -0
  129. package/lib/module/valueUnpacker.js +83 -0
  130. package/lib/module/valueUnpacker.js.map +1 -0
  131. package/lib/module/workletFunction.js +37 -0
  132. package/lib/module/workletFunction.js.map +1 -0
  133. package/lib/module/workletTypes.js +12 -0
  134. package/lib/module/workletTypes.js.map +1 -0
  135. package/lib/typescript/PlatformChecker.d.ts +7 -0
  136. package/lib/typescript/PlatformChecker.d.ts.map +1 -0
  137. package/lib/typescript/WorkletsError.d.ts +3 -0
  138. package/lib/typescript/WorkletsError.d.ts.map +1 -0
  139. package/lib/typescript/WorkletsModule/JSWorklets.d.ts +3 -0
  140. package/lib/typescript/WorkletsModule/JSWorklets.d.ts.map +1 -0
  141. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +5 -0
  142. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
  143. package/lib/typescript/WorkletsModule/index.d.ts +3 -0
  144. package/lib/typescript/WorkletsModule/index.d.ts.map +1 -0
  145. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +2 -0
  146. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -0
  147. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +2 -0
  148. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -0
  149. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +12 -0
  150. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
  151. package/lib/typescript/animationFrameQueue/mockedRequestAnimationFrame.d.ts +6 -0
  152. package/lib/typescript/animationFrameQueue/mockedRequestAnimationFrame.d.ts.map +1 -0
  153. package/lib/typescript/animationFrameQueue/requestAnimationFrame.d.ts +2 -0
  154. package/lib/typescript/animationFrameQueue/requestAnimationFrame.d.ts.map +1 -0
  155. package/lib/typescript/errors.d.ts +19 -0
  156. package/lib/typescript/errors.d.ts.map +1 -0
  157. package/lib/typescript/index.d.ts +13 -0
  158. package/lib/typescript/index.d.ts.map +1 -0
  159. package/lib/typescript/initializers.d.ts +6 -0
  160. package/lib/typescript/initializers.d.ts.map +1 -0
  161. package/lib/typescript/logger/LogBox.d.ts +32 -0
  162. package/lib/typescript/logger/LogBox.d.ts.map +1 -0
  163. package/lib/typescript/logger/index.d.ts +3 -0
  164. package/lib/typescript/logger/index.d.ts.map +1 -0
  165. package/lib/typescript/logger/logger.d.ts +52 -0
  166. package/lib/typescript/logger/logger.d.ts.map +1 -0
  167. package/lib/typescript/runtimes.d.ts +16 -0
  168. package/lib/typescript/runtimes.d.ts.map +1 -0
  169. package/lib/typescript/shareableMappingCache.d.ts +16 -0
  170. package/lib/typescript/shareableMappingCache.d.ts.map +1 -0
  171. package/lib/typescript/shareables.d.ts +15 -0
  172. package/lib/typescript/shareables.d.ts.map +1 -0
  173. package/lib/typescript/specs/NativeWorkletsModule.d.ts +7 -0
  174. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
  175. package/lib/typescript/specs/index.d.ts +3 -0
  176. package/lib/typescript/specs/index.d.ts.map +1 -0
  177. package/lib/typescript/threads.d.ts +49 -0
  178. package/lib/typescript/threads.d.ts.map +1 -0
  179. package/lib/typescript/valueUnpacker.d.ts +2 -0
  180. package/lib/typescript/valueUnpacker.d.ts.map +1 -0
  181. package/lib/typescript/workletFunction.d.ts +27 -0
  182. package/lib/typescript/workletFunction.d.ts.map +1 -0
  183. package/lib/typescript/workletTypes.d.ts +49 -0
  184. package/lib/typescript/workletTypes.d.ts.map +1 -0
  185. package/package.json +106 -8
  186. package/plugin/index.js +3 -0
  187. package/scripts/worklets_utils.rb +53 -0
  188. package/src/PlatformChecker.ts +43 -0
  189. package/src/WorkletsError.ts +13 -0
  190. package/src/WorkletsModule/JSWorklets.ts +57 -0
  191. package/src/WorkletsModule/NativeWorklets.ts +68 -0
  192. package/src/WorkletsModule/index.ts +7 -0
  193. package/src/WorkletsModule/workletsModuleInstance.ts +9 -0
  194. package/src/WorkletsModule/workletsModuleInstance.web.ts +5 -0
  195. package/src/WorkletsModule/workletsModuleProxy.ts +30 -0
  196. package/src/animationFrameQueue/mockedRequestAnimationFrame.ts +11 -0
  197. package/src/animationFrameQueue/requestAnimationFrame.ts +41 -0
  198. package/src/errors.ts +103 -0
  199. package/src/index.ts +42 -0
  200. package/src/initializers.ts +175 -0
  201. package/src/logger/LogBox.ts +55 -0
  202. package/src/logger/index.ts +3 -0
  203. package/src/logger/logger.ts +155 -0
  204. package/src/privateGlobals.d.ts +41 -0
  205. package/src/runtimes.ts +92 -0
  206. package/src/shareableMappingCache.ts +44 -0
  207. package/src/shareables.ts +577 -0
  208. package/src/specs/NativeWorkletsModule.ts +9 -0
  209. package/src/specs/index.ts +5 -0
  210. package/src/threads.ts +275 -0
  211. package/src/valueUnpacker.ts +110 -0
  212. package/src/workletFunction.ts +47 -0
  213. package/src/workletTypes.ts +76 -0
  214. package/Animated.js +0 -13
  215. package/AnimatedEvent.js +0 -167
  216. package/AnimatedImplementation.js +0 -666
  217. package/CoreAnimated.js +0 -43
  218. package/Easing.js +0 -236
  219. package/NativeAnimatedHelper.js +0 -226
  220. package/SpringConfig.js +0 -79
  221. package/animations/Animation.js +0 -36
  222. package/animations/DecayAnimation.js +0 -70
  223. package/animations/SpringAnimation.js +0 -125
  224. package/animations/TimingAnimation.js +0 -70
  225. package/bezier.js +0 -128
  226. package/createAnimatedComponent.js +0 -188
  227. package/nodes/AnimatedBlock.js +0 -19
  228. package/nodes/AnimatedClock.js +0 -76
  229. package/nodes/AnimatedCond.js +0 -23
  230. package/nodes/AnimatedDetach.js +0 -15
  231. package/nodes/AnimatedInterpolation.js +0 -338
  232. package/nodes/AnimatedNode.js +0 -97
  233. package/nodes/AnimatedOnChange.js +0 -28
  234. package/nodes/AnimatedOp.js +0 -17
  235. package/nodes/AnimatedProps.js +0 -154
  236. package/nodes/AnimatedSet.js +0 -19
  237. package/nodes/AnimatedStartClock.js +0 -21
  238. package/nodes/AnimatedStopClock.js +0 -21
  239. package/nodes/AnimatedStyle.js +0 -89
  240. package/nodes/AnimatedTracking.js +0 -36
  241. package/nodes/AnimatedTransform.js +0 -93
  242. package/nodes/AnimatedValue.js +0 -271
  243. package/nodes/AnimatedWithInput.js +0 -21
  244. package/nodes/SpringNode.js +0 -106
  245. package/nodes/TimingStep.js +0 -44
  246. package/utils.js +0 -28
@@ -1,666 +0,0 @@
1
- import { AnimatedEvent, attachNativeEvent } from './AnimatedEvent';
2
- import AnimatedCond from './nodes/AnimatedCond';
3
- import AnimatedSet from './nodes/AnimatedSet';
4
- import AnimatedInterpolation from './nodes/AnimatedInterpolation';
5
- import AnimatedOp from './nodes/AnimatedOp';
6
- import AnimatedOnChange from './nodes/AnimatedOnChange';
7
- import AnimatedNode from './nodes/AnimatedNode';
8
- import AnimatedProps from './nodes/AnimatedProps';
9
- import AnimatedTracking from './nodes/AnimatedTracking';
10
- import AnimatedValue from './nodes/AnimatedValue';
11
- import DecayAnimation from './animations/DecayAnimation';
12
- import SpringAnimation from './animations/SpringAnimation';
13
- import TimingAnimation from './animations/TimingAnimation';
14
- import SpringNode from './nodes/SpringNode';
15
- import AnimatedClock from './nodes/AnimatedClock';
16
- import AnimatedStartClock from './nodes/AnimatedStartClock';
17
- import AnimatedStopClock from './nodes/AnimatedStopClock';
18
-
19
- import { adapt } from './utils';
20
- import createAnimatedComponent from './createAnimatedComponent';
21
-
22
- const add = function(a, b) {
23
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a + b);
24
- };
25
-
26
- const divide = function(a, b) {
27
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a / b);
28
- };
29
-
30
- const multiply = function(a, b) {
31
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a * b);
32
- };
33
-
34
- const set = function(what, value) {
35
- return new AnimatedSet(what, adapt(value));
36
- };
37
-
38
- const cond = function(cond, ifBlock, elseBlock) {
39
- return new AnimatedCond(adapt(cond), adapt(ifBlock), adapt(elseBlock));
40
- };
41
-
42
- const eq = function(a, b) {
43
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a === b);
44
- };
45
-
46
- const lessThan = function(a, b) {
47
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a < b);
48
- };
49
-
50
- const defined = function(v) {
51
- return new AnimatedOp(
52
- [adapt(v)],
53
- ([v]) => v !== null && v !== undefined && !isNaN(v)
54
- );
55
- };
56
-
57
- const or = function(a, b) {
58
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a || b);
59
- };
60
-
61
- const and = function(a, b) {
62
- return new AnimatedOp([adapt(a), adapt(b)], ([a, b]) => a && b);
63
- };
64
-
65
- const block = function(items) {
66
- return adapt(items);
67
- };
68
-
69
- const call = function(items, func) {
70
- return new AnimatedOp(
71
- items.map(node => adapt(node)),
72
- values => func(values) && 0
73
- );
74
- };
75
-
76
- const modulo = function(a, modulus) {
77
- return new AnimatedOp(
78
- [adapt(a), adapt(modulus)],
79
- ([a, b]) => (a % b + b) % b
80
- );
81
- };
82
-
83
- const onChange = function(value, action) {
84
- return new AnimatedOnChange(adapt(value), adapt(action));
85
- };
86
-
87
- const min = function(a, b) {
88
- return cond(lessThan(a, b), a, b);
89
- };
90
-
91
- const max = function(a, b) {
92
- return cond(lessThan(a, b), b, a);
93
- };
94
-
95
- const diff = function(v) {
96
- const stash = new AnimatedValue(0);
97
- const prev = new AnimatedValue();
98
- return block([
99
- set(stash, cond(defined(prev), add(v, multiply(-1, prev)), 0)),
100
- set(prev, v),
101
- stash,
102
- ]);
103
- };
104
-
105
- const acc = function(v) {
106
- const acc = new AnimatedValue(0);
107
- return set(acc, add(acc, v));
108
- };
109
-
110
- const diffClamp = function(a, minVal, maxVal) {
111
- const value = new AnimatedValue();
112
- return set(
113
- value,
114
- min(max(add(cond(defined(value), value, a), diff(a)), minVal), maxVal)
115
- );
116
- };
117
-
118
- const startClock = function(clock) {
119
- return new AnimatedStartClock(clock);
120
- };
121
-
122
- const stopClock = function(clock) {
123
- return new AnimatedStopClock(clock);
124
- };
125
-
126
- const _combineCallbacks = function(callback, config) {
127
- if (callback && config.onComplete) {
128
- return (...args) => {
129
- config.onComplete && config.onComplete(...args);
130
- callback && callback(...args);
131
- };
132
- } else {
133
- return callback || config.onComplete;
134
- }
135
- };
136
-
137
- const maybeVectorAnim = function(value, config, anim) {
138
- return null;
139
- };
140
-
141
- const spring = function(clock, toValue, springState, springConfig) {
142
- if (springState !== undefined) {
143
- return new SpringNode(clock, adapt(toValue), springState, springConfig);
144
- }
145
- const value = clock; // for compatibility with Animated lib
146
- const config = toValue;
147
- const start = function(animatedValue, configuration, callback) {
148
- callback = _combineCallbacks(callback, configuration);
149
- const singleValue = animatedValue;
150
- const singleConfig = configuration;
151
- singleValue.stopTracking();
152
- if (configuration.toValue instanceof AnimatedNode) {
153
- singleValue.track(
154
- new AnimatedTracking(
155
- singleValue,
156
- configuration.toValue,
157
- SpringAnimation,
158
- singleConfig,
159
- callback
160
- )
161
- );
162
- } else {
163
- singleValue.animate(new SpringAnimation(singleConfig), callback);
164
- }
165
- };
166
- return {
167
- start: function(callback) {
168
- start(value, config, callback);
169
- },
170
-
171
- stop: function() {
172
- value.stopAnimation();
173
- },
174
-
175
- reset: function() {
176
- value.resetAnimation();
177
- },
178
-
179
- _startNativeLoop: function(iterations) {
180
- const singleConfig = { ...config, iterations };
181
- start(value, singleConfig);
182
- },
183
-
184
- _isUsingNativeDriver: function() {
185
- return config.useNativeDriver || false;
186
- },
187
- };
188
- };
189
-
190
- const timing = function(value, config) {
191
- const start = function(animatedValue, configuration, callback) {
192
- callback = _combineCallbacks(callback, configuration);
193
- const singleValue = animatedValue;
194
- const singleConfig = configuration;
195
- singleValue.stopTracking();
196
- if (configuration.toValue instanceof AnimatedNode) {
197
- singleValue.track(
198
- new AnimatedTracking(
199
- singleValue,
200
- configuration.toValue,
201
- TimingAnimation,
202
- singleConfig,
203
- callback
204
- )
205
- );
206
- } else {
207
- singleValue.animate(new TimingAnimation(singleConfig), callback);
208
- }
209
- };
210
-
211
- return (
212
- maybeVectorAnim(value, config, timing) || {
213
- start: function(callback) {
214
- start(value, config, callback);
215
- },
216
-
217
- stop: function() {
218
- value.stopAnimation();
219
- },
220
-
221
- reset: function() {
222
- value.resetAnimation();
223
- },
224
-
225
- _startNativeLoop: function(iterations) {
226
- const singleConfig = { ...config, iterations };
227
- start(value, singleConfig);
228
- },
229
-
230
- _isUsingNativeDriver: function() {
231
- return config.useNativeDriver || false;
232
- },
233
- }
234
- );
235
- };
236
-
237
- const decay = function(value, config) {
238
- const start = function(animatedValue, configuration, callback) {
239
- callback = _combineCallbacks(callback, configuration);
240
- const singleValue = animatedValue;
241
- const singleConfig = configuration;
242
- singleValue.stopTracking();
243
- singleValue.animate(new DecayAnimation(singleConfig), callback);
244
- };
245
-
246
- return (
247
- maybeVectorAnim(value, config, decay) || {
248
- start: function(callback) {
249
- start(value, config, callback);
250
- },
251
-
252
- stop: function() {
253
- value.stopAnimation();
254
- },
255
-
256
- reset: function() {
257
- value.resetAnimation();
258
- },
259
-
260
- _startNativeLoop: function(iterations) {
261
- const singleConfig = { ...config, iterations };
262
- start(value, singleConfig);
263
- },
264
-
265
- _isUsingNativeDriver: function() {
266
- return config.useNativeDriver || false;
267
- },
268
- }
269
- );
270
- };
271
-
272
- const sequence = function(animations) {
273
- let current = 0;
274
- return {
275
- start: function(callback) {
276
- const onComplete = function(result) {
277
- if (!result.finished) {
278
- callback && callback(result);
279
- return;
280
- }
281
-
282
- current++;
283
-
284
- if (current === animations.length) {
285
- callback && callback(result);
286
- return;
287
- }
288
-
289
- animations[current].start(onComplete);
290
- };
291
-
292
- if (animations.length === 0) {
293
- callback && callback({ finished: true });
294
- } else {
295
- animations[current].start(onComplete);
296
- }
297
- },
298
-
299
- stop: function() {
300
- if (current < animations.length) {
301
- animations[current].stop();
302
- }
303
- },
304
-
305
- reset: function() {
306
- animations.forEach((animation, idx) => {
307
- if (idx <= current) {
308
- animation.reset();
309
- }
310
- });
311
- current = 0;
312
- },
313
-
314
- _startNativeLoop: function() {
315
- throw new Error(
316
- 'Loops run using the native driver cannot contain Animated.sequence animations'
317
- );
318
- },
319
-
320
- _isUsingNativeDriver: function() {
321
- return false;
322
- },
323
- };
324
- };
325
-
326
- const parallel = function(animations, config) {
327
- let doneCount = 0;
328
- // Make sure we only call stop() at most once for each animation
329
- const hasEnded = {};
330
- const stopTogether = !(config && config.stopTogether === false);
331
-
332
- const result = {
333
- start: function(callback) {
334
- if (doneCount === animations.length) {
335
- callback && callback({ finished: true });
336
- return;
337
- }
338
-
339
- animations.forEach((animation, idx) => {
340
- const cb = function(endResult) {
341
- hasEnded[idx] = true;
342
- doneCount++;
343
- if (doneCount === animations.length) {
344
- doneCount = 0;
345
- callback && callback(endResult);
346
- return;
347
- }
348
-
349
- if (!endResult.finished && stopTogether) {
350
- result.stop();
351
- }
352
- };
353
-
354
- if (!animation) {
355
- cb({ finished: true });
356
- } else {
357
- animation.start(cb);
358
- }
359
- });
360
- },
361
-
362
- stop: function() {
363
- animations.forEach((animation, idx) => {
364
- !hasEnded[idx] && animation.stop();
365
- hasEnded[idx] = true;
366
- });
367
- },
368
-
369
- reset: function() {
370
- animations.forEach((animation, idx) => {
371
- animation.reset();
372
- hasEnded[idx] = false;
373
- doneCount = 0;
374
- });
375
- },
376
-
377
- _startNativeLoop: function() {
378
- throw new Error(
379
- 'Loops run using the native driver cannot contain Animated.parallel animations'
380
- );
381
- },
382
-
383
- _isUsingNativeDriver: function() {
384
- return false;
385
- },
386
- };
387
-
388
- return result;
389
- };
390
-
391
- const delay = function(time) {
392
- // Would be nice to make a specialized implementation
393
- return timing(new AnimatedValue(0), { toValue: 0, delay: time, duration: 0 });
394
- };
395
-
396
- const stagger = function(time, animations) {
397
- return parallel(
398
- animations.map((animation, i) => {
399
- return sequence([delay(time * i), animation]);
400
- })
401
- );
402
- };
403
-
404
- const loop = function(animation, { iterations = -1 } = {}) {
405
- let isFinished = false;
406
- let iterationsSoFar = 0;
407
- return {
408
- start: function(callback) {
409
- const restart = function(result = { finished: true }) {
410
- if (
411
- isFinished ||
412
- iterationsSoFar === iterations ||
413
- result.finished === false
414
- ) {
415
- callback && callback(result);
416
- } else {
417
- iterationsSoFar++;
418
- animation.reset();
419
- animation.start(restart);
420
- }
421
- };
422
- if (!animation || iterations === 0) {
423
- callback && callback({ finished: true });
424
- } else {
425
- if (animation._isUsingNativeDriver()) {
426
- animation._startNativeLoop(iterations);
427
- } else {
428
- restart(); // Start looping recursively on the js thread
429
- }
430
- }
431
- },
432
-
433
- stop: function() {
434
- isFinished = true;
435
- animation.stop();
436
- },
437
-
438
- reset: function() {
439
- iterationsSoFar = 0;
440
- isFinished = false;
441
- animation.reset();
442
- },
443
-
444
- _startNativeLoop: function() {
445
- throw new Error(
446
- 'Loops run using the native driver cannot contain Animated.loop animations'
447
- );
448
- },
449
-
450
- _isUsingNativeDriver: function() {
451
- return animation._isUsingNativeDriver();
452
- },
453
- };
454
- };
455
-
456
- function forkEvent(event, listener) {
457
- if (!event) {
458
- return listener;
459
- } else if (event instanceof AnimatedEvent) {
460
- event.__addListener(listener);
461
- return event;
462
- } else {
463
- return (...args) => {
464
- typeof event === 'function' && event(...args);
465
- listener(...args);
466
- };
467
- }
468
- }
469
-
470
- function unforkEvent(event, listener) {
471
- if (event && event instanceof AnimatedEvent) {
472
- event.__removeListener(listener);
473
- }
474
- }
475
-
476
- const event = function(argMapping, config) {
477
- const animatedEvent = new AnimatedEvent(argMapping, config);
478
- if (animatedEvent.__isNative) {
479
- return animatedEvent;
480
- } else {
481
- return animatedEvent.__getHandler();
482
- }
483
- };
484
-
485
- /**
486
- * The `Animated` library is designed to make animations fluid, powerful, and
487
- * easy to build and maintain. `Animated` focuses on declarative relationships
488
- * between inputs and outputs, with configurable transforms in between, and
489
- * simple `start`/`stop` methods to control time-based animation execution.
490
- *
491
- * See http://facebook.github.io/react-native/docs/animated.html
492
- */
493
- module.exports = {
494
- /**
495
- * Standard value class for driving animations. Typically initialized with
496
- * `new Animated.Value(0);`
497
- *
498
- * See http://facebook.github.io/react-native/docs/animated.html#value
499
- */
500
- Value: AnimatedValue,
501
- /**
502
- * Exported to use the Interpolation type in flow.
503
- *
504
- * See http://facebook.github.io/react-native/docs/animated.html#interpolation
505
- */
506
- Interpolation: AnimatedInterpolation,
507
- /**
508
- * Exported for ease of type checking. All animated values derive from this
509
- * class.
510
- *
511
- * See http://facebook.github.io/react-native/docs/animated.html#node
512
- */
513
- Node: AnimatedNode,
514
-
515
- /**
516
- * Animates a value from an initial velocity to zero based on a decay
517
- * coefficient.
518
- *
519
- * See http://facebook.github.io/react-native/docs/animated.html#decay
520
- */
521
- decay,
522
- /**
523
- * Animates a value along a timed easing curve. The Easing module has tons of
524
- * predefined curves, or you can use your own function.
525
- *
526
- * See http://facebook.github.io/react-native/docs/animated.html#timing
527
- */
528
- timing,
529
- /**
530
- * Animates a value according to an analytical spring model based on
531
- * damped harmonic oscillation.
532
- *
533
- * See http://facebook.github.io/react-native/docs/animated.html#spring
534
- */
535
- spring,
536
-
537
- /**
538
- * Creates a new Animated value composed from two Animated values added
539
- * together.
540
- *
541
- * See http://facebook.github.io/react-native/docs/animated.html#add
542
- */
543
- add,
544
-
545
- cond,
546
- block,
547
- set,
548
- lessThan,
549
- eq,
550
- or,
551
- and,
552
- onChange,
553
- call,
554
- min,
555
- max,
556
- diff,
557
- defined,
558
- acc,
559
- startClock,
560
- stopClock,
561
- Clock: AnimatedClock,
562
-
563
- /**
564
- * Creates a new Animated value composed by dividing the first Animated value
565
- * by the second Animated value.
566
- *
567
- * See http://facebook.github.io/react-native/docs/animated.html#divide
568
- */
569
- divide,
570
-
571
- /**
572
- * Creates a new Animated value composed from two Animated values multiplied
573
- * together.
574
- *
575
- * See http://facebook.github.io/react-native/docs/animated.html#multiply
576
- */
577
- multiply,
578
-
579
- /**
580
- * Creates a new Animated value that is the (non-negative) modulo of the
581
- * provided Animated value.
582
- *
583
- * See http://facebook.github.io/react-native/docs/animated.html#modulo
584
- */
585
- modulo,
586
-
587
- /**
588
- * Create a new Animated value that is limited between 2 values. It uses the
589
- * difference between the last value so even if the value is far from the
590
- * bounds it will start changing when the value starts getting closer again.
591
- *
592
- * See http://facebook.github.io/react-native/docs/animated.html#diffclamp
593
- */
594
- diffClamp,
595
-
596
- /**
597
- * Starts an animation after the given delay.
598
- *
599
- * See http://facebook.github.io/react-native/docs/animated.html#delay
600
- */
601
- delay,
602
- /**
603
- * Starts an array of animations in order, waiting for each to complete
604
- * before starting the next. If the current running animation is stopped, no
605
- * following animations will be started.
606
- *
607
- * See http://facebook.github.io/react-native/docs/animated.html#sequence
608
- */
609
- sequence,
610
- /**
611
- * Starts an array of animations all at the same time. By default, if one
612
- * of the animations is stopped, they will all be stopped. You can override
613
- * this with the `stopTogether` flag.
614
- *
615
- * See http://facebook.github.io/react-native/docs/animated.html#parallel
616
- */
617
- parallel,
618
- /**
619
- * Array of animations may run in parallel (overlap), but are started in
620
- * sequence with successive delays. Nice for doing trailing effects.
621
- *
622
- * See http://facebook.github.io/react-native/docs/animated.html#stagger
623
- */
624
- stagger,
625
- /**
626
- * Loops a given animation continuously, so that each time it reaches the
627
- * end, it resets and begins again from the start.
628
- *
629
- * See http://facebook.github.io/react-native/docs/animated.html#loop
630
- */
631
- loop,
632
-
633
- /**
634
- * Takes an array of mappings and extracts values from each arg accordingly,
635
- * then calls `setValue` on the mapped outputs.
636
- *
637
- * See http://facebook.github.io/react-native/docs/animated.html#event
638
- */
639
- event,
640
-
641
- /**
642
- * Make any React component Animatable. Used to create `Animated.View`, etc.
643
- *
644
- * See http://facebook.github.io/react-native/docs/animated.html#createanimatedcomponent
645
- */
646
- createAnimatedComponent,
647
-
648
- /**
649
- * Imperative API to attach an animated value to an event on a view. Prefer
650
- * using `Animated.event` with `useNativeDrive: true` if possible.
651
- *
652
- * See http://facebook.github.io/react-native/docs/animated.html#attachnativeevent
653
- */
654
- attachNativeEvent,
655
-
656
- /**
657
- * Advanced imperative API for snooping on animated events that are passed in
658
- * through props. Use values directly where possible.
659
- *
660
- * See http://facebook.github.io/react-native/docs/animated.html#forkevent
661
- */
662
- forkEvent,
663
- unforkEvent,
664
-
665
- __PropsOnlyForTests: AnimatedProps,
666
- };
package/CoreAnimated.js DELETED
@@ -1,43 +0,0 @@
1
- const UPDATED_NODES = [];
2
-
3
- let loopID = 1;
4
- let propUpdatesEnqueued = null;
5
-
6
- function findAndUpdateNodes(node) {
7
- if (typeof node.update === 'function') {
8
- node.update();
9
- } else {
10
- node.__getChildren().forEach(findAndUpdateNodes);
11
- }
12
- }
13
-
14
- function runPropUpdates() {
15
- const visitedNodes = new Set();
16
- for (let i = 0; i < UPDATED_NODES.length; i++) {
17
- const node = UPDATED_NODES[i];
18
- if (!visitedNodes.has(node)) {
19
- visitedNodes.add(node);
20
- findAndUpdateNodes(node);
21
- }
22
- }
23
- UPDATED_NODES.length = 0; // clear array
24
- propUpdatesEnqueued = null;
25
- loopID += 1;
26
- }
27
-
28
- function onNodeUpdated(node) {
29
- UPDATED_NODES.push(node);
30
- if (!propUpdatesEnqueued) {
31
- propUpdatesEnqueued = setImmediate(runPropUpdates);
32
- }
33
- }
34
-
35
- function evaluate(node) {
36
- if (node.__lastLoopID < loopID) {
37
- node.__lastLoopID = loopID;
38
- return (node.__memoizedValue = node.__onEvaluate());
39
- }
40
- return node.__memoizedValue;
41
- }
42
-
43
- export { onNodeUpdated, evaluate };