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,338 +0,0 @@
1
- import AnimatedWithInput from './AnimatedWithInput';
2
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
3
-
4
- import invariant from 'fbjs/lib/invariant';
5
- import normalizeColor from 'normalizeColor';
6
-
7
- const linear = t => t;
8
-
9
- /**
10
- * Very handy helper to map input ranges to output ranges with an easing
11
- * function and custom behavior outside of the ranges.
12
- */
13
- function createInterpolation(config) {
14
- if (config.outputRange && typeof config.outputRange[0] === 'string') {
15
- return createInterpolationFromStringOutputRange(config);
16
- }
17
-
18
- const outputRange = config.outputRange;
19
- checkInfiniteRange('outputRange', outputRange);
20
-
21
- const inputRange = config.inputRange;
22
- checkInfiniteRange('inputRange', inputRange);
23
- checkValidInputRange(inputRange);
24
-
25
- invariant(
26
- inputRange.length === outputRange.length,
27
- 'inputRange (' +
28
- inputRange.length +
29
- ') and outputRange (' +
30
- outputRange.length +
31
- ') must have the same length'
32
- );
33
-
34
- const easing = config.easing || linear;
35
-
36
- let extrapolateLeft = 'extend';
37
- if (config.extrapolateLeft !== undefined) {
38
- extrapolateLeft = config.extrapolateLeft;
39
- } else if (config.extrapolate !== undefined) {
40
- extrapolateLeft = config.extrapolate;
41
- }
42
-
43
- let extrapolateRight = 'extend';
44
- if (config.extrapolateRight !== undefined) {
45
- extrapolateRight = config.extrapolateRight;
46
- } else if (config.extrapolate !== undefined) {
47
- extrapolateRight = config.extrapolate;
48
- }
49
-
50
- return input => {
51
- invariant(
52
- typeof input === 'number',
53
- 'Cannot interpolation an input which is not a number'
54
- );
55
-
56
- const range = findRange(input, inputRange);
57
- return interpolate(
58
- input,
59
- inputRange[range],
60
- inputRange[range + 1],
61
- outputRange[range],
62
- outputRange[range + 1],
63
- easing,
64
- extrapolateLeft,
65
- extrapolateRight
66
- );
67
- };
68
- }
69
-
70
- function interpolate(
71
- input,
72
- inputMin,
73
- inputMax,
74
- outputMin,
75
- outputMax,
76
- easing,
77
- extrapolateLeft,
78
- extrapolateRight
79
- ) {
80
- let result = input;
81
-
82
- // Extrapolate
83
- if (result < inputMin) {
84
- if (extrapolateLeft === 'identity') {
85
- return result;
86
- } else if (extrapolateLeft === 'clamp') {
87
- result = inputMin;
88
- } else if (extrapolateLeft === 'extend') {
89
- // noop
90
- }
91
- }
92
-
93
- if (result > inputMax) {
94
- if (extrapolateRight === 'identity') {
95
- return result;
96
- } else if (extrapolateRight === 'clamp') {
97
- result = inputMax;
98
- } else if (extrapolateRight === 'extend') {
99
- // noop
100
- }
101
- }
102
-
103
- if (outputMin === outputMax) {
104
- return outputMin;
105
- }
106
-
107
- if (inputMin === inputMax) {
108
- if (input <= inputMin) {
109
- return outputMin;
110
- }
111
- return outputMax;
112
- }
113
-
114
- // Input Range
115
- if (inputMin === -Infinity) {
116
- result = -result;
117
- } else if (inputMax === Infinity) {
118
- result = result - inputMin;
119
- } else {
120
- result = (result - inputMin) / (inputMax - inputMin);
121
- }
122
-
123
- // Easing
124
- result = easing(result);
125
-
126
- // Output Range
127
- if (outputMin === -Infinity) {
128
- result = -result;
129
- } else if (outputMax === Infinity) {
130
- result = result + outputMin;
131
- } else {
132
- result = result * (outputMax - outputMin) + outputMin;
133
- }
134
-
135
- return result;
136
- }
137
-
138
- function colorToRgba(input) {
139
- let int32Color = normalizeColor(input);
140
- if (int32Color === null) {
141
- return input;
142
- }
143
-
144
- int32Color = int32Color || 0;
145
-
146
- const r = (int32Color & 0xff000000) >>> 24;
147
- const g = (int32Color & 0x00ff0000) >>> 16;
148
- const b = (int32Color & 0x0000ff00) >>> 8;
149
- const a = (int32Color & 0x000000ff) / 255;
150
-
151
- return `rgba(${r}, ${g}, ${b}, ${a})`;
152
- }
153
-
154
- const stringShapeRegex = /[0-9\.-]+/g;
155
-
156
- /**
157
- * Supports string shapes by extracting numbers so new values can be computed,
158
- * and recombines those values into new strings of the same shape. Supports
159
- * things like:
160
- *
161
- * rgba(123, 42, 99, 0.36) // colors
162
- * -45deg // values with units
163
- */
164
- function createInterpolationFromStringOutputRange(config) {
165
- let outputRange = config.outputRange;
166
- invariant(outputRange.length >= 2, 'Bad output range');
167
- outputRange = outputRange.map(colorToRgba);
168
- checkPattern(outputRange);
169
-
170
- // ['rgba(0, 100, 200, 0)', 'rgba(50, 150, 250, 0.5)']
171
- // ->
172
- // [
173
- // [0, 50],
174
- // [100, 150],
175
- // [200, 250],
176
- // [0, 0.5],
177
- // ]
178
- /* $FlowFixMe(>=0.18.0): `outputRange[0].match()` can return `null`. Need to
179
- * guard against this possibility.
180
- */
181
- const outputRanges = outputRange[0].match(stringShapeRegex).map(() => []);
182
- outputRange.forEach(value => {
183
- /* $FlowFixMe(>=0.18.0): `value.match()` can return `null`. Need to guard
184
- * against this possibility.
185
- */
186
- value.match(stringShapeRegex).forEach((number, i) => {
187
- outputRanges[i].push(+number);
188
- });
189
- });
190
-
191
- /* $FlowFixMe(>=0.18.0): `outputRange[0].match()` can return `null`. Need to
192
- * guard against this possibility.
193
- */
194
- const interpolations = outputRange[0]
195
- .match(stringShapeRegex)
196
- .map((value, i) => {
197
- return createInterpolation({
198
- ...config,
199
- outputRange: outputRanges[i],
200
- });
201
- });
202
-
203
- // rgba requires that the r,g,b are integers.... so we want to round them, but we *dont* want to
204
- // round the opacity (4th column).
205
- const shouldRound = isRgbOrRgba(outputRange[0]);
206
-
207
- return input => {
208
- let i = 0;
209
- // 'rgba(0, 100, 200, 0)'
210
- // ->
211
- // 'rgba(${interpolations[0](input)}, ${interpolations[1](input)}, ...'
212
- return outputRange[0].replace(stringShapeRegex, () => {
213
- const val = +interpolations[i++](input);
214
- const rounded =
215
- shouldRound && i < 4 ? Math.round(val) : Math.round(val * 1000) / 1000;
216
- return String(rounded);
217
- });
218
- };
219
- }
220
-
221
- function isRgbOrRgba(range) {
222
- return typeof range === 'string' && range.startsWith('rgb');
223
- }
224
-
225
- function checkPattern(arr) {
226
- const pattern = arr[0].replace(stringShapeRegex, '');
227
- for (let i = 1; i < arr.length; ++i) {
228
- invariant(
229
- pattern === arr[i].replace(stringShapeRegex, ''),
230
- 'invalid pattern ' + arr[0] + ' and ' + arr[i]
231
- );
232
- }
233
- }
234
-
235
- function findRange(input, inputRange) {
236
- let i;
237
- for (i = 1; i < inputRange.length - 1; ++i) {
238
- if (inputRange[i] >= input) {
239
- break;
240
- }
241
- }
242
- return i - 1;
243
- }
244
-
245
- function checkValidInputRange(arr) {
246
- invariant(arr.length >= 2, 'inputRange must have at least 2 elements');
247
- for (let i = 1; i < arr.length; ++i) {
248
- invariant(
249
- arr[i] >= arr[i - 1],
250
- /* $FlowFixMe(>=0.13.0) - In the addition expression below this comment,
251
- * one or both of the operands may be something that doesn't cleanly
252
- * convert to a string, like undefined, null, and object, etc. If you really
253
- * mean this implicit string conversion, you can do something like
254
- * String(myThing)
255
- */
256
- 'inputRange must be monotonically increasing ' + arr
257
- );
258
- }
259
- }
260
-
261
- function checkInfiniteRange(name, arr) {
262
- invariant(arr.length >= 2, name + ' must have at least 2 elements');
263
- invariant(
264
- arr.length !== 2 || arr[0] !== -Infinity || arr[1] !== Infinity,
265
- /* $FlowFixMe(>=0.13.0) - In the addition expression below this comment,
266
- * one or both of the operands may be something that doesn't cleanly convert
267
- * to a string, like undefined, null, and object, etc. If you really mean
268
- * this implicit string conversion, you can do something like
269
- * String(myThing)
270
- */
271
- name + 'cannot be ]-infinity;+infinity[ ' + arr
272
- );
273
- }
274
-
275
- export default class AnimatedInterpolation extends AnimatedWithInput {
276
- // Export for testing.
277
- static __createInterpolation = createInterpolation;
278
-
279
- constructor(parent, config) {
280
- super([parent]);
281
- this._parent = parent;
282
- this._config = config;
283
- this._interpolation = createInterpolation(config);
284
- }
285
-
286
- __makeNative() {
287
- this._parent.__makeNative();
288
- super.__makeNative();
289
- }
290
-
291
- __onEvaluate() {
292
- const parentValue = val(this._parent);
293
- invariant(
294
- typeof parentValue === 'number',
295
- 'Cannot interpolate an input which is not a number.'
296
- );
297
- return this._interpolation(parentValue);
298
- }
299
-
300
- interpolate(config) {
301
- return new AnimatedInterpolation(this, config);
302
- }
303
-
304
- __transformDataType(range) {
305
- // Change the string array type to number array
306
- // So we can reuse the same logic in iOS and Android platform
307
- return range.map(function(value) {
308
- if (typeof value !== 'string') {
309
- return value;
310
- }
311
- if (/deg$/.test(value)) {
312
- const degrees = parseFloat(value) || 0;
313
- const radians = degrees * Math.PI / 180.0;
314
- return radians;
315
- } else {
316
- // Assume radians
317
- return parseFloat(value) || 0;
318
- }
319
- });
320
- }
321
-
322
- __getNativeConfig() {
323
- if (__DEV__) {
324
- NativeAnimatedHelper.validateInterpolation(this._config);
325
- }
326
-
327
- return {
328
- inputRange: this._config.inputRange,
329
- // Only the `outputRange` can contain strings so we don't need to transform `inputRange` here
330
- outputRange: this.__transformDataType(this._config.outputRange),
331
- extrapolateLeft:
332
- this._config.extrapolateLeft || this._config.extrapolate || 'extend',
333
- extrapolateRight:
334
- this._config.extrapolateRight || this._config.extrapolate || 'extend',
335
- type: 'interpolation',
336
- };
337
- }
338
- }
@@ -1,97 +0,0 @@
1
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
2
- import { evaluate } from '../CoreAnimated';
3
-
4
- import invariant from 'fbjs/lib/invariant';
5
-
6
- // Note(vjeux): this would be better as an interface but flow doesn't
7
- // support them yet
8
- export default class AnimatedNode {
9
- __attach() {}
10
- __detach() {
11
- if (this.__isNative && this.__nativeTag != null) {
12
- NativeAnimatedHelper.API.dropAnimatedNode(this.__nativeTag);
13
- this.__nativeTag = undefined;
14
- }
15
- }
16
- __getValue() {
17
- return evaluate(this);
18
- }
19
- __onEvaluate() {
20
- throw new Excaption('Missing implementation of onEvaluate');
21
- }
22
- __getProps() {
23
- return this.__getValue();
24
- }
25
-
26
- __getChildren() {
27
- return this.__children;
28
- }
29
-
30
- __addChild(child) {
31
- if (this.__children.length === 0) {
32
- this.__attach();
33
- }
34
- this.__children.push(child);
35
- if (this.__isNative) {
36
- // Only accept "native" animated nodes as children
37
- child.__makeNative();
38
- NativeAnimatedHelper.API.connectAnimatedNodes(
39
- this.__getNativeTag(),
40
- child.__getNativeTag()
41
- );
42
- }
43
- }
44
-
45
- __removeChild(child) {
46
- const index = this.__children.indexOf(child);
47
- if (index === -1) {
48
- console.warn("Trying to remove a child that doesn't exist");
49
- return;
50
- }
51
- if (this.__isNative && child.__isNative) {
52
- NativeAnimatedHelper.API.disconnectAnimatedNodes(
53
- this.__getNativeTag(),
54
- child.__getNativeTag()
55
- );
56
- }
57
- this.__children.splice(index, 1);
58
- if (this.__children.length === 0) {
59
- this.__detach();
60
- }
61
- }
62
-
63
- /* Methods and props used by native Animated impl */
64
- __lastLoopID = 0;
65
- __memoizedValue = null;
66
-
67
- __children = [];
68
- __makeNative() {
69
- if (!this.__isNative) {
70
- throw new Error('This node cannot be made a "native" animated node');
71
- }
72
- }
73
- __getNativeTag() {
74
- NativeAnimatedHelper.assertNativeAnimatedModule();
75
- invariant(
76
- this.__isNative,
77
- 'Attempt to get native tag from node not marked as "native"'
78
- );
79
- if (this.__nativeTag == null) {
80
- const nativeTag = NativeAnimatedHelper.generateNewNodeTag();
81
- NativeAnimatedHelper.API.createAnimatedNode(
82
- nativeTag,
83
- this.__getNativeConfig()
84
- );
85
- this.__nativeTag = nativeTag;
86
- }
87
- return this.__nativeTag;
88
- }
89
- __getNativeConfig() {
90
- throw new Error(
91
- 'This JS animated node type cannot be used as native animated node'
92
- );
93
- }
94
- toJSON() {
95
- return this.__getValue();
96
- }
97
- }
@@ -1,28 +0,0 @@
1
- import AnimatedWithInput from './AnimatedWithInput';
2
- import { val } from '../utils';
3
-
4
- export default class AnimatedOnChange extends AnimatedWithInput {
5
- _value;
6
- _what;
7
- _lastValue = null;
8
-
9
- constructor(value, what) {
10
- super([value]);
11
- this._value = value;
12
- this._what = what;
13
- this._lastValue = val(value);
14
- }
15
-
16
- update() {
17
- // side effects
18
- val(this);
19
- }
20
-
21
- __onEvaluate() {
22
- const newValue = val(this._value);
23
- if (newValue !== this._lastValue) {
24
- val(this._what);
25
- this._lastValue = newValue;
26
- }
27
- }
28
- }
@@ -1,17 +0,0 @@
1
- import AnimatedWithInput from './AnimatedWithInput';
2
- import { val } from '../utils';
3
-
4
- export default class AnimatedOp extends AnimatedWithInput {
5
- _inputNodes;
6
- _processor;
7
-
8
- constructor(inputNodes, processor) {
9
- super(inputNodes);
10
- this._inputNodes = inputNodes;
11
- this._processor = processor;
12
- }
13
-
14
- __onEvaluate() {
15
- return this._processor(this._inputNodes.map(node => val(node)));
16
- }
17
- }
@@ -1,154 +0,0 @@
1
- import { AnimatedEvent } from '../AnimatedEvent';
2
- import AnimatedNode from './AnimatedNode';
3
- import AnimatedStyle from './AnimatedStyle';
4
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
5
- import ReactNative from 'ReactNative';
6
-
7
- import invariant from 'fbjs/lib/invariant';
8
-
9
- export default class AnimatedProps extends AnimatedNode {
10
- constructor(props, callback) {
11
- super();
12
- if (props.style) {
13
- props = {
14
- ...props,
15
- style: new AnimatedStyle(props.style),
16
- };
17
- }
18
- this._props = props;
19
- this._callback = callback;
20
- this.__attach();
21
- }
22
-
23
- __getProps() {
24
- const props = {};
25
- for (const key in this._props) {
26
- const value = this._props[key];
27
- if (value instanceof AnimatedNode) {
28
- if (!value.__isNative || value instanceof AnimatedStyle) {
29
- // We cannot use value of natively driven nodes this way as the value we have access from
30
- // JS may not be up to date.
31
- props[key] = value.__getProps();
32
- }
33
- } else if (value instanceof AnimatedEvent) {
34
- props[key] = value.__getHandler();
35
- } else {
36
- props[key] = value;
37
- }
38
- }
39
- return props;
40
- }
41
-
42
- __onEvaluate() {
43
- const props = {};
44
- for (const key in this._props) {
45
- const value = this._props[key];
46
- if (value instanceof AnimatedNode) {
47
- props[key] = value.__getValue();
48
- }
49
- }
50
- return props;
51
- }
52
-
53
- __attach() {
54
- for (const key in this._props) {
55
- const value = this._props[key];
56
- if (value instanceof AnimatedNode) {
57
- value.__addChild(this);
58
- }
59
- }
60
- }
61
-
62
- __getParams() {
63
- const params = [];
64
- for (const key in this._props) {
65
- const value = this._props[key];
66
- if (value instanceof AnimatedNode) {
67
- params.push(value);
68
- }
69
- }
70
- return params;
71
- }
72
-
73
- __detach() {
74
- if (this.__isNative && this._animatedView) {
75
- this.__disconnectAnimatedView();
76
- }
77
- for (const key in this._props) {
78
- const value = this._props[key];
79
- if (value instanceof AnimatedNode) {
80
- value.__removeChild(this);
81
- }
82
- }
83
- super.__detach();
84
- }
85
-
86
- update() {
87
- this._callback();
88
- }
89
-
90
- __makeNative() {
91
- if (!this.__isNative) {
92
- this.__isNative = true;
93
- for (const key in this._props) {
94
- const value = this._props[key];
95
- if (value instanceof AnimatedNode) {
96
- value.__makeNative();
97
- }
98
- }
99
- if (this._animatedView) {
100
- this.__connectAnimatedView();
101
- }
102
- }
103
- }
104
-
105
- setNativeView(animatedView) {
106
- if (this._animatedView === animatedView) {
107
- return;
108
- }
109
- this._animatedView = animatedView;
110
- if (this.__isNative) {
111
- this.__connectAnimatedView();
112
- }
113
- }
114
-
115
- __connectAnimatedView() {
116
- invariant(this.__isNative, 'Expected node to be marked as "native"');
117
- const nativeViewTag = ReactNative.findNodeHandle(this._animatedView);
118
- invariant(
119
- nativeViewTag != null,
120
- 'Unable to locate attached view in the native tree'
121
- );
122
- NativeAnimatedHelper.API.connectAnimatedNodeToView(
123
- this.__getNativeTag(),
124
- nativeViewTag
125
- );
126
- }
127
-
128
- __disconnectAnimatedView() {
129
- invariant(this.__isNative, 'Expected node to be marked as "native"');
130
- const nativeViewTag = ReactNative.findNodeHandle(this._animatedView);
131
- invariant(
132
- nativeViewTag != null,
133
- 'Unable to locate attached view in the native tree'
134
- );
135
- NativeAnimatedHelper.API.disconnectAnimatedNodeFromView(
136
- this.__getNativeTag(),
137
- nativeViewTag
138
- );
139
- }
140
-
141
- __getNativeConfig() {
142
- const propsConfig = {};
143
- for (const propKey in this._props) {
144
- const value = this._props[propKey];
145
- if (value instanceof AnimatedNode) {
146
- propsConfig[propKey] = value.__getNativeTag();
147
- }
148
- }
149
- return {
150
- type: 'props',
151
- props: propsConfig,
152
- };
153
- }
154
- }
@@ -1,19 +0,0 @@
1
- import AnimatedWithInput from './AnimatedWithInput';
2
- import { val } from '../utils';
3
-
4
- export default class AnimatedSet extends AnimatedWithInput {
5
- _what;
6
- _value;
7
-
8
- constructor(what, value) {
9
- super([value]);
10
- this._what = what;
11
- this._value = value;
12
- }
13
-
14
- __onEvaluate() {
15
- const newValue = val(this._value);
16
- this._what._updateValue(newValue);
17
- return newValue;
18
- }
19
- }
@@ -1,21 +0,0 @@
1
- import AnimatedNode from './AnimatedNode';
2
- import AnimatedClock from './AnimatedClock';
3
- import invariant from 'fbjs/lib/invariant';
4
-
5
- export default class AnimatedStartClock extends AnimatedNode {
6
- _clockNode;
7
-
8
- constructor(clockNode) {
9
- super();
10
- invariant(
11
- clockNode instanceof AnimatedClock,
12
- 'Node is not of an AnimatedClock type'
13
- );
14
- this._clockNode = clockNode;
15
- }
16
-
17
- __onEvaluate() {
18
- this._clockNode.start();
19
- return 0;
20
- }
21
- }
@@ -1,21 +0,0 @@
1
- import AnimatedNode from './AnimatedNode';
2
- import AnimatedClock from './AnimatedClock';
3
- import invariant from 'fbjs/lib/invariant';
4
-
5
- export default class AnimatedStopClock extends AnimatedNode {
6
- _clockNode;
7
-
8
- constructor(clockNode) {
9
- super();
10
- invariant(
11
- clockNode instanceof AnimatedClock,
12
- 'Node is not of an AnimatedClock type'
13
- );
14
- this._clockNode = clockNode;
15
- }
16
-
17
- __onEvaluate() {
18
- this._clockNode.stop();
19
- return 0;
20
- }
21
- }