react-native-reanimated 3.0.2 → 3.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 (473) hide show
  1. package/Common/cpp/Fabric/FabricUtils.h +1 -1
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +38 -27
  3. package/Common/cpp/SharedItems/Shareables.h +22 -0
  4. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +2 -0
  5. package/Common/cpp/Tools/RuntimeDecorator.cpp +4 -1
  6. package/Common/cpp/Tools/RuntimeDecorator.h +2 -1
  7. package/Common/cpp/Tools/SingleInstanceChecker.h +14 -2
  8. package/RNReanimated.podspec +5 -2
  9. package/android/CMakeLists.txt +4 -0
  10. package/android/build.gradle +18 -10
  11. package/android/src/main/cpp/NativeProxy.cpp +316 -337
  12. package/android/src/main/cpp/NativeProxy.h +53 -11
  13. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +7 -12
  14. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +11 -8
  15. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +21 -14
  16. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +0 -3
  17. package/ios/Fabric/REAInitializerRCTFabricSurface.mm +1 -0
  18. package/ios/REANodesManager.h +1 -0
  19. package/ios/REANodesManager.mm +30 -4
  20. package/ios/keyboardObserver/REAKeyboardEventObserver.m +51 -130
  21. package/ios/native/NativeMethods.mm +1 -1
  22. package/ios/native/NativeProxy.mm +4 -1
  23. package/ios/native/REAIOSErrorHandler.mm +1 -1
  24. package/ios/native/REAIOSLogger.mm +1 -1
  25. package/ios/native/REAIOSScheduler.mm +1 -1
  26. package/ios/native/REAInitializer.mm +1 -1
  27. package/ios/native/REAMessageThread.mm +2 -2
  28. package/lib/commonjs/Animated.js +0 -8
  29. package/lib/commonjs/Animated.js.map +1 -1
  30. package/lib/commonjs/ConfigHelper.js +8 -19
  31. package/lib/commonjs/ConfigHelper.js.map +1 -1
  32. package/lib/commonjs/createAnimatedComponent.js +20 -158
  33. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  34. package/lib/commonjs/index.js +0 -9
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/index.web.js +0 -7
  37. package/lib/commonjs/index.web.js.map +1 -1
  38. package/lib/commonjs/reanimated2/Bezier.js +14 -34
  39. package/lib/commonjs/reanimated2/Bezier.js.map +1 -1
  40. package/lib/commonjs/reanimated2/Colors.js +60 -132
  41. package/lib/commonjs/reanimated2/Colors.js.map +1 -1
  42. package/lib/commonjs/reanimated2/Easing.js +81 -34
  43. package/lib/commonjs/reanimated2/Easing.js.map +1 -1
  44. package/lib/commonjs/reanimated2/NativeMethods.js +8 -20
  45. package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
  46. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +5 -31
  47. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  48. package/lib/commonjs/reanimated2/NativeReanimated/index.js +0 -7
  49. package/lib/commonjs/reanimated2/NativeReanimated/index.js.map +1 -1
  50. package/lib/commonjs/reanimated2/PlatformChecker.js +0 -6
  51. package/lib/commonjs/reanimated2/PlatformChecker.js.map +1 -1
  52. package/lib/commonjs/reanimated2/PropAdapters.js +10 -12
  53. package/lib/commonjs/reanimated2/PropAdapters.js.map +1 -1
  54. package/lib/commonjs/reanimated2/UpdateProps.js +3 -12
  55. package/lib/commonjs/reanimated2/UpdateProps.js.map +1 -1
  56. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +0 -10
  57. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  58. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -22
  59. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  60. package/lib/commonjs/reanimated2/animation/decay.js +7 -18
  61. package/lib/commonjs/reanimated2/animation/decay.js.map +1 -1
  62. package/lib/commonjs/reanimated2/animation/delay.js +0 -11
  63. package/lib/commonjs/reanimated2/animation/delay.js.map +1 -1
  64. package/lib/commonjs/reanimated2/animation/index.js +0 -8
  65. package/lib/commonjs/reanimated2/animation/index.js.map +1 -1
  66. package/lib/commonjs/reanimated2/animation/repeat.js +6 -22
  67. package/lib/commonjs/reanimated2/animation/repeat.js.map +1 -1
  68. package/lib/commonjs/reanimated2/animation/sequence.js +3 -20
  69. package/lib/commonjs/reanimated2/animation/sequence.js.map +1 -1
  70. package/lib/commonjs/reanimated2/animation/spring.js +11 -23
  71. package/lib/commonjs/reanimated2/animation/spring.js.map +1 -1
  72. package/lib/commonjs/reanimated2/animation/styleAnimation.js +3 -35
  73. package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
  74. package/lib/commonjs/reanimated2/animation/timing.js +0 -11
  75. package/lib/commonjs/reanimated2/animation/timing.js.map +1 -1
  76. package/lib/commonjs/reanimated2/animation/util.js +11 -41
  77. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  78. package/lib/commonjs/reanimated2/commonTypes.js +16 -23
  79. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  80. package/lib/commonjs/reanimated2/component/FlatList.js +0 -16
  81. package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
  82. package/lib/commonjs/reanimated2/component/Image.js +0 -4
  83. package/lib/commonjs/reanimated2/component/Image.js.map +1 -1
  84. package/lib/commonjs/reanimated2/component/ScrollView.js +0 -4
  85. package/lib/commonjs/reanimated2/component/ScrollView.js.map +1 -1
  86. package/lib/commonjs/reanimated2/component/Text.js +0 -4
  87. package/lib/commonjs/reanimated2/component/Text.js.map +1 -1
  88. package/lib/commonjs/reanimated2/component/View.js +0 -4
  89. package/lib/commonjs/reanimated2/component/View.js.map +1 -1
  90. package/lib/commonjs/reanimated2/core.js +6 -48
  91. package/lib/commonjs/reanimated2/core.js.map +1 -1
  92. package/lib/commonjs/reanimated2/errors.js +3 -14
  93. package/lib/commonjs/reanimated2/errors.js.map +1 -1
  94. package/lib/commonjs/reanimated2/fabricUtils.js +3 -5
  95. package/lib/commonjs/reanimated2/fabricUtils.js.map +1 -1
  96. package/lib/commonjs/reanimated2/fabricUtils.web.js +1 -3
  97. package/lib/commonjs/reanimated2/fabricUtils.web.js.map +1 -1
  98. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js +3 -12
  99. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  100. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +13 -17
  101. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  102. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  103. package/lib/commonjs/reanimated2/hook/Hooks.js +0 -5
  104. package/lib/commonjs/reanimated2/hook/Hooks.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/commonTypes.js.map +1 -1
  106. package/lib/commonjs/reanimated2/hook/index.js +0 -12
  107. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  108. package/lib/commonjs/reanimated2/hook/useAnimatedGestureHandler.js +4 -17
  109. package/lib/commonjs/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
  110. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +2 -9
  111. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  112. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +1 -11
  113. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  114. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +0 -12
  115. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  116. package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js +2 -9
  117. package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  118. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +8 -23
  119. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  120. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +13 -71
  121. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  122. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +4 -13
  123. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  124. package/lib/commonjs/reanimated2/hook/useFrameCallback.js +0 -5
  125. package/lib/commonjs/reanimated2/hook/useFrameCallback.js.map +1 -1
  126. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +0 -7
  127. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  128. package/lib/commonjs/reanimated2/hook/useSharedValue.js +2 -7
  129. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  130. package/lib/commonjs/reanimated2/hook/utils.js +8 -39
  131. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  132. package/lib/commonjs/reanimated2/index.js +0 -26
  133. package/lib/commonjs/reanimated2/index.js.map +1 -1
  134. package/lib/commonjs/reanimated2/initializers.js +21 -43
  135. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  136. package/lib/commonjs/reanimated2/interpolateColor.js +6 -43
  137. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  138. package/lib/commonjs/reanimated2/interpolation.js +14 -29
  139. package/lib/commonjs/reanimated2/interpolation.js.map +1 -1
  140. package/lib/commonjs/reanimated2/jestUtils.js +11 -44
  141. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  142. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +15 -39
  143. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  144. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +9 -28
  145. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  146. package/lib/commonjs/reanimated2/js-reanimated/MapperRegistry.js +7 -37
  147. package/lib/commonjs/reanimated2/js-reanimated/MapperRegistry.js.map +1 -1
  148. package/lib/commonjs/reanimated2/js-reanimated/MutableValue.js +5 -18
  149. package/lib/commonjs/reanimated2/js-reanimated/MutableValue.js.map +1 -1
  150. package/lib/commonjs/reanimated2/js-reanimated/global.js +2 -9
  151. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  152. package/lib/commonjs/reanimated2/js-reanimated/index.js +3 -14
  153. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +7 -26
  155. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +3 -49
  157. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
  158. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +7 -43
  159. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
  160. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +4 -5
  161. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  162. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +0 -4
  163. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  164. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +4 -23
  165. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  166. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +3 -74
  167. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  168. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Fade.js +3 -53
  169. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
  170. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Flip.js +3 -63
  171. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
  172. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +7 -26
  173. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  174. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +3 -13
  175. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
  176. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +3 -23
  177. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  178. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +3 -43
  179. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
  180. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +3 -43
  181. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  182. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +3 -23
  183. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
  184. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +3 -83
  185. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  186. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/index.js +0 -20
  187. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
  188. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +3 -22
  189. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
  190. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +5 -29
  191. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
  192. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +3 -9
  193. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
  194. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +5 -11
  195. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
  196. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +3 -8
  197. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
  198. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +3 -12
  199. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
  200. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/index.js +0 -12
  201. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
  202. package/lib/commonjs/reanimated2/layoutReanimation/index.js +0 -9
  203. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  204. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +3 -17
  205. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
  206. package/lib/commonjs/reanimated2/mappers.js +26 -32
  207. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  208. package/lib/commonjs/reanimated2/mock.js +5 -15
  209. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  210. package/lib/commonjs/reanimated2/mutables.js +2 -28
  211. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  212. package/lib/commonjs/reanimated2/platform-specific/RNRenderer.js +0 -2
  213. package/lib/commonjs/reanimated2/platform-specific/RNRenderer.js.map +1 -1
  214. package/lib/commonjs/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
  215. package/lib/commonjs/reanimated2/platform-specific/checkCppVersion.js +31 -0
  216. package/lib/commonjs/reanimated2/platform-specific/checkCppVersion.js.map +1 -0
  217. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +0 -2
  218. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -1
  219. package/lib/commonjs/reanimated2/platform-specific/jsVersion.js +14 -0
  220. package/lib/commonjs/reanimated2/platform-specific/jsVersion.js.map +1 -0
  221. package/lib/commonjs/reanimated2/pluginUtils.js +0 -1
  222. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -1
  223. package/lib/commonjs/reanimated2/shareables.js +92 -49
  224. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  225. package/lib/commonjs/reanimated2/threads.js +42 -46
  226. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  227. package/lib/commonjs/reanimated2/utils.js +0 -5
  228. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  229. package/lib/commonjs/reanimated2/valueSetter.js +6 -21
  230. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  231. package/lib/commonjs/setAndForwardRef.js +3 -3
  232. package/lib/commonjs/setAndForwardRef.js.map +1 -1
  233. package/lib/module/Animated.js.map +1 -1
  234. package/lib/module/ConfigHelper.js +9 -15
  235. package/lib/module/ConfigHelper.js.map +1 -1
  236. package/lib/module/createAnimatedComponent.js +20 -139
  237. package/lib/module/createAnimatedComponent.js.map +1 -1
  238. package/lib/module/index.js +0 -2
  239. package/lib/module/index.js.map +1 -1
  240. package/lib/module/index.web.js.map +1 -1
  241. package/lib/module/reanimated2/Bezier.js +14 -33
  242. package/lib/module/reanimated2/Bezier.js.map +1 -1
  243. package/lib/module/reanimated2/Colors.js +59 -109
  244. package/lib/module/reanimated2/Colors.js.map +1 -1
  245. package/lib/module/reanimated2/Easing.js +37 -33
  246. package/lib/module/reanimated2/Easing.js.map +1 -1
  247. package/lib/module/reanimated2/NativeMethods.js +8 -15
  248. package/lib/module/reanimated2/NativeMethods.js.map +1 -1
  249. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +5 -27
  250. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  251. package/lib/module/reanimated2/NativeReanimated/index.js +0 -2
  252. package/lib/module/reanimated2/NativeReanimated/index.js.map +1 -1
  253. package/lib/module/reanimated2/PlatformChecker.js.map +1 -1
  254. package/lib/module/reanimated2/PropAdapters.js +12 -10
  255. package/lib/module/reanimated2/PropAdapters.js.map +1 -1
  256. package/lib/module/reanimated2/UpdateProps.js +3 -5
  257. package/lib/module/reanimated2/UpdateProps.js.map +1 -1
  258. package/lib/module/reanimated2/ViewDescriptorsSet.js +0 -6
  259. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  260. package/lib/module/reanimated2/WorkletEventHandler.js +5 -18
  261. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  262. package/lib/module/reanimated2/animation/decay.js +7 -15
  263. package/lib/module/reanimated2/animation/decay.js.map +1 -1
  264. package/lib/module/reanimated2/animation/delay.js +0 -9
  265. package/lib/module/reanimated2/animation/delay.js.map +1 -1
  266. package/lib/module/reanimated2/animation/index.js.map +1 -1
  267. package/lib/module/reanimated2/animation/repeat.js +6 -20
  268. package/lib/module/reanimated2/animation/repeat.js.map +1 -1
  269. package/lib/module/reanimated2/animation/sequence.js +3 -18
  270. package/lib/module/reanimated2/animation/sequence.js.map +1 -1
  271. package/lib/module/reanimated2/animation/spring.js +11 -21
  272. package/lib/module/reanimated2/animation/spring.js.map +1 -1
  273. package/lib/module/reanimated2/animation/styleAnimation.js +7 -31
  274. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  275. package/lib/module/reanimated2/animation/timing.js +0 -8
  276. package/lib/module/reanimated2/animation/timing.js.map +1 -1
  277. package/lib/module/reanimated2/animation/util.js +10 -33
  278. package/lib/module/reanimated2/animation/util.js.map +1 -1
  279. package/lib/module/reanimated2/commonTypes.js +12 -19
  280. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  281. package/lib/module/reanimated2/component/FlatList.js +0 -4
  282. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  283. package/lib/module/reanimated2/component/Image.js.map +1 -1
  284. package/lib/module/reanimated2/component/ScrollView.js.map +1 -1
  285. package/lib/module/reanimated2/component/Text.js.map +1 -1
  286. package/lib/module/reanimated2/component/View.js.map +1 -1
  287. package/lib/module/reanimated2/core.js +6 -22
  288. package/lib/module/reanimated2/core.js.map +1 -1
  289. package/lib/module/reanimated2/errors.js +3 -13
  290. package/lib/module/reanimated2/errors.js.map +1 -1
  291. package/lib/module/reanimated2/fabricUtils.js +3 -3
  292. package/lib/module/reanimated2/fabricUtils.js.map +1 -1
  293. package/lib/module/reanimated2/fabricUtils.web.js +1 -1
  294. package/lib/module/reanimated2/fabricUtils.web.js.map +1 -1
  295. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +3 -8
  296. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  297. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +13 -15
  298. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  299. package/lib/module/reanimated2/globals.d.js.map +1 -1
  300. package/lib/module/reanimated2/hook/Hooks.js +3 -2
  301. package/lib/module/reanimated2/hook/Hooks.js.map +1 -1
  302. package/lib/module/reanimated2/hook/commonTypes.js.map +1 -1
  303. package/lib/module/reanimated2/hook/index.js.map +1 -1
  304. package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js +3 -14
  305. package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
  306. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +2 -5
  307. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  308. package/lib/module/reanimated2/hook/useAnimatedReaction.js +1 -7
  309. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  310. package/lib/module/reanimated2/hook/useAnimatedRef.js +0 -6
  311. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  312. package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js +2 -7
  313. package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  314. package/lib/module/reanimated2/hook/useAnimatedSensor.js +9 -20
  315. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  316. package/lib/module/reanimated2/hook/useAnimatedStyle.js +13 -59
  317. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  318. package/lib/module/reanimated2/hook/useDerivedValue.js +4 -8
  319. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  320. package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
  321. package/lib/module/reanimated2/hook/useScrollViewOffset.js +0 -1
  322. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  323. package/lib/module/reanimated2/hook/useSharedValue.js +2 -3
  324. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  325. package/lib/module/reanimated2/hook/utils.js +8 -21
  326. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  327. package/lib/module/reanimated2/index.js.map +1 -1
  328. package/lib/module/reanimated2/initializers.js +23 -37
  329. package/lib/module/reanimated2/initializers.js.map +1 -1
  330. package/lib/module/reanimated2/interpolateColor.js +5 -34
  331. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  332. package/lib/module/reanimated2/interpolation.js +13 -28
  333. package/lib/module/reanimated2/interpolation.js.map +1 -1
  334. package/lib/module/reanimated2/jestUtils.js +11 -35
  335. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  336. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +15 -35
  337. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  338. package/lib/module/reanimated2/js-reanimated/Mapper.js +9 -23
  339. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  340. package/lib/module/reanimated2/js-reanimated/MapperRegistry.js +7 -35
  341. package/lib/module/reanimated2/js-reanimated/MapperRegistry.js.map +1 -1
  342. package/lib/module/reanimated2/js-reanimated/MutableValue.js +5 -16
  343. package/lib/module/reanimated2/js-reanimated/MutableValue.js.map +1 -1
  344. package/lib/module/reanimated2/js-reanimated/global.js +2 -6
  345. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  346. package/lib/module/reanimated2/js-reanimated/index.js +3 -9
  347. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  348. package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +7 -23
  349. package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
  350. package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +3 -45
  351. package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
  352. package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +7 -39
  353. package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
  354. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +3 -3
  355. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  356. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  357. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +4 -19
  358. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  359. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +3 -52
  360. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  361. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js +3 -32
  362. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
  363. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js +3 -38
  364. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
  365. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +7 -16
  366. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  367. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +3 -8
  368. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
  369. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +3 -14
  370. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  371. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +3 -26
  372. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
  373. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +3 -26
  374. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  375. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +3 -14
  376. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
  377. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +3 -50
  378. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  379. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
  380. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +3 -17
  381. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
  382. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +5 -23
  383. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
  384. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +3 -5
  385. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
  386. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +5 -6
  387. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
  388. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +3 -5
  389. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
  390. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +3 -8
  391. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
  392. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
  393. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  394. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +3 -13
  395. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
  396. package/lib/module/reanimated2/mappers.js +26 -25
  397. package/lib/module/reanimated2/mappers.js.map +1 -1
  398. package/lib/module/reanimated2/mock.js +5 -15
  399. package/lib/module/reanimated2/mock.js.map +1 -1
  400. package/lib/module/reanimated2/mutables.js +2 -19
  401. package/lib/module/reanimated2/mutables.js.map +1 -1
  402. package/lib/module/reanimated2/platform-specific/RNRenderer.js.map +1 -1
  403. package/lib/module/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
  404. package/lib/module/reanimated2/platform-specific/checkCppVersion.js +24 -0
  405. package/lib/module/reanimated2/platform-specific/checkCppVersion.js.map +1 -0
  406. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +0 -1
  407. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -1
  408. package/lib/module/reanimated2/platform-specific/jsVersion.js +7 -0
  409. package/lib/module/reanimated2/platform-specific/jsVersion.js.map +1 -0
  410. package/lib/module/reanimated2/pluginUtils.js.map +1 -1
  411. package/lib/module/reanimated2/shareables.js +96 -44
  412. package/lib/module/reanimated2/shareables.js.map +1 -1
  413. package/lib/module/reanimated2/threads.js +39 -33
  414. package/lib/module/reanimated2/threads.js.map +1 -1
  415. package/lib/module/reanimated2/utils.js +0 -3
  416. package/lib/module/reanimated2/utils.js.map +1 -1
  417. package/lib/module/reanimated2/valueSetter.js +6 -19
  418. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  419. package/lib/module/setAndForwardRef.js +3 -2
  420. package/lib/module/setAndForwardRef.js.map +1 -1
  421. package/package.json +46 -40
  422. package/plugin/.eslintrc.js +7 -0
  423. package/plugin/README.md +241 -0
  424. package/plugin/build/plugin.js +714 -0
  425. package/plugin/build/plugin.js.map +7 -0
  426. package/plugin/index.js +1 -807
  427. package/plugin/package.json +23 -0
  428. package/plugin/src/buildWorkletString.ts +213 -0
  429. package/plugin/src/commonObjects.ts +60 -0
  430. package/plugin/src/injectVersion.ts +37 -0
  431. package/plugin/src/makeWorklet.ts +375 -0
  432. package/plugin/src/plugin.ts +49 -0
  433. package/plugin/src/processForCalleesWorklets.ts +106 -0
  434. package/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts +156 -0
  435. package/plugin/src/processIfWorkletFunction.ts +55 -0
  436. package/plugin/src/processIfWorkletNode.ts +44 -0
  437. package/plugin/src/processInlineStylesWarning.ts +129 -0
  438. package/plugin/src/processWorkletObjectMethod.ts +31 -0
  439. package/plugin/src/types.ts +15 -0
  440. package/plugin/src/utils.ts +6 -0
  441. package/plugin/tsconfig.json +15 -0
  442. package/plugin/yarn.lock +2193 -0
  443. package/react-native-reanimated.d.ts +1 -0
  444. package/scripts/reanimated_utils.rb +2 -2
  445. package/src/createAnimatedComponent.tsx +2 -3
  446. package/src/reanimated2/Easing.ts +19 -0
  447. package/src/reanimated2/NativeMethods.ts +9 -4
  448. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +2 -2
  449. package/src/reanimated2/UpdateProps.ts +2 -2
  450. package/src/reanimated2/animation/decay.ts +7 -1
  451. package/src/reanimated2/animation/styleAnimation.ts +5 -1
  452. package/src/reanimated2/core.ts +4 -4
  453. package/src/reanimated2/errors.ts +1 -0
  454. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +12 -4
  455. package/src/reanimated2/globals.d.ts +71 -112
  456. package/src/reanimated2/hook/commonTypes.ts +1 -1
  457. package/src/reanimated2/hook/useAnimatedReaction.ts +2 -2
  458. package/src/reanimated2/hook/useAnimatedSensor.ts +2 -2
  459. package/src/reanimated2/initializers.ts +11 -8
  460. package/src/reanimated2/jestUtils.ts +0 -1
  461. package/src/reanimated2/js-reanimated/JSReanimated.ts +5 -1
  462. package/src/reanimated2/js-reanimated/index.ts +1 -1
  463. package/src/reanimated2/mappers.ts +26 -4
  464. package/src/reanimated2/mock.ts +1 -0
  465. package/src/reanimated2/platform-specific/checkCppVersion.ts +29 -0
  466. package/src/reanimated2/platform-specific/jsVersion.ts +6 -0
  467. package/src/reanimated2/shareables.ts +107 -8
  468. package/src/reanimated2/threads.ts +36 -17
  469. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +0 -42
  470. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +0 -1
  471. package/lib/module/reanimated2/platform-specific/checkVersion.js +0 -35
  472. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +0 -1
  473. package/src/reanimated2/platform-specific/checkVersion.ts +0 -39
@@ -4,17 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.withSpring = withSpring;
7
-
8
7
  var _util = require("./util");
9
-
10
8
  function withSpring(toValue, userConfig, callback) {
11
9
  'worklet';
12
10
 
13
11
  return (0, _util.defineAnimation)(toValue, () => {
14
- 'worklet'; // TODO: figure out why we can't use spread or Object.assign here
12
+ 'worklet';
13
+
14
+ // TODO: figure out why we can't use spread or Object.assign here
15
15
  // when user config is "frozen object" we can't enumerate it (perhaps
16
16
  // something is wrong with the object prototype).
17
-
18
17
  const config = {
19
18
  damping: 10,
20
19
  mass: 1,
@@ -24,11 +23,9 @@ function withSpring(toValue, userConfig, callback) {
24
23
  restSpeedThreshold: 2,
25
24
  velocity: 0
26
25
  };
27
-
28
26
  if (userConfig) {
29
27
  Object.keys(userConfig).forEach(key => config[key] = userConfig[key]);
30
28
  }
31
-
32
29
  function spring(animation, now) {
33
30
  const {
34
31
  toValue,
@@ -44,25 +41,24 @@ function withSpring(toValue, userConfig, callback) {
44
41
  const v0 = -velocity;
45
42
  const x0 = toValue - current;
46
43
  const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
47
-
48
44
  const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)
49
-
50
45
  const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay
51
46
 
52
47
  const t = deltaTime / 1000;
53
48
  const sin1 = Math.sin(omega1 * t);
54
- const cos1 = Math.cos(omega1 * t); // under damped
49
+ const cos1 = Math.cos(omega1 * t);
55
50
 
51
+ // under damped
56
52
  const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
57
53
  const underDampedFrag1 = underDampedEnvelope * (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
58
- const underDampedPosition = toValue - underDampedFrag1; // This looks crazy -- it's actually just the derivative of the oscillation function
59
-
60
- const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1); // critically damped
54
+ const underDampedPosition = toValue - underDampedFrag1;
55
+ // This looks crazy -- it's actually just the derivative of the oscillation function
56
+ const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
61
57
 
58
+ // critically damped
62
59
  const criticallyDampedEnvelope = Math.exp(-omega0 * t);
63
60
  const criticallyDampedPosition = toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
64
61
  const criticallyDampedVelocity = criticallyDampedEnvelope * (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
65
-
66
62
  const isOvershooting = () => {
67
63
  if (config.overshootClamping && config.stiffness !== 0) {
68
64
  return current < toValue ? animation.current > toValue : animation.current < toValue;
@@ -70,10 +66,8 @@ function withSpring(toValue, userConfig, callback) {
70
66
  return false;
71
67
  }
72
68
  };
73
-
74
69
  const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;
75
70
  const isDisplacement = config.stiffness === 0 || Math.abs(toValue - current) < config.restDisplacementThreshold;
76
-
77
71
  if (zeta < 1) {
78
72
  animation.current = underDampedPosition;
79
73
  animation.velocity = underDampedVelocity;
@@ -81,24 +75,19 @@ function withSpring(toValue, userConfig, callback) {
81
75
  animation.current = criticallyDampedPosition;
82
76
  animation.velocity = criticallyDampedVelocity;
83
77
  }
84
-
85
78
  if (isOvershooting() || isVelocity && isDisplacement) {
86
79
  if (config.stiffness !== 0) {
87
80
  animation.velocity = 0;
88
81
  animation.current = toValue;
89
- } // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
90
-
91
-
82
+ }
83
+ // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
92
84
  animation.lastTimestamp = 0;
93
85
  return true;
94
86
  }
95
-
96
87
  return false;
97
88
  }
98
-
99
89
  function onStart(animation, value, now, previousAnimation) {
100
90
  animation.current = value;
101
-
102
91
  if (previousAnimation) {
103
92
  animation.velocity = previousAnimation.velocity || animation.velocity || 0;
104
93
  animation.lastTimestamp = previousAnimation.lastTimestamp || now;
@@ -106,7 +95,6 @@ function withSpring(toValue, userConfig, callback) {
106
95
  animation.lastTimestamp = now;
107
96
  }
108
97
  }
109
-
110
98
  return {
111
99
  onFrame: spring,
112
100
  onStart,
@@ -1 +1 @@
1
- {"version":3,"names":["withSpring","toValue","userConfig","callback","defineAnimation","config","damping","mass","stiffness","overshootClamping","restDisplacementThreshold","restSpeedThreshold","velocity","Object","keys","forEach","key","spring","animation","now","lastTimestamp","current","deltaTime","Math","min","c","m","k","v0","x0","zeta","sqrt","omega0","omega1","t","sin1","sin","cos1","cos","underDampedEnvelope","exp","underDampedFrag1","underDampedPosition","underDampedVelocity","criticallyDampedEnvelope","criticallyDampedPosition","criticallyDampedVelocity","isOvershooting","isVelocity","abs","isDisplacement","onStart","value","previousAnimation","onFrame"],"sources":["spring.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\n\ninterface SpringConfig {\n mass?: number;\n stiffness?: number;\n overshootClamping?: boolean;\n restDisplacementThreshold?: number;\n restSpeedThreshold?: number;\n velocity?: number;\n damping?: number;\n}\n\nexport interface SpringAnimation extends Animation<SpringAnimation> {\n current: AnimatableValue;\n toValue: AnimatableValue;\n velocity: number;\n lastTimestamp: Timestamp;\n}\n\nexport interface InnerSpringAnimation\n extends Omit<SpringAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withSpring(\n toValue: AnimatableValue,\n userConfig?: SpringConfig,\n callback?: AnimationCallback\n): Animation<SpringAnimation> {\n 'worklet';\n\n return defineAnimation<SpringAnimation>(toValue, () => {\n 'worklet';\n\n // TODO: figure out why we can't use spread or Object.assign here\n // when user config is \"frozen object\" we can't enumerate it (perhaps\n // something is wrong with the object prototype).\n const config: Required<SpringConfig> = {\n damping: 10,\n mass: 1,\n stiffness: 100,\n overshootClamping: false,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 2,\n velocity: 0,\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function spring(animation: InnerSpringAnimation, now: Timestamp): boolean {\n const { toValue, lastTimestamp, current, velocity } = animation;\n\n const deltaTime = Math.min(now - lastTimestamp, 64);\n animation.lastTimestamp = now;\n\n const c = config.damping;\n const m = config.mass;\n const k = config.stiffness;\n\n const v0 = -velocity;\n const x0 = toValue - current;\n\n const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio\n const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)\n const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay\n\n const t = deltaTime / 1000;\n\n const sin1 = Math.sin(omega1 * t);\n const cos1 = Math.cos(omega1 * t);\n\n // under damped\n const underDampedEnvelope = Math.exp(-zeta * omega0 * t);\n const underDampedFrag1 =\n underDampedEnvelope *\n (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);\n\n const underDampedPosition = toValue - underDampedFrag1;\n // This looks crazy -- it's actually just the derivative of the oscillation function\n const underDampedVelocity =\n zeta * omega0 * underDampedFrag1 -\n underDampedEnvelope *\n (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);\n\n // critically damped\n const criticallyDampedEnvelope = Math.exp(-omega0 * t);\n const criticallyDampedPosition =\n toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);\n\n const criticallyDampedVelocity =\n criticallyDampedEnvelope *\n (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);\n\n const isOvershooting = () => {\n if (config.overshootClamping && config.stiffness !== 0) {\n return current < toValue\n ? animation.current > toValue\n : animation.current < toValue;\n } else {\n return false;\n }\n };\n\n const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;\n const isDisplacement =\n config.stiffness === 0 ||\n Math.abs(toValue - current) < config.restDisplacementThreshold;\n\n if (zeta < 1) {\n animation.current = underDampedPosition;\n animation.velocity = underDampedVelocity;\n } else {\n animation.current = criticallyDampedPosition;\n animation.velocity = criticallyDampedVelocity;\n }\n\n if (isOvershooting() || (isVelocity && isDisplacement)) {\n if (config.stiffness !== 0) {\n animation.velocity = 0;\n animation.current = toValue;\n }\n // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one\n animation.lastTimestamp = 0;\n return true;\n }\n return false;\n }\n\n function onStart(\n animation: SpringAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: SpringAnimation\n ): void {\n animation.current = value;\n if (previousAnimation) {\n animation.velocity =\n previousAnimation.velocity || animation.velocity || 0;\n animation.lastTimestamp = previousAnimation.lastTimestamp || now;\n } else {\n animation.lastTimestamp = now;\n }\n }\n\n return {\n onFrame: spring,\n onStart,\n toValue,\n velocity: config.velocity || 0,\n current: toValue,\n callback,\n l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jC,GAHF,EAIEkC,iBAJF,EAKQ;MACNnC,SAAS,CAACG,OAAV,GAAoB+B,KAApB;;MACA,IAAIC,iBAAJ,EAAuB;QACrBnC,SAAS,CAACN,QAAV,GACEyC,iBAAiB,CAACzC,QAAlB,IAA8BM,SAAS,CAACN,QAAxC,IAAoD,CADtD;QAEAM,SAAS,CAACE,aAAV,GAA0BiC,iBAAiB,CAACjC,aAAlB,IAAmCD,GAA7D;MACD,CAJD,MAIO;QACLD,SAAS,CAACE,aAAV,GAA0BD,GAA1B;MACD;IACF;;IAED,OAAO;MACLmC,OAAO,EAAErC,MADJ;MAELkC,OAFK;MAGLlD,OAHK;MAILW,QAAQ,EAAEP,MAAM,CAACO,QAAP,IAAmB,CAJxB;MAKLS,OAAO,EAAEpB,OALJ;MAMLE,QANK;MAOLiB,aAAa,EAAE;IAPV,CAAP;EASD,CA9HM,CAAP;AA+HD"}
1
+ {"version":3,"names":["_util","require","withSpring","toValue","userConfig","callback","defineAnimation","config","damping","mass","stiffness","overshootClamping","restDisplacementThreshold","restSpeedThreshold","velocity","Object","keys","forEach","key","spring","animation","now","lastTimestamp","current","deltaTime","Math","min","c","m","k","v0","x0","zeta","sqrt","omega0","omega1","t","sin1","sin","cos1","cos","underDampedEnvelope","exp","underDampedFrag1","underDampedPosition","underDampedVelocity","criticallyDampedEnvelope","criticallyDampedPosition","criticallyDampedVelocity","isOvershooting","isVelocity","abs","isDisplacement","onStart","value","previousAnimation","onFrame"],"sources":["spring.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\n\ninterface SpringConfig {\n mass?: number;\n stiffness?: number;\n overshootClamping?: boolean;\n restDisplacementThreshold?: number;\n restSpeedThreshold?: number;\n velocity?: number;\n damping?: number;\n}\n\nexport interface SpringAnimation extends Animation<SpringAnimation> {\n current: AnimatableValue;\n toValue: AnimatableValue;\n velocity: number;\n lastTimestamp: Timestamp;\n}\n\nexport interface InnerSpringAnimation\n extends Omit<SpringAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withSpring(\n toValue: AnimatableValue,\n userConfig?: SpringConfig,\n callback?: AnimationCallback\n): Animation<SpringAnimation> {\n 'worklet';\n\n return defineAnimation<SpringAnimation>(toValue, () => {\n 'worklet';\n\n // TODO: figure out why we can't use spread or Object.assign here\n // when user config is \"frozen object\" we can't enumerate it (perhaps\n // something is wrong with the object prototype).\n const config: Required<SpringConfig> = {\n damping: 10,\n mass: 1,\n stiffness: 100,\n overshootClamping: false,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 2,\n velocity: 0,\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function spring(animation: InnerSpringAnimation, now: Timestamp): boolean {\n const { toValue, lastTimestamp, current, velocity } = animation;\n\n const deltaTime = Math.min(now - lastTimestamp, 64);\n animation.lastTimestamp = now;\n\n const c = config.damping;\n const m = config.mass;\n const k = config.stiffness;\n\n const v0 = -velocity;\n const x0 = toValue - current;\n\n const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio\n const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)\n const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay\n\n const t = deltaTime / 1000;\n\n const sin1 = Math.sin(omega1 * t);\n const cos1 = Math.cos(omega1 * t);\n\n // under damped\n const underDampedEnvelope = Math.exp(-zeta * omega0 * t);\n const underDampedFrag1 =\n underDampedEnvelope *\n (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);\n\n const underDampedPosition = toValue - underDampedFrag1;\n // This looks crazy -- it's actually just the derivative of the oscillation function\n const underDampedVelocity =\n zeta * omega0 * underDampedFrag1 -\n underDampedEnvelope *\n (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);\n\n // critically damped\n const criticallyDampedEnvelope = Math.exp(-omega0 * t);\n const criticallyDampedPosition =\n toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);\n\n const criticallyDampedVelocity =\n criticallyDampedEnvelope *\n (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);\n\n const isOvershooting = () => {\n if (config.overshootClamping && config.stiffness !== 0) {\n return current < toValue\n ? animation.current > toValue\n : animation.current < toValue;\n } else {\n return false;\n }\n };\n\n const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;\n const isDisplacement =\n config.stiffness === 0 ||\n Math.abs(toValue - current) < config.restDisplacementThreshold;\n\n if (zeta < 1) {\n animation.current = underDampedPosition;\n animation.velocity = underDampedVelocity;\n } else {\n animation.current = criticallyDampedPosition;\n animation.velocity = criticallyDampedVelocity;\n }\n\n if (isOvershooting() || (isVelocity && isDisplacement)) {\n if (config.stiffness !== 0) {\n animation.velocity = 0;\n animation.current = toValue;\n }\n // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one\n animation.lastTimestamp = 0;\n return true;\n }\n return false;\n }\n\n function onStart(\n animation: SpringAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: SpringAnimation\n ): void {\n animation.current = value;\n if (previousAnimation) {\n animation.velocity =\n previousAnimation.velocity || animation.velocity || 0;\n animation.lastTimestamp = previousAnimation.lastTimestamp || now;\n } else {\n animation.lastTimestamp = now;\n }\n }\n\n return {\n onFrame: spring,\n onStart,\n toValue,\n velocity: config.velocity || 0,\n current: toValue,\n callback,\n lastTimestamp: 0,\n } as SpringAnimation;\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AA+BO,SAASC,UAAUA,CACxBC,OAAwB,EACxBC,UAAyB,EACzBC,QAA4B,EACA;EAC5B,SAAS;;EAET,OAAO,IAAAC,qBAAe,EAAkBH,OAAO,EAAE,MAAM;IACrD,SAAS;;IAET;IACA;IACA;IACA,MAAMI,MAA8B,GAAG;MACrCC,OAAO,EAAE,EAAE;MACXC,IAAI,EAAE,C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O;MACLmC,OAAO,EAAErC,MAAM;MACfkC,OAAO;MACPlD,OAAO;MACPW,QAAQ,EAAEP,MAAM,CAACO,QAAQ,IAAI,CAAC;MAC9BS,OAAO,EAAEpB,OAAO;MAChBE,QAAQ;MACRiB,aAAa,EAAE;IACjB,CAAC;EACH,CAAC,CAAC;AACJ"}
@@ -6,15 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.resolvePath = resolvePath;
7
7
  exports.setPath = setPath;
8
8
  exports.withStyleAnimation = withStyleAnimation;
9
-
10
9
  var _util = require("./util");
11
-
12
10
  var _timing = require("./timing");
13
-
14
11
  var _UpdateProps = require("../UpdateProps");
15
-
16
12
  var _Colors = require("../Colors");
17
-
18
13
  // resolves path to value for nested objects
19
14
  // if path cannot be resolved returns undefined
20
15
  function resolvePath(obj, path) {
@@ -24,25 +19,23 @@ function resolvePath(obj, path) {
24
19
  return keys.reduce((acc, current) => {
25
20
  if (Array.isArray(acc) && typeof current === 'number') {
26
21
  return acc[current];
27
- } else if (typeof acc === 'object' && current in acc) {
22
+ } else if (acc !== null && typeof acc === 'object' && current in acc) {
28
23
  return acc[current];
29
24
  }
30
-
31
25
  return undefined;
32
26
  }, obj);
33
- } // set value at given path
27
+ }
34
28
 
29
+ // set value at given path
35
30
 
36
31
  function setPath(obj, path, value) {
37
32
  'worklet';
38
33
 
39
34
  const keys = Array.isArray(path) ? path : [path];
40
35
  let currObj = obj;
41
-
42
36
  for (let i = 0; i < keys.length - 1; i++) {
43
37
  // creates entry if there isn't one
44
38
  currObj = currObj;
45
-
46
39
  if (!(keys[i] in currObj)) {
47
40
  // if next key is a number create an array
48
41
  if (typeof keys[i + 1] === 'number') {
@@ -51,13 +44,10 @@ function setPath(obj, path, value) {
51
44
  currObj[keys[i]] = {};
52
45
  }
53
46
  }
54
-
55
47
  currObj = currObj[keys[i]];
56
48
  }
57
-
58
49
  currObj[keys[keys.length - 1]] = value;
59
50
  }
60
-
61
51
  function withStyleAnimation(styleAnimations) {
62
52
  'worklet';
63
53
 
@@ -70,10 +60,8 @@ function withStyleAnimation(styleAnimations) {
70
60
  value: animation.styleAnimations,
71
61
  path: []
72
62
  }];
73
-
74
63
  while (entriesToCheck.length > 0) {
75
64
  const currentEntry = entriesToCheck.pop();
76
-
77
65
  if (Array.isArray(currentEntry.value)) {
78
66
  for (let index = 0; index < currentEntry.value.length; index++) {
79
67
  entriesToCheck.push({
@@ -91,43 +79,33 @@ function withStyleAnimation(styleAnimations) {
91
79
  }
92
80
  } else {
93
81
  const currentStyleAnimation = currentEntry.value;
94
-
95
82
  if (currentStyleAnimation.finished) {
96
83
  continue;
97
84
  }
98
-
99
85
  const finished = currentStyleAnimation.onFrame(currentStyleAnimation, now);
100
-
101
86
  if (finished) {
102
87
  currentStyleAnimation.finished = true;
103
-
104
88
  if (currentStyleAnimation.callback) {
105
89
  currentStyleAnimation.callback(true);
106
90
  }
107
91
  } else {
108
92
  stillGoing = true;
109
93
  }
110
-
111
94
  if (_UpdateProps.ColorProperties.includes(currentEntry.path[0])) {
112
95
  currentStyleAnimation.current = (0, _Colors.processColor)(currentStyleAnimation.current);
113
96
  }
114
-
115
97
  setPath(animation.current, currentEntry.path, currentStyleAnimation.current);
116
98
  }
117
99
  }
118
-
119
100
  return !stillGoing;
120
101
  };
121
-
122
102
  const onStart = (animation, value, now, previousAnimation) => {
123
103
  const entriesToCheck = [{
124
104
  value: styleAnimations,
125
105
  path: []
126
106
  }];
127
-
128
107
  while (entriesToCheck.length > 0) {
129
108
  const currentEntry = entriesToCheck.pop();
130
-
131
109
  if (Array.isArray(currentEntry.value)) {
132
110
  for (let index = 0; index < currentEntry.value.length; index++) {
133
111
  entriesToCheck.push({
@@ -145,18 +123,14 @@ function withStyleAnimation(styleAnimations) {
145
123
  } else {
146
124
  const prevAnimation = resolvePath(previousAnimation === null || previousAnimation === void 0 ? void 0 : previousAnimation.styleAnimations, currentEntry.path);
147
125
  let prevVal = resolvePath(value, currentEntry.path);
148
-
149
126
  if (prevAnimation && !prevVal) {
150
127
  prevVal = prevAnimation.current;
151
128
  }
152
-
153
129
  if (prevVal === undefined) {
154
130
  console.warn(`Initial values for animation are missing for property ${currentEntry.path.join('.')}`);
155
131
  }
156
-
157
132
  setPath(animation.current, currentEntry.path, prevVal);
158
133
  let currentAnimation;
159
-
160
134
  if (typeof currentEntry.value !== 'object' || !currentEntry.value.onStart) {
161
135
  currentAnimation = (0, _timing.withTiming)(currentEntry.value, {
162
136
  duration: 0
@@ -165,19 +139,15 @@ function withStyleAnimation(styleAnimations) {
165
139
  } else {
166
140
  currentAnimation = currentEntry.value;
167
141
  }
168
-
169
142
  currentAnimation.onStart(currentAnimation, prevVal, now, prevAnimation);
170
143
  }
171
144
  }
172
145
  };
173
-
174
146
  const callback = finished => {
175
147
  if (!finished) {
176
148
  const animationsToCheck = [styleAnimations];
177
-
178
149
  while (animationsToCheck.length > 0) {
179
150
  const currentAnimation = animationsToCheck.pop();
180
-
181
151
  if (Array.isArray(currentAnimation)) {
182
152
  for (const element of currentAnimation) {
183
153
  animationsToCheck.push(element);
@@ -188,7 +158,6 @@ function withStyleAnimation(styleAnimations) {
188
158
  }
189
159
  } else {
190
160
  const currentStyleAnimation = currentAnimation;
191
-
192
161
  if (!currentStyleAnimation.finished && currentStyleAnimation.callback) {
193
162
  currentStyleAnimation.callback(false);
194
163
  }
@@ -196,7 +165,6 @@ function withStyleAnimation(styleAnimations) {
196
165
  }
197
166
  }
198
167
  };
199
-
200
168
  return {
201
169
  isHigherOrder: true,
202
170
  onFrame,
@@ -1 +1 @@
1
- {"version":3,"names":["resolvePath","obj","path","keys","Array","isArray","reduce","acc","current","undefined","setPath","value","currObj","i","length","withStyleAnimation","styleAnimations","defineAnimation","onFrame","animation","now","stillGoing","entriesToCheck","currentEntry","pop","index","push","concat","key","Object","currentStyleAnimation","finished","callback","ColorProperties","includes","processColor","onStart","previousAnimation","prevAnimation","prevVal","console","warn","join","currentAnimation","withTiming","duration","animationsToCheck","element","values","isHigherOrder"],"sources":["styleAnimation.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Timestamp,\n AnimatableValue,\n AnimationObject,\n Animation,\n AnimatedStyle,\n NestedObject,\n NestedObjectValues,\n} from '../commonTypes';\nimport { StyleLayoutAnimation } from './commonTypes';\nimport { withTiming } from './timing';\nimport { ColorProperties } from '../UpdateProps';\nimport { processColor } from '../Colors';\n\n// resolves path to value for nested objects\n// if path cannot be resolved returns undefined\nexport function resolvePath<T>(\n obj: NestedObject<T>,\n path: AnimatableValue[] | AnimatableValue\n): NestedObjectValues<T> | undefined {\n 'worklet';\n const keys: AnimatableValue[] = Array.isArray(path) ? path : [path];\n return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {\n if (Array.isArray(acc) && typeof current === 'number') {\n return acc[current];\n } else if (typeof acc === 'object' && (current as number | string) in acc) {\n return (acc as { [key: string]: NestedObjectValues<T> })[\n current as number | string\n ];\n }\n return undefined;\n }, obj);\n}\n\n// set value at given path\ntype Path = Array<string | number> | string | number;\nexport function setPath<T>(\n obj: NestedObject<T>,\n path: Path,\n value: NestedObjectValues<T>\n): void {\n 'worklet';\n const keys: Path = Array.isArray(path) ? path : [path];\n let currObj: NestedObjectValues<T> = obj;\n for (let i = 0; i < keys.length - 1; i++) {\n // creates entry if there isn't one\n currObj = currObj as { [key: string]: NestedObjectValues<T> };\n if (!(keys[i] in currObj)) {\n // if next key is a number create an array\n if (typeof keys[i + 1] === 'number') {\n currObj[keys[i]] = [];\n } else {\n currObj[keys[i]] = {};\n }\n }\n currObj = currObj[keys[i]];\n }\n\n (currObj as { [key: string]: NestedObjectValues<T> })[keys[keys.length - 1]] =\n value;\n}\n\ninterface NestedObjectEntry<T> {\n value: NestedObjectValues<T>;\n path: (string | number)[];\n}\n\nexport function withStyleAnimation(\n styleAnimations: AnimatedStyle\n): StyleLayoutAnimation {\n 'worklet';\n return defineAnimation<StyleLayoutAnimation>({}, () => {\n 'worklet';\n\n const onFrame = (\n animation: StyleLayoutAnimation,\n now: Timestamp\n ): boolean => {\n let stillGoing = false;\n const entriesToCheck: NestedObjectEntry<AnimationObject>[] = [\n { value: animation.styleAnimations, path: [] },\n ];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<AnimationObject> =\n entriesToCheck.pop() as NestedObjectEntry<AnimationObject>;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onFrame === undefined\n ) {\n // nested object\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentEntry.value as AnimationObject;\n if (currentStyleAnimation.finished) {\n continue;\n }\n const finished = currentStyleAnimation.onFrame(\n currentStyleAnimation,\n now\n );\n if (finished) {\n currentStyleAnimation.finished = true;\n if (currentStyleAnimation.callback) {\n currentStyleAnimation.callback(true);\n }\n } else {\n stillGoing = true;\n }\n\n if (ColorProperties.includes(currentEntry.path[0] as string)) {\n currentStyleAnimation.current = processColor(\n currentStyleAnimation.current\n ) as number;\n }\n\n setPath(\n animation.current,\n currentEntry.path,\n currentStyleAnimation.current\n );\n }\n }\n return !stillGoing;\n };\n\n const onStart = (\n animation: StyleLayoutAnimation,\n value: AnimatedStyle,\n now: Timestamp,\n previousAnimation: StyleLayoutAnimation\n ): void => {\n const entriesToCheck: NestedObjectEntry<\n AnimationObject | AnimatableValue\n >[] = [{ value: styleAnimations, path: [] }];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<\n AnimationObject | AnimatableValue\n > = entriesToCheck.pop() as NestedObjectEntry<\n AnimationObject | AnimatableValue\n >;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onStart === undefined\n ) {\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const prevAnimation = resolvePath(\n previousAnimation?.styleAnimations,\n currentEntry.path\n );\n let prevVal = resolvePath(value, currentEntry.path);\n if (prevAnimation && !prevVal) {\n prevVal = prevAnimation.current;\n }\n if (prevVal === undefined) {\n console.warn(\n `Initial values for animation are missing for property ${currentEntry.path.join(\n '.'\n )}`\n );\n }\n setPath(animation.current, currentEntry.path, prevVal);\n let currentAnimation: AnimationObject;\n if (\n typeof currentEntry.value !== 'object' ||\n !currentEntry.value.onStart\n ) {\n currentAnimation = withTiming(\n currentEntry.value as AnimatableValue,\n { duration: 0 }\n );\n setPath(\n animation.styleAnimations,\n currentEntry.path,\n currentAnimation\n );\n } else {\n currentAnimation = currentEntry.value as Animation<AnimationObject>;\n }\n currentAnimation.onStart(\n currentAnimation,\n prevVal,\n now,\n prevAnimation\n );\n }\n }\n };\n\n const callback = (finished: boolean): void => {\n if (!finished) {\n const animationsToCheck: NestedObjectValues<AnimationObject>[] = [\n styleAnimations,\n ];\n while (animationsToCheck.length > 0) {\n const currentAnimation: NestedObjectValues<AnimationObject> =\n animationsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentAnimation)) {\n for (const element of currentAnimation) {\n animationsToCheck.push(element);\n }\n } else if (\n typeof currentAnimation === 'object' &&\n currentAnimation.onStart === undefined\n ) {\n for (const value of Object.values(currentAnimation)) {\n animationsToCheck.push(value);\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentAnimation as AnimationObject;\n if (\n !currentStyleAnimation.finished &&\n currentStyleAnimation.callback\n ) {\n currentStyleAnimation.callback(false);\n }\n }\n }\n }\n };\n\n return {\n isHigherOrder: true,\n onFrame,\n onStart,\n current: {},\n styleAnimations,\n callback,\n } as StyleLayoutA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;YACD;UACF,CAPM,MAOA;YACL,MAAMmB,qBAAsC,GAC1Ca,gBADF;;YAEA,IACE,CAACb,qBAAqB,CAACC,QAAvB,IACAD,qBAAqB,CAACE,QAFxB,EAGE;cACAF,qBAAqB,CAACE,QAAtB,CAA+B,KAA/B;YACD;UACF;QACF;MACF;IACF,CA/BD;;IAiCA,OAAO;MACLiB,aAAa,EAAE,IADV;MAEL/B,OAFK;MAGLkB,OAHK;MAIL5B,OAAO,EAAE,EAJJ;MAKLQ,eALK;MAMLgB;IANK,CAAP;EAQD,CAxLM,CAAP;AAyLD"}
1
+ {"version":3,"names":["_util","require","_timing","_UpdateProps","_Colors","resolvePath","obj","path","keys","Array","isArray","reduce","acc","current","undefined","setPath","value","currObj","i","length","withStyleAnimation","styleAnimations","defineAnimation","onFrame","animation","now","stillGoing","entriesToCheck","currentEntry","pop","index","push","concat","key","Object","currentStyleAnimation","finished","callback","ColorProperties","includes","processColor","onStart","previousAnimation","prevAnimation","prevVal","console","warn","join","currentAnimation","withTiming","duration","animationsToCheck","element","values","isHigherOrder"],"sources":["styleAnimation.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Timestamp,\n AnimatableValue,\n AnimationObject,\n Animation,\n AnimatedStyle,\n NestedObject,\n NestedObjectValues,\n} from '../commonTypes';\nimport { StyleLayoutAnimation } from './commonTypes';\nimport { withTiming } from './timing';\nimport { ColorProperties } from '../UpdateProps';\nimport { processColor } from '../Colors';\n\n// resolves path to value for nested objects\n// if path cannot be resolved returns undefined\nexport function resolvePath<T>(\n obj: NestedObject<T>,\n path: AnimatableValue[] | AnimatableValue\n): NestedObjectValues<T> | undefined {\n 'worklet';\n const keys: AnimatableValue[] = Array.isArray(path) ? path : [path];\n return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {\n if (Array.isArray(acc) && typeof current === 'number') {\n return acc[current];\n } else if (\n acc !== null &&\n typeof acc === 'object' &&\n (current as number | string) in acc\n ) {\n return (acc as { [key: string]: NestedObjectValues<T> })[\n current as number | string\n ];\n }\n return undefined;\n }, obj);\n}\n\n// set value at given path\ntype Path = Array<string | number> | string | number;\nexport function setPath<T>(\n obj: NestedObject<T>,\n path: Path,\n value: NestedObjectValues<T>\n): void {\n 'worklet';\n const keys: Path = Array.isArray(path) ? path : [path];\n let currObj: NestedObjectValues<T> = obj;\n for (let i = 0; i < keys.length - 1; i++) {\n // creates entry if there isn't one\n currObj = currObj as { [key: string]: NestedObjectValues<T> };\n if (!(keys[i] in currObj)) {\n // if next key is a number create an array\n if (typeof keys[i + 1] === 'number') {\n currObj[keys[i]] = [];\n } else {\n currObj[keys[i]] = {};\n }\n }\n currObj = currObj[keys[i]];\n }\n\n (currObj as { [key: string]: NestedObjectValues<T> })[keys[keys.length - 1]] =\n value;\n}\n\ninterface NestedObjectEntry<T> {\n value: NestedObjectValues<T>;\n path: (string | number)[];\n}\n\nexport function withStyleAnimation(\n styleAnimations: AnimatedStyle\n): StyleLayoutAnimation {\n 'worklet';\n return defineAnimation<StyleLayoutAnimation>({}, () => {\n 'worklet';\n\n const onFrame = (\n animation: StyleLayoutAnimation,\n now: Timestamp\n ): boolean => {\n let stillGoing = false;\n const entriesToCheck: NestedObjectEntry<AnimationObject>[] = [\n { value: animation.styleAnimations, path: [] },\n ];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<AnimationObject> =\n entriesToCheck.pop() as NestedObjectEntry<AnimationObject>;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onFrame === undefined\n ) {\n // nested object\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentEntry.value as AnimationObject;\n if (currentStyleAnimation.finished) {\n continue;\n }\n const finished = currentStyleAnimation.onFrame(\n currentStyleAnimation,\n now\n );\n if (finished) {\n currentStyleAnimation.finished = true;\n if (currentStyleAnimation.callback) {\n currentStyleAnimation.callback(true);\n }\n } else {\n stillGoing = true;\n }\n\n if (ColorProperties.includes(currentEntry.path[0] as string)) {\n currentStyleAnimation.current = processColor(\n currentStyleAnimation.current\n ) as number;\n }\n\n setPath(\n animation.current,\n currentEntry.path,\n currentStyleAnimation.current\n );\n }\n }\n return !stillGoing;\n };\n\n const onStart = (\n animation: StyleLayoutAnimation,\n value: AnimatedStyle,\n now: Timestamp,\n previousAnimation: StyleLayoutAnimation\n ): void => {\n const entriesToCheck: NestedObjectEntry<\n AnimationObject | AnimatableValue\n >[] = [{ value: styleAnimations, path: [] }];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<\n AnimationObject | AnimatableValue\n > = entriesToCheck.pop() as NestedObjectEntry<\n AnimationObject | AnimatableValue\n >;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onStart === undefined\n ) {\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const prevAnimation = resolvePath(\n previousAnimation?.styleAnimations,\n currentEntry.path\n );\n let prevVal = resolvePath(value, currentEntry.path);\n if (prevAnimation && !prevVal) {\n prevVal = prevAnimation.current;\n }\n if (prevVal === undefined) {\n console.warn(\n `Initial values for animation are missing for property ${currentEntry.path.join(\n '.'\n )}`\n );\n }\n setPath(animation.current, currentEntry.path, prevVal);\n let currentAnimation: AnimationObject;\n if (\n typeof currentEntry.value !== 'object' ||\n !currentEntry.value.onStart\n ) {\n currentAnimation = withTiming(\n currentEntry.value as AnimatableValue,\n { duration: 0 }\n );\n setPath(\n animation.styleAnimations,\n currentEntry.path,\n currentAnimation\n );\n } else {\n currentAnimation = currentEntry.value as Animation<AnimationObject>;\n }\n currentAnimation.onStart(\n currentAnimation,\n prevVal,\n now,\n prevAnimation\n );\n }\n }\n };\n\n const callback = (finished: boolean): void => {\n if (!finished) {\n const animationsToCheck: NestedObjectValues<AnimationObject>[] = [\n styleAnimations,\n ];\n while (animationsToCheck.length > 0) {\n const currentAnimation: NestedObjectValues<AnimationObject> =\n animationsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentAnimation)) {\n for (const element of currentAnimation) {\n animationsToCheck.push(element);\n }\n } else if (\n typeof currentAnimation === 'object' &&\n currentAnimation.onStart === undefined\n ) {\n for (const value of Object.values(currentAnimation)) {\n animationsToCheck.push(value);\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentAnimation as AnimationObject;\n if (\n !currentStyleAnimation.finished &&\n currentStyleAnimation.callback\n ) {\n currentStyleAnimation.callback(false);\n }\n }\n }\n }\n };\n\n return {\n isHigherOrder: true,\n onFrame,\n onStart,\n current: {},\n styleAnimations,\n callback,\n } as StyleLayoutAnimation;\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAWA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA;AACA;AACO,SAASI,WAAWA,CACzBC,GAAoB,EACpBC,IAAyC,EACN;EACnC,SAAS;;EACT,MAAMC,IAAuB,GAAGC,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,GAAGA,IAAI,GAAG,CAACA,IAAI,CAAC;EACnE,OAAOC,IAAI,CAACG,MAAM,CAAoC,CAACC,GAAG,EAAEC,OAAO,KAAK;IACtE,IAAIJ,KAAK,CAACC,OAAO,CAACE,GAAG,CAAC,IAAI,OAAOC,OAAO,KAAK,QAAQ,EAAE;MACrD,OAAOD,GAAG,CAACC,OAAO,CAAC;IACrB,CAAC,MAAM,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AgC,gBAAgB,CAACP,OAAO,CACtBO,gBAAgB,EAChBJ,OAAO,EACPnB,GAAG,EACHkB,aAAa,CACd;QACH;MACF;IACF,CAAC;IAED,MAAMN,QAAQ,GAAID,QAAiB,IAAW;MAC5C,IAAI,CAACA,QAAQ,EAAE;QACb,MAAMe,iBAAwD,GAAG,CAC/D9B,eAAe,CAChB;QACD,OAAO8B,iBAAiB,CAAChC,MAAM,GAAG,CAAC,EAAE;UACnC,MAAM6B,gBAAqD,GACzDG,iBAAiB,CAACtB,GAAG,EAAyC;UAChE,IAAIpB,KAAK,CAACC,OAAO,CAACsC,gBAAgB,CAAC,EAAE;YACnC,KAAK,MAAMI,OAAO,IAAIJ,gBAAgB,EAAE;cACtCG,iBAAiB,CAACpB,IAAI,CAACqB,OAAO,CAAC;YACjC;UACF,CAAC,MAAM,IACL,OAAOJ,gBAAgB,KAAK,QAAQ,IACpCA,gBAAgB,CAACP,OAAO,KAAK3B,SAAS,EACtC;YACA,KAAK,MAAME,KAAK,IAAIkB,MAAM,CAACmB,MAAM,CAACL,gBAAgB,CAAC,EAAE;cACnDG,iBAAiB,CAACpB,IAAI,CAACf,KAAK,CAAC;YAC/B;UACF,CAAC,MAAM;YACL,MAAMmB,qBAAsC,GAC1Ca,gBAAmC;YACrC,IACE,CAACb,qBAAqB,CAACC,QAAQ,IAC/BD,qBAAqB,CAACE,QAAQ,EAC9B;cACAF,qBAAqB,CAACE,QAAQ,CAAC,KAAK,CAAC;YACvC;UACF;QACF;MACF;IACF,CAAC;IAED,OAAO;MACLiB,aAAa,EAAE,IAAI;MACnB/B,OAAO;MACPkB,OAAO;MACP5B,OAAO,EAAE,CAAC,CAAC;MACXQ,eAAe;MACfgB;IACF,CAAC;EACH,CAAC,CAAC;AACJ"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.withTiming = withTiming;
7
-
8
7
  var _Easing = require("../Easing");
9
-
10
8
  var _util = require("./util");
11
-
12
9
  function withTiming(toValue, userConfig, callback) {
13
10
  'worklet';
14
11
 
@@ -19,11 +16,9 @@ function withTiming(toValue, userConfig, callback) {
19
16
  duration: 300,
20
17
  easing: _Easing.Easing.inOut(_Easing.Easing.quad)
21
18
  };
22
-
23
19
  if (userConfig) {
24
20
  Object.keys(userConfig).forEach(key => config[key] = userConfig[key]);
25
21
  }
26
-
27
22
  function timing(animation, now) {
28
23
  const {
29
24
  toValue,
@@ -31,19 +26,16 @@ function withTiming(toValue, userConfig, callback) {
31
26
  startValue
32
27
  } = animation;
33
28
  const runtime = now - startTime;
34
-
35
29
  if (runtime >= config.duration) {
36
30
  // reset startTime to avoid reusing finished animation config in `start` method
37
31
  animation.startTime = 0;
38
32
  animation.current = toValue;
39
33
  return true;
40
34
  }
41
-
42
35
  const progress = animation.easing(runtime / config.duration);
43
36
  animation.current = startValue + (toValue - startValue) * progress;
44
37
  return false;
45
38
  }
46
-
47
39
  function onStart(animation, value, now, previousAnimation) {
48
40
  if (previousAnimation && previousAnimation.type === 'timing' && previousAnimation.toValue === toValue && previousAnimation.startTime) {
49
41
  // to maintain continuity of timing animations we check if we are starting
@@ -55,16 +47,13 @@ function withTiming(toValue, userConfig, callback) {
55
47
  animation.startTime = now;
56
48
  animation.startValue = value;
57
49
  }
58
-
59
50
  animation.current = value;
60
-
61
51
  if (typeof config.easing === 'object') {
62
52
  animation.easing = config.easing.factory();
63
53
  } else {
64
54
  animation.easing = config.easing;
65
55
  }
66
56
  }
67
-
68
57
  return {
69
58
  type: 'timing',
70
59
  onFrame: timing,
@@ -1 +1 @@
1
- {"version":3,"names":["withTiming","toValue","userConfig","callback","defineAnimation","config","duration","easing","Easing","inOut","quad","Object","keys","forEach","key","timing","animation","now","startTime","startValue","runtime","current","progress","onStart","value","previousAnimation","type","factory","onFrame"],"sources":["timing.ts"],"sourcesContent":["import { Easing, EasingFn, EasingFactoryFn } from '../Easing';\nimport { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n Timestamp,\n AnimatableValue,\n} from '../commonTypes';\n\ninterface TimingConfig {\n duration?: number;\n easing?: EasingFn | EasingFactoryFn;\n}\n\nexport interface TimingAnimation extends Animation<TimingAnimation> {\n type: string;\n easing: EasingFn;\n startValue: AnimatableValue;\n startTime: Timestamp;\n progress: number;\n toValue: AnimatableValue;\n current: AnimatableValue;\n}\n\nexport interface InnerTimingAnimation\n extends Omit<TimingAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withTiming(\n toValue: AnimatableValue,\n userConfig?: TimingConfig,\n callback?: AnimationCallback\n): Animation<TimingAnimation> {\n 'worklet';\n\n return defineAnimation<TimingAnimation>(toValue, () => {\n 'worklet';\n const config: Required<TimingConfig> = {\n duration: 300,\n easing: Easing.inOut(Easing.quad),\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function timing(animation: InnerTimingAnimation, now: Timestamp): boolean {\n const { toValue, startTime, startValue } = animation;\n const runtime = now - startTime;\n\n if (runtime >= config.duration) {\n // reset startTime to avoid reusing finished animation config in `start` method\n animation.startTime = 0;\n animation.current = toValue;\n return true;\n }\n const progress = animation.easing(runtime / config.duration);\n animation.current =\n (startValue as number) + (toValue - (startValue as number)) * progress;\n return false;\n }\n\n function onStart(\n animation: TimingAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: Animation<TimingAnimation>\n ): void {\n if (\n previousAnimation &&\n (previousAnimation as TimingAnimation).type === 'timing' &&\n (previousAnimation as TimingAnimation).toValue === toValue &&\n (previousAnimation as TimingAnimation).startTime\n ) {\n // to maintain continuity of timing animations we check if we are starting\n // new timing over the old one with the same parameters. If so, we want\n // to copy animation timeline properties\n animation.startTime = (previousAnimation as TimingAnimation).startTime;\n animation.startValue = (\n previousAnimation as TimingAnimation\n ).startValue;\n } else {\n animation.startTime = now;\n animation.startValue = value;\n }\n animation.current = value;\n if (typeof config.easing === 'object') {\n animation.easing = config.easing.factory();\n } else {\n animation.easing = config.easing;\n }\n }\n\n return {\n type: 'timing',\n onFrame: timing,\n onStart: onStart as (animation: TimingAnimation, now: number) => boolean,\n progress: 0,\n toValue,\n startValue: 0,\n startTime: 0,\n easing: () => 0,\n current: toValue,\n callback,\n } as TimingAnimation;\n });\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AA6BO,SAASA,UAAT,CACLC,OADK,EAELC,UAFK,EAGLC,QAHK,EAIuB;EAC5B;;EAEA,OAAO,IAAAC,qBAAA,EAAiCH,OAAjC,EAA0C,MAAM;IACrD;;IACA,MAAMI,MAA8B,GAAG;MACrCC,QAAQ,EAAE,GAD2B;MAErCC,MAAM,EAAEC,cAAA,CAAOC,KAAP,CAAaD,cAAA,CAAOE,IAApB;IAF6B,CAAvC;;IAIA,IAAIR,UAAJ,EAAgB;MACdS,MAAM,CAACC,IAAP,CAAYV,UAAZ,EAAwBW,OAAxB,CACGC,GAAD,IACIT,MAAD,CAAgBS,GAAhB,IAAuBZ,UAAU,CAACY,GAAD,CAFtC;IAID;;IAED,SAASC,MAAT,CAAgBC,SAAhB,EAAiDC,GAAjD,EAA0E;MACxE,MAAM;QAAEhB,OAAF;QAAWiB,SAAX;QAAsBC;MAAtB,IAAqCH,SAA3C;MACA,MAAMI,OAAO,GAAGH,GAAG,GAAGC,SAAtB;;MAEA,IAAIE,OAAO,IAAIf,MAAM,CAACC,QAAtB,EAAgC;QAC9B;QACAU,SAAS,CAACE,SAAV,GAAsB,CAAtB;QACAF,SAAS,CAACK,OAAV,GAAoBpB,OAApB;QACA,OAAO,IAAP;MACD;;MACD,MAAMqB,QAAQ,GAAGN,SAAS,CAACT,MAAV,CAAiBa,OAAO,GAAGf,MAAM,CAACC,QAAlC,CAAjB;MACAU,SAAS,CAACK,OAAV,GACGF,UAAD,GAAyB,CAAClB,OAAO,GAAIkB,UAAZ,IAAqCG,QADhE;MAEA,OAAO,KAAP;IACD;;IAED,SAASC,OAAT,CACEP,SADF,EAEEQ,KAFF,EAGEP,GAHF,EAIEQ,iBAJF,EAKQ;MACN,IACEA,iBAAiB,IAChBA,iBAAD,CAAuCC,IAAvC,KAAgD,QADhD,IAECD,iBAAD,CAAuCxB,OAAvC,KAAmDA,OAFnD,IAGCwB,iBAAD,CAAuCP,SAJzC,EAKE;QACA;QACA;QACA;QACAF,SAAS,CAACE,SAAV,GAAuBO,iBAAD,CAAuCP,SAA7D;QACAF,SAAS,CAACG,UAAV,GACEM,iBADqB,CAErBN,UAFF;MAGD,CAbD,MAaO;QACLH,SAAS,CAACE,SAAV,GAAsBD,GAAtB;QACAD,SAAS,CAACG,UAAV,GAAuBK,KAAvB;MACD;;MACDR,SAAS,CAACK,OAAV,GAAoBG,KAApB;;MACA,IAAI,OAAOnB,MAAM,CAACE,MAAd,KAAyB,QAA7B,EAAuC;QACrCS,SAAS,CAACT,MAAV,GAAmBF,MAAM,CAACE,MAAP,CAAcoB,OAAd,EAAnB;MACD,CAFD,MAEO;QACLX,SAAS,CAACT,MAAV,GAAmBF,MAAM,CAACE,MAA1B;MACD;IACF;;IAED,OAAO;MACLmB,IAAI,EAAE,QADD;MAELE,OAAO,EAAEb,MAFJ;MAGLQ,OAAO,EAAEA,OAHJ;MAILD,QAAQ,EAAE,CAJL;MAKLrB,OALK;MAMLkB,UAAU,EAAE,CANP;MAOLD,SAAS,EAAE,CAPN;MAQLX,MAAM,EAAE,MAAM,CART;MASLc,OAAO,EAAEpB,OATJ;MAULE;IAVK,CAAP;EAYD,CAxEM,CAAP;AAyED"}
1
+ {"version":3,"names":["_Easing","require","_util","withTiming","toValue","userConfig","callback","defineAnimation","config","duration","easing","Easing","inOut","quad","Object","keys","forEach","key","timing","animation","now","startTime","startValue","runtime","current","progress","onStart","value","previousAnimation","type","factory","onFrame"],"sources":["timing.ts"],"sourcesContent":["import { Easing, EasingFn, EasingFactoryFn } from '../Easing';\nimport { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n Timestamp,\n AnimatableValue,\n} from '../commonTypes';\n\ninterface TimingConfig {\n duration?: number;\n easing?: EasingFn | EasingFactoryFn;\n}\n\nexport interface TimingAnimation extends Animation<TimingAnimation> {\n type: string;\n easing: EasingFn;\n startValue: AnimatableValue;\n startTime: Timestamp;\n progress: number;\n toValue: AnimatableValue;\n current: AnimatableValue;\n}\n\nexport interface InnerTimingAnimation\n extends Omit<TimingAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withTiming(\n toValue: AnimatableValue,\n userConfig?: TimingConfig,\n callback?: AnimationCallback\n): Animation<TimingAnimation> {\n 'worklet';\n\n return defineAnimation<TimingAnimation>(toValue, () => {\n 'worklet';\n const config: Required<TimingConfig> = {\n duration: 300,\n easing: Easing.inOut(Easing.quad),\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function timing(animation: InnerTimingAnimation, now: Timestamp): boolean {\n const { toValue, startTime, startValue } = animation;\n const runtime = now - startTime;\n\n if (runtime >= config.duration) {\n // reset startTime to avoid reusing finished animation config in `start` method\n animation.startTime = 0;\n animation.current = toValue;\n return true;\n }\n const progress = animation.easing(runtime / config.duration);\n animation.current =\n (startValue as number) + (toValue - (startValue as number)) * progress;\n return false;\n }\n\n function onStart(\n animation: TimingAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: Animation<TimingAnimation>\n ): void {\n if (\n previousAnimation &&\n (previousAnimation as TimingAnimation).type === 'timing' &&\n (previousAnimation as TimingAnimation).toValue === toValue &&\n (previousAnimation as TimingAnimation).startTime\n ) {\n // to maintain continuity of timing animations we check if we are starting\n // new timing over the old one with the same parameters. If so, we want\n // to copy animation timeline properties\n animation.startTime = (previousAnimation as TimingAnimation).startTime;\n animation.startValue = (\n previousAnimation as TimingAnimation\n ).startValue;\n } else {\n animation.startTime = now;\n animation.startValue = value;\n }\n animation.current = value;\n if (typeof config.easing === 'object') {\n animation.easing = config.easing.factory();\n } else {\n animation.easing = config.easing;\n }\n }\n\n return {\n type: 'timing',\n onFrame: timing,\n onStart: onStart as (animation: TimingAnimation, now: number) => boolean,\n progress: 0,\n toValue,\n startValue: 0,\n startTime: 0,\n easing: () => 0,\n current: toValue,\n callback,\n } as TimingAnimation;\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AA6BO,SAASE,UAAUA,CACxBC,OAAwB,EACxBC,UAAyB,EACzBC,QAA4B,EACA;EAC5B,SAAS;;EAET,OAAO,IAAAC,qBAAe,EAAkBH,OAAO,EAAE,MAAM;IACrD,SAAS;;IACT,MAAMI,MAA8B,GAAG;MACrCC,QAAQ,EAAE,GAAG;MACbC,MAAM,EAAEC,cAAM,CAACC,KAAK,CAACD,cAAM,CAACE,IAAI;IAClC,CAAC;IACD,IAAIR,UAAU,EAAE;MACdS,MAAM,CAACC,IAAI,CAACV,UAAU,CAAC,CAACW,OAAO,CAC5BC,GAAG,IACAT,MAAM,CAASS,GAAG,CAAC,GAAGZ,UAAU,CAACY,GAAG,CAA6B,CACtE;IACH;IAEA,SAASC,MAAMA,CAACC,SAA+B,EAAEC,GAAc,EAAW;MACxE,MAAM;QAAEhB,OAAO;QAAEiB,SAAS;QAAEC;MAAW,CAAC,GAAGH,SAAS;MACpD,MAAMI,OAAO,GAAGH,GAAG,GAAGC,SAAS;MAE/B,IAAIE,OAAO,IAAIf,MAAM,CAACC,QAAQ,EAAE;QAC9B;QACAU,SAAS,CAACE,SAAS,GAAG,CAAC;QACvBF,SAAS,CAACK,OAAO,GAAGpB,OAAO;QAC3B,OAAO,IAAI;MACb;MACA,MAAMqB,QAAQ,GAAGN,SAAS,CAACT,MAAM,CAACa,OAAO,GAAGf,MAAM,CAACC,QAAQ,CAAC;MAC5DU,SAAS,CAACK,OAAO,GACdF,UAAU,GAAc,CAAClB,OAAO,GAAIkB,UAAqB,IAAIG,QAAQ;MACxE,OAAO,KAAK;IACd;IAEA,SAAS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