react-native-reanimated 2.4.1 → 2.7.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 (387) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +72 -0
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +30 -1
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +64 -39
  4. package/Common/cpp/SharedItems/ShareableValue.cpp +2 -2
  5. package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -14
  6. package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
  7. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
  8. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
  9. package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
  10. package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
  11. package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
  12. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
  13. package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
  14. package/README.md +2 -2
  15. package/RNReanimated.podspec +15 -6
  16. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  17. package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
  18. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  19. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  20. package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
  21. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  22. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  23. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  24. package/android/.gradle/7.2/gc.properties +0 -0
  25. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  26. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  27. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  28. package/android/.gradle/checksums/checksums.lock +0 -0
  29. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  30. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  31. package/android/.gradle/vcs-1/gc.properties +0 -0
  32. package/android/CMakeLists.txt +198 -0
  33. package/android/README.md +15 -0
  34. package/android/build.gradle +676 -73
  35. package/android/empty.cpp +1 -0
  36. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  37. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  38. package/android/gradle.properties +25 -0
  39. package/android/gradlew +234 -0
  40. package/android/gradlew.bat +89 -0
  41. package/android/react-native-reanimated-64-hermes.aar +0 -0
  42. package/android/react-native-reanimated-64-jsc.aar +0 -0
  43. package/android/react-native-reanimated-65-hermes.aar +0 -0
  44. package/android/react-native-reanimated-65-jsc.aar +0 -0
  45. package/android/react-native-reanimated-66-hermes.aar +0 -0
  46. package/android/react-native-reanimated-66-jsc.aar +0 -0
  47. package/android/react-native-reanimated-67-hermes.aar +0 -0
  48. package/android/react-native-reanimated-67-jsc.aar +0 -0
  49. package/android/react-native-reanimated-68-hermes.aar +0 -0
  50. package/android/react-native-reanimated-68-jsc.aar +0 -0
  51. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
  52. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  53. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  54. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  55. package/android/rnVersionPatch/65/.gitkeep +0 -0
  56. package/android/rnVersionPatch/66/.gitkeep +0 -0
  57. package/android/rnVersionPatch/67/.gitkeep +0 -0
  58. package/android/rnVersionPatch/68/.gitkeep +0 -0
  59. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  60. package/android/settings.gradle +1 -0
  61. package/android/spotless.gradle +9 -0
  62. package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
  63. package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
  64. package/android/src/main/cpp/AndroidLogger.cpp +27 -0
  65. package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
  66. package/android/src/main/cpp/JNIHelper.cpp +59 -0
  67. package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
  68. package/android/src/main/cpp/NativeProxy.cpp +327 -0
  69. package/android/src/main/cpp/OnLoad.cpp +17 -0
  70. package/android/src/main/cpp/TurboModule.cpp +44 -0
  71. package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
  72. package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
  73. package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
  74. package/android/src/main/cpp/headers/JNIHelper.h +30 -0
  75. package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
  76. package/android/src/main/cpp/headers/NativeProxy.h +170 -0
  77. package/android/src/main/cpp/headers/TurboModule.h +70 -0
  78. package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
  79. package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
  80. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
  81. package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
  82. package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
  83. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
  84. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +288 -0
  85. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
  86. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
  87. package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
  88. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
  89. package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
  90. package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
  91. package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
  92. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +524 -0
  93. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
  94. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
  95. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
  96. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  97. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
  98. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
  99. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
  100. package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
  101. package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
  102. package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
  103. package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
  104. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
  105. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
  106. package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
  107. package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
  108. package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
  109. package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
  110. package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
  111. package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
  112. package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
  113. package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
  114. package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
  115. package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
  116. package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
  117. package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
  118. package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
  119. package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
  120. package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
  121. package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
  122. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
  123. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
  124. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
  125. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
  126. package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
  127. package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
  128. package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
  129. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
  130. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
  131. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  132. package/ios/LayoutReanimation/REAAnimationsManager.m +16 -6
  133. package/ios/LayoutReanimation/REASnapshot.m +1 -1
  134. package/ios/LayoutReanimation/REAUIManager.h +1 -1
  135. package/ios/LayoutReanimation/REAUIManager.mm +4 -5
  136. package/ios/Nodes/REAAlwaysNode.h +1 -1
  137. package/ios/Nodes/REAAlwaysNode.m +5 -5
  138. package/ios/Nodes/REABezierNode.h +1 -1
  139. package/ios/Nodes/REABezierNode.m +4 -5
  140. package/ios/Nodes/REABlockNode.h +1 -1
  141. package/ios/Nodes/REABlockNode.m +2 -2
  142. package/ios/Nodes/REACallFuncNode.h +1 -1
  143. package/ios/Nodes/REACallFuncNode.m +5 -5
  144. package/ios/Nodes/REAClockNodes.h +1 -1
  145. package/ios/Nodes/REAClockNodes.m +4 -4
  146. package/ios/Nodes/REAConcatNode.h +1 -1
  147. package/ios/Nodes/REAConcatNode.m +3 -3
  148. package/ios/Nodes/REACondNode.h +1 -1
  149. package/ios/Nodes/REACondNode.m +3 -3
  150. package/ios/Nodes/READebugNode.h +1 -1
  151. package/ios/Nodes/READebugNode.m +3 -3
  152. package/ios/Nodes/REAEventNode.h +1 -2
  153. package/ios/Nodes/REAEventNode.m +3 -3
  154. package/ios/Nodes/REAFunctionNode.h +1 -1
  155. package/ios/Nodes/REAFunctionNode.m +3 -3
  156. package/ios/Nodes/REAJSCallNode.h +1 -1
  157. package/ios/Nodes/REAJSCallNode.m +3 -3
  158. package/ios/Nodes/REANode.m +2 -2
  159. package/ios/Nodes/REAOperatorNode.h +1 -1
  160. package/ios/Nodes/REAOperatorNode.m +2 -3
  161. package/ios/Nodes/REAParamNode.h +1 -1
  162. package/ios/Nodes/REAParamNode.m +4 -4
  163. package/ios/Nodes/REAPropsNode.h +1 -1
  164. package/ios/Nodes/REAPropsNode.m +4 -6
  165. package/ios/Nodes/REASetNode.h +1 -1
  166. package/ios/Nodes/REASetNode.m +4 -4
  167. package/ios/Nodes/REAStyleNode.h +1 -1
  168. package/ios/Nodes/REAStyleNode.m +2 -3
  169. package/ios/Nodes/REATransformNode.h +1 -1
  170. package/ios/Nodes/REATransformNode.m +2 -2
  171. package/ios/Nodes/REAValueNode.h +1 -3
  172. package/ios/Nodes/REAValueNode.m +1 -1
  173. package/ios/REAEventDispatcher.m +1 -1
  174. package/ios/REAModule.h +1 -1
  175. package/ios/REAModule.m +12 -14
  176. package/ios/REANodesManager.h +5 -3
  177. package/ios/REANodesManager.m +97 -27
  178. package/ios/Transitioning/RCTConvert+REATransition.h +1 -2
  179. package/ios/Transitioning/RCTConvert+REATransition.m +1 -1
  180. package/ios/Transitioning/REAAllTransitions.h +1 -1
  181. package/ios/Transitioning/REAAllTransitions.m +2 -3
  182. package/ios/Transitioning/REATransition.h +2 -3
  183. package/ios/Transitioning/REATransition.m +3 -4
  184. package/ios/Transitioning/REATransitionAnimation.m +1 -2
  185. package/ios/Transitioning/REATransitionManager.m +2 -4
  186. package/ios/Transitioning/REATransitionValues.m +2 -3
  187. package/ios/native/NativeMethods.h +1 -3
  188. package/ios/native/NativeMethods.mm +1 -1
  189. package/ios/native/NativeProxy.h +2 -2
  190. package/ios/native/NativeProxy.mm +86 -15
  191. package/ios/native/REAIOSErrorHandler.h +2 -4
  192. package/ios/native/REAIOSErrorHandler.mm +1 -1
  193. package/ios/native/REAIOSLogger.h +1 -3
  194. package/ios/native/REAIOSLogger.mm +1 -1
  195. package/ios/native/REAIOSScheduler.h +1 -3
  196. package/ios/native/REAIOSScheduler.mm +2 -2
  197. package/ios/native/REAInitializer.h +0 -7
  198. package/ios/native/REAInitializer.mm +2 -2
  199. package/ios/native/UIResponder+Reanimated.mm +3 -3
  200. package/ios/sensor/ReanimatedSensor.h +25 -0
  201. package/ios/sensor/ReanimatedSensor.m +217 -0
  202. package/ios/sensor/ReanimatedSensorContainer.h +12 -0
  203. package/ios/sensor/ReanimatedSensorContainer.m +40 -0
  204. package/ios/sensor/ReanimatedSensorType.h +7 -0
  205. package/lib/ConfigHelper.js +2 -3
  206. package/lib/createAnimatedComponent.js +3 -4
  207. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  208. package/lib/reanimated1/derived/interpolate.js +2 -4
  209. package/lib/reanimated2/Colors.js +2 -1
  210. package/lib/reanimated2/Easing.js +9 -3
  211. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
  212. package/lib/reanimated2/NativeReanimated/index.js +0 -4
  213. package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
  214. package/lib/reanimated2/animation/styleAnimation.js +2 -1
  215. package/lib/reanimated2/core.js +30 -60
  216. package/lib/reanimated2/globals.d.ts +7 -2
  217. package/lib/reanimated2/hook/index.js +1 -0
  218. package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
  219. package/lib/reanimated2/interpolateColor.js +11 -11
  220. package/lib/reanimated2/interpolation.js +1 -1
  221. package/lib/reanimated2/jestUtils.js +9 -4
  222. package/lib/reanimated2/js-reanimated/JSReanimated.js +23 -2
  223. package/lib/reanimated2/js-reanimated/index.js +3 -3
  224. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
  225. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
  226. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
  227. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
  228. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
  229. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
  230. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
  231. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  232. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
  233. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
  234. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
  235. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
  236. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
  237. package/lib/reanimated2/mock.js +3 -2
  238. package/lib/types/lib/ConfigHelper.d.ts +12 -0
  239. package/lib/types/lib/ReanimatedEventEmitter.d.ts +3 -0
  240. package/lib/types/lib/ReanimatedModule.d.ts +2 -0
  241. package/lib/types/lib/ReanimatedModule.macos.d.ts +2 -0
  242. package/lib/types/lib/ReanimatedModule.native.d.ts +2 -0
  243. package/lib/types/lib/ReanimatedModule.windows.d.ts +2 -0
  244. package/lib/types/lib/ReanimatedModuleCompat.d.ts +14 -0
  245. package/lib/types/lib/createAnimatedComponent.d.ts +33 -0
  246. package/lib/types/lib/reanimated2/Bezier.d.ts +6 -0
  247. package/lib/types/lib/reanimated2/Colors.d.ts +31 -0
  248. package/lib/types/lib/reanimated2/Easing.d.ts +172 -0
  249. package/lib/types/lib/reanimated2/NativeMethods.d.ts +14 -0
  250. package/lib/types/lib/reanimated2/NativeReanimated/NativeReanimated.d.ts +20 -0
  251. package/lib/types/lib/reanimated2/NativeReanimated/index.d.ts +3 -0
  252. package/lib/types/lib/reanimated2/PlatformChecker.d.ts +5 -0
  253. package/lib/types/lib/reanimated2/PropAdapters.d.ts +4 -0
  254. package/lib/types/lib/reanimated2/UpdateProps.d.ts +9 -0
  255. package/lib/types/lib/reanimated2/ViewDescriptorsSet.d.ts +20 -0
  256. package/lib/types/lib/reanimated2/WorkletEventHandler.d.ts +13 -0
  257. package/lib/types/lib/reanimated2/__mocks__/MutableValue.d.ts +5 -0
  258. package/lib/types/lib/reanimated2/__mocks__/NativeReanimated.d.ts +13 -0
  259. package/lib/types/lib/reanimated2/__mocks__/NativeReanimated.native.d.ts +13 -0
  260. package/lib/types/lib/reanimated2/animation/commonTypes.d.ts +27 -0
  261. package/lib/types/lib/reanimated2/animation/decay.d.ts +19 -0
  262. package/lib/types/lib/reanimated2/animation/delay.d.ts +7 -0
  263. package/lib/types/lib/reanimated2/animation/index.d.ts +9 -0
  264. package/lib/types/lib/reanimated2/animation/repeat.d.ts +12 -0
  265. package/lib/types/lib/reanimated2/animation/sequence.d.ts +7 -0
  266. package/lib/types/lib/reanimated2/animation/spring.d.ts +22 -0
  267. package/lib/types/lib/reanimated2/animation/styleAnimation.d.ts +7 -0
  268. package/lib/types/lib/reanimated2/animation/timing.d.ts +21 -0
  269. package/lib/types/lib/reanimated2/animation/util.d.ts +9 -0
  270. package/lib/types/lib/reanimated2/commonTypes.d.ts +79 -0
  271. package/lib/types/lib/reanimated2/component/FlatList.d.ts +9 -0
  272. package/lib/types/lib/reanimated2/component/WrappedComponents.d.ts +8 -0
  273. package/lib/types/lib/reanimated2/component/index.d.ts +9 -0
  274. package/lib/types/lib/reanimated2/core.d.ts +24 -0
  275. package/lib/types/lib/reanimated2/hook/Hooks.d.ts +5 -0
  276. package/lib/types/lib/reanimated2/hook/commonTypes.d.ts +14 -0
  277. package/lib/types/lib/reanimated2/hook/index.d.ts +10 -0
  278. package/lib/types/lib/reanimated2/hook/useAnimatedGestureHandler.d.ts +35 -0
  279. package/lib/types/lib/reanimated2/hook/useAnimatedReaction.d.ts +12 -0
  280. package/lib/types/lib/reanimated2/hook/useAnimatedRef.d.ts +3 -0
  281. package/lib/types/lib/reanimated2/hook/useAnimatedScrollHandler.d.ts +21 -0
  282. package/lib/types/lib/reanimated2/hook/useAnimatedSensor.d.ts +20 -0
  283. package/lib/types/lib/reanimated2/hook/useAnimatedStyle.d.ts +11 -0
  284. package/lib/types/lib/reanimated2/hook/useDerivedValue.d.ts +4 -0
  285. package/lib/types/lib/reanimated2/hook/useSharedValue.d.ts +2 -0
  286. package/lib/types/lib/reanimated2/hook/utils.d.ts +28 -0
  287. package/lib/types/lib/reanimated2/index.d.ts +12 -0
  288. package/lib/types/lib/reanimated2/interpolateColor.d.ts +26 -0
  289. package/lib/types/lib/reanimated2/interpolation.d.ts +14 -0
  290. package/lib/types/lib/reanimated2/jestUtils.d.ts +12 -0
  291. package/lib/types/lib/reanimated2/js-reanimated/JSReanimated.d.ts +30 -0
  292. package/lib/types/lib/reanimated2/js-reanimated/Mapper.d.ts +14 -0
  293. package/lib/types/lib/reanimated2/js-reanimated/MapperRegistry.d.ts +14 -0
  294. package/lib/types/lib/reanimated2/js-reanimated/MutableValue.d.ts +14 -0
  295. package/lib/types/lib/reanimated2/js-reanimated/commonTypes.d.ts +44 -0
  296. package/lib/types/lib/reanimated2/js-reanimated/index.d.ts +15 -0
  297. package/lib/types/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.d.ts +1 -0
  298. package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.d.ts +22 -0
  299. package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.d.ts +38 -0
  300. package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.d.ts +25 -0
  301. package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.d.ts +77 -0
  302. package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/index.d.ts +4 -0
  303. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.d.ts +62 -0
  304. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Default.d.ts +4 -0
  305. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.d.ts +42 -0
  306. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.d.ts +50 -0
  307. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.d.ts +18 -0
  308. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.d.ts +10 -0
  309. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.d.ts +18 -0
  310. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.d.ts +34 -0
  311. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.d.ts +34 -0
  312. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.d.ts +18 -0
  313. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.d.ts +66 -0
  314. package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/index.d.ts +10 -0
  315. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.d.ts +19 -0
  316. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.d.ts +13 -0
  317. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.d.ts +6 -0
  318. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.d.ts +6 -0
  319. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.d.ts +7 -0
  320. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.d.ts +9 -0
  321. package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/index.d.ts +6 -0
  322. package/lib/types/lib/reanimated2/layoutReanimation/index.d.ts +4 -0
  323. package/lib/types/lib/reanimated2/mock.d.ts +55 -0
  324. package/lib/types/lib/reanimated2/platform-specific/RNRenderer.d.ts +1 -0
  325. package/lib/types/lib/reanimated2/platform-specific/RNRenderer.web.d.ts +0 -0
  326. package/lib/types/lib/reanimated2/utils.d.ts +7 -0
  327. package/lib/types/lib/setAndForwardRef.d.ts +40 -0
  328. package/lib/types/react-native-reanimated-tests.d.ts +1 -0
  329. package/mock.js +4 -4
  330. package/package.json +43 -39
  331. package/plugin.js +3 -12
  332. package/react-native-reanimated.d.ts +58 -32
  333. package/src/ConfigHelper.ts +4 -5
  334. package/src/createAnimatedComponent.tsx +4 -4
  335. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  336. package/src/reanimated1/derived/interpolate.js +2 -4
  337. package/src/reanimated2/Colors.ts +2 -1
  338. package/src/reanimated2/Easing.ts +9 -3
  339. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -15
  340. package/src/reanimated2/NativeReanimated/index.ts +0 -6
  341. package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
  342. package/src/reanimated2/animation/index.ts +1 -0
  343. package/src/reanimated2/animation/styleAnimation.ts +10 -7
  344. package/src/reanimated2/animation/timing.ts +3 -1
  345. package/src/reanimated2/animation/util.ts +10 -11
  346. package/src/reanimated2/commonTypes.ts +20 -1
  347. package/src/reanimated2/component/FlatList.tsx +3 -2
  348. package/src/reanimated2/core.ts +34 -73
  349. package/src/reanimated2/globals.d.ts +7 -2
  350. package/src/reanimated2/hook/index.ts +1 -0
  351. package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
  352. package/src/reanimated2/hook/utils.ts +2 -1
  353. package/src/reanimated2/interpolateColor.ts +11 -11
  354. package/src/reanimated2/interpolation.ts +2 -6
  355. package/src/reanimated2/jestUtils.ts +20 -4
  356. package/src/reanimated2/js-reanimated/JSReanimated.ts +25 -2
  357. package/src/reanimated2/js-reanimated/index.ts +3 -3
  358. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
  359. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
  360. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
  361. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
  362. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
  363. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
  364. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
  365. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
  366. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
  367. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
  368. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
  369. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
  370. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
  371. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +26 -19
  372. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
  373. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
  374. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
  375. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
  376. package/src/reanimated2/mock.ts +3 -2
  377. package/android/expo/linking.gradle +0 -46
  378. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +0 -12
  379. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +0 -26
  380. package/android/react-native-reanimated-63-hermes.aar +0 -0
  381. package/android/react-native-reanimated-63-jsc.aar +0 -0
  382. package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
  383. package/expo-module.config.json +0 -3
  384. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  385. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  386. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  387. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
@@ -1,6 +1,5 @@
1
1
  import reanimatedJS from '../js-reanimated';
2
2
  import { shouldBeUseWeb } from '../PlatformChecker';
3
- import { Platform } from 'react-native';
4
3
  import { NativeReanimated } from './NativeReanimated';
5
4
 
6
5
  let exportedModule;
@@ -8,11 +7,6 @@ if (shouldBeUseWeb()) {
8
7
  exportedModule = reanimatedJS;
9
8
  } else {
10
9
  exportedModule = new NativeReanimated();
11
- if (exportedModule.useOnlyV1 && Platform.OS === 'android') {
12
- console.warn(
13
- `If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/installation`
14
- );
15
- }
16
10
  }
17
11
 
18
12
  export default exportedModule as NativeReanimated;
@@ -2,7 +2,7 @@ import { useRef } from 'react';
2
2
  import { makeMutable } from './core';
3
3
  import { SharedValue } from './commonTypes';
4
4
  import { Descriptor } from './hook/commonTypes';
5
- import { Platform } from 'react-native';
5
+ import { shouldBeUseWeb } from './PlatformChecker';
6
6
 
7
7
  export interface ViewRefSet<T> {
8
8
  items: Set<T>;
@@ -24,8 +24,7 @@ export interface ViewDescriptorsSet {
24
24
  ) => void;
25
25
  }
26
26
 
27
- const scheduleUpdates =
28
- Platform.OS === 'web' ? requestAnimationFrame : setImmediate;
27
+ const scheduleUpdates = shouldBeUseWeb() ? requestAnimationFrame : setImmediate;
29
28
 
30
29
  export function makeViewDescriptorsSet(): ViewDescriptorsSet {
31
30
  const ref = useRef<ViewDescriptorsSet | null>(null);
@@ -1,6 +1,7 @@
1
1
  export {
2
2
  HigherOrderAnimation,
3
3
  NextAnimation,
4
+ DelayAnimation,
4
5
  RepeatAnimation,
5
6
  SequenceAnimation,
6
7
  StyleLayoutAnimation,
@@ -57,9 +57,8 @@ export function setPath<T>(
57
57
  currObj = currObj[keys[i]];
58
58
  }
59
59
 
60
- (currObj as { [key: string]: NestedObjectValues<T> })[
61
- keys[keys.length - 1]
62
- ] = value;
60
+ (currObj as { [key: string]: NestedObjectValues<T> })[keys[keys.length - 1]] =
61
+ value;
63
62
  }
64
63
 
65
64
  interface NestedObjectEntry<T> {
@@ -83,7 +82,8 @@ export function withStyleAnimation(
83
82
  { value: animation.styleAnimations, path: [] },
84
83
  ];
85
84
  while (entriesToCheck.length > 0) {
86
- const currentEntry: NestedObjectEntry<AnimationObject> = entriesToCheck.pop() as NestedObjectEntry<AnimationObject>;
85
+ const currentEntry: NestedObjectEntry<AnimationObject> =
86
+ entriesToCheck.pop() as NestedObjectEntry<AnimationObject>;
87
87
  if (Array.isArray(currentEntry.value)) {
88
88
  for (let index = 0; index < currentEntry.value.length; index++) {
89
89
  entriesToCheck.push({
@@ -103,7 +103,8 @@ export function withStyleAnimation(
103
103
  });
104
104
  }
105
105
  } else {
106
- const currentStyleAnimation: AnimationObject = currentEntry.value as AnimationObject;
106
+ const currentStyleAnimation: AnimationObject =
107
+ currentEntry.value as AnimationObject;
107
108
  if (currentStyleAnimation.finished) {
108
109
  continue;
109
110
  }
@@ -211,7 +212,8 @@ export function withStyleAnimation(
211
212
  styleAnimations,
212
213
  ];
213
214
  while (animationsToCheck.length > 0) {
214
- const currentAnimation: NestedObjectValues<AnimationObject> = animationsToCheck.pop() as NestedObjectValues<AnimationObject>;
215
+ const currentAnimation: NestedObjectValues<AnimationObject> =
216
+ animationsToCheck.pop() as NestedObjectValues<AnimationObject>;
215
217
  if (Array.isArray(currentAnimation)) {
216
218
  for (const element of currentAnimation) {
217
219
  animationsToCheck.push(element);
@@ -224,7 +226,8 @@ export function withStyleAnimation(
224
226
  animationsToCheck.push(value);
225
227
  }
226
228
  } else {
227
- const currentStyleAnimation: AnimationObject = currentAnimation as AnimationObject;
229
+ const currentStyleAnimation: AnimationObject =
230
+ currentAnimation as AnimationObject;
228
231
  if (
229
232
  !currentStyleAnimation.finished &&
230
233
  currentStyleAnimation.callback
@@ -80,7 +80,9 @@ export function withTiming(
80
80
  // new timing over the old one with the same parameters. If so, we want
81
81
  // to copy animation timeline properties
82
82
  animation.startTime = (previousAnimation as TimingAnimation).startTime;
83
- animation.startValue = (previousAnimation as TimingAnimation).startValue;
83
+ animation.startValue = (
84
+ previousAnimation as TimingAnimation
85
+ ).startValue;
84
86
  } else {
85
87
  animation.startTime = now;
86
88
  animation.startValue = value;
@@ -228,17 +228,16 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
228
228
  };
229
229
  }
230
230
 
231
- type AnimationToDecoration<
232
- T extends AnimationObject | StyleLayoutAnimation
233
- > = T extends StyleLayoutAnimation
234
- ? Record<string, unknown>
235
- : T extends DelayAnimation
236
- ? NextAnimation<DelayAnimation>
237
- : T extends RepeatAnimation
238
- ? NextAnimation<RepeatAnimation>
239
- : T extends SequenceAnimation
240
- ? NextAnimation<SequenceAnimation>
241
- : AnimatableValue | T;
231
+ type AnimationToDecoration<T extends AnimationObject | StyleLayoutAnimation> =
232
+ T extends StyleLayoutAnimation
233
+ ? Record<string, unknown>
234
+ : T extends DelayAnimation
235
+ ? NextAnimation<DelayAnimation>
236
+ : T extends RepeatAnimation
237
+ ? NextAnimation<RepeatAnimation>
238
+ : T extends SequenceAnimation
239
+ ? NextAnimation<SequenceAnimation>
240
+ : AnimatableValue | T;
242
241
 
243
242
  export function defineAnimation<
244
243
  T extends AnimationObject | StyleLayoutAnimation
@@ -51,7 +51,6 @@ export interface WorkletFunction {
51
51
  _closure?: Context;
52
52
  __workletHash?: number;
53
53
  __optimalization?: number;
54
- __worklet?: boolean;
55
54
  }
56
55
 
57
56
  export interface BasicWorkletFunction<T> extends WorkletFunction {
@@ -126,3 +125,23 @@ export type AnimationCallback = (
126
125
  ) => void;
127
126
 
128
127
  export type Timestamp = number;
128
+
129
+ export type Value3D = {
130
+ x: number;
131
+ y: number;
132
+ z: number;
133
+ };
134
+
135
+ export type SensorValue3D = SharedValue<Value3D>;
136
+
137
+ export type ValueRotation = {
138
+ qw: number;
139
+ qx: number;
140
+ qy: number;
141
+ qz: number;
142
+ yaw: number;
143
+ pitch: number;
144
+ roll: number;
145
+ };
146
+
147
+ export type SensorValueRotation = SharedValue<ValueRotation>;
@@ -13,7 +13,8 @@ const createCellRenderer = (itemLayoutAnimation?: ILayoutAnimationBuilder) => {
13
13
  return (
14
14
  <WrappedComponents.View
15
15
  layout={itemLayoutAnimation}
16
- onLayout={props.onLayout}>
16
+ onLayout={props.onLayout}
17
+ >
17
18
  {props.children}
18
19
  </WrappedComponents.View>
19
20
  );
@@ -22,7 +23,7 @@ const createCellRenderer = (itemLayoutAnimation?: ILayoutAnimationBuilder) => {
22
23
  return cellRenderer;
23
24
  };
24
25
 
25
- interface ReanimatedFlatlistProps<ItemT> extends FlatListProps<ItemT> {
26
+ export interface ReanimatedFlatlistProps<ItemT> extends FlatListProps<ItemT> {
26
27
  itemLayoutAnimation?: ILayoutAnimationBuilder;
27
28
  }
28
29
 
@@ -4,7 +4,6 @@ import { Platform } from 'react-native';
4
4
  import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
5
5
  import {
6
6
  BasicWorkletFunction,
7
- WorkletFunction,
8
7
  ComplexWorkletFunction,
9
8
  SharedValue,
10
9
  AnimationObject,
@@ -14,10 +13,6 @@ import {
14
13
  import { Descriptor } from './hook/commonTypes';
15
14
  import JSReanimated from './js-reanimated/JSReanimated';
16
15
 
17
- global.__reanimatedWorkletInit = function (worklet: WorkletFunction) {
18
- worklet.__worklet = true;
19
- };
20
-
21
16
  if (global._setGlobalConsole === undefined) {
22
17
  // it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1
23
18
  global._setGlobalConsole = () => {
@@ -63,7 +58,7 @@ export const checkPluginState: (throwError: boolean) => boolean = (
63
58
  export const isConfigured: (throwError?: boolean) => boolean = (
64
59
  throwError = false
65
60
  ) => {
66
- return checkPluginState(throwError) && !NativeReanimatedModule.useOnlyV1;
61
+ return checkPluginState(throwError);
67
62
  };
68
63
 
69
64
  export const isConfiguredCheck: () => void = () => {
@@ -74,48 +69,6 @@ export const isConfiguredCheck: () => void = () => {
74
69
  }
75
70
  };
76
71
 
77
- function _toArrayReanimated<T>(object: Iterable<T> | ArrayLike<T> | T[]): T[] {
78
- 'worklet';
79
- if (Array.isArray(object)) {
80
- return object;
81
- }
82
- if (
83
- typeof Symbol !== 'undefined' &&
84
- (typeof Symbol === 'function' ? Symbol.iterator : '@@iterator') in
85
- Object(object)
86
- ) {
87
- return Array.from(object);
88
- }
89
- throw new Error(
90
- 'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
91
- );
92
- }
93
-
94
- function _mergeObjectsReanimated(): unknown {
95
- 'worklet';
96
- // we can't use rest parameters in worklets at the moment
97
- // eslint-disable-next-line prefer-rest-params
98
- const arr = Array.from(arguments);
99
- return Object.assign.apply(null, [arr[0], ...arr.slice(1)]);
100
- }
101
-
102
- global.__reanimatedWorkletInit = function (worklet: WorkletFunction) {
103
- worklet.__worklet = true;
104
-
105
- if (worklet._closure) {
106
- const closure = worklet._closure;
107
- Object.keys(closure).forEach((key) => {
108
- if (key === '_toConsumableArray') {
109
- closure[key] = _toArrayReanimated;
110
- }
111
-
112
- if (key === '_objectSpread') {
113
- closure[key] = _mergeObjectsReanimated;
114
- }
115
- });
116
- }
117
- };
118
-
119
72
  function pushFrame(frame: (timestamp: Timestamp) => void): void {
120
73
  (NativeReanimatedModule as JSReanimated).pushFrame(frame);
121
74
  }
@@ -362,32 +315,30 @@ export function runOnJS<A extends any[], R>(
362
315
  }
363
316
  }
364
317
 
365
- if (!NativeReanimatedModule.useOnlyV1) {
366
- NativeReanimatedModule.installCoreFunctions(
367
- NativeReanimatedModule.native
368
- ? (workletValueSetter as <T>(value: T) => void)
369
- : (workletValueSetterJS as <T>(value: T) => void)
370
- );
318
+ NativeReanimatedModule.installCoreFunctions(
319
+ NativeReanimatedModule.native
320
+ ? (workletValueSetter as <T>(value: T) => void)
321
+ : (workletValueSetterJS as <T>(value: T) => void)
322
+ );
371
323
 
372
- if (!isWeb() && isConfigured()) {
373
- const capturableConsole = console;
374
- runOnUI(() => {
375
- 'worklet';
376
- const console = {
377
- debug: runOnJS(capturableConsole.debug),
378
- log: runOnJS(capturableConsole.log),
379
- warn: runOnJS(capturableConsole.warn),
380
- error: runOnJS(capturableConsole.error),
381
- info: runOnJS(capturableConsole.info),
382
- };
383
- _setGlobalConsole(console);
384
- if (global.performance == null) {
385
- global.performance = {
386
- now: global._chronoNow,
387
- };
388
- }
389
- })();
390
- }
324
+ if (!isWeb() && isConfigured()) {
325
+ const capturableConsole = console;
326
+ runOnUI(() => {
327
+ 'worklet';
328
+ const console = {
329
+ debug: runOnJS(capturableConsole.debug),
330
+ log: runOnJS(capturableConsole.log),
331
+ warn: runOnJS(capturableConsole.warn),
332
+ error: runOnJS(capturableConsole.error),
333
+ info: runOnJS(capturableConsole.info),
334
+ };
335
+ _setGlobalConsole(console);
336
+ if (global.performance == null) {
337
+ global.performance = {
338
+ now: global._chronoNow,
339
+ } as any; // due to conflict with lib.dom.d.ts -> Performance
340
+ }
341
+ })();
391
342
  }
392
343
 
393
344
  type FeaturesConfig = {
@@ -418,3 +369,13 @@ export function enableLayoutAnimations(
418
369
  NativeReanimatedModule.enableLayoutAnimations(flag);
419
370
  }
420
371
  }
372
+
373
+ export function configureProps(uiProps: string[], nativeProps: string[]): void {
374
+ if (!nativeShouldBeMock()) {
375
+ NativeReanimatedModule.configureProps(uiProps, nativeProps);
376
+ }
377
+ }
378
+
379
+ export function jestResetJsReanimatedModule() {
380
+ (NativeReanimatedModule as JSReanimated).jestResetModule();
381
+ }
@@ -1,4 +1,4 @@
1
- import { AnimatedStyle, StyleProps, WorkletFunction } from './commonTypes';
1
+ import { AnimatedStyle, StyleProps } from './commonTypes';
2
2
  import { ReanimatedConsole } from './core';
3
3
  import { MeasuredDimensions } from './NativeMethods';
4
4
  import { NativeReanimated } from './NativeReanimated/NativeReanimated';
@@ -27,9 +27,11 @@ declare global {
27
27
  animated: boolean
28
28
  ) => void;
29
29
  const _chronoNow: () => number;
30
+ const ReanimatedDataMock: {
31
+ now: () => number;
32
+ };
30
33
  namespace NodeJS {
31
34
  interface Global {
32
- __reanimatedWorkletInit: (worklet: WorkletFunction) => void;
33
35
  _setGlobalConsole: (console?: ReanimatedConsole) => void;
34
36
  _log: (s: string) => void;
35
37
  _setGestureState: () => void;
@@ -50,6 +52,9 @@ declare global {
50
52
  yogaValues: unknown
51
53
  ): void;
52
54
  };
55
+ ReanimatedDataMock: {
56
+ now: () => number;
57
+ };
53
58
  }
54
59
  }
55
60
  }
@@ -23,3 +23,4 @@ export {
23
23
  ScrollHandlers,
24
24
  } from './useAnimatedScrollHandler';
25
25
  export { useDerivedValue, DerivedValue } from './useDerivedValue';
26
+ export { useAnimatedSensor, SensorType } from './useAnimatedSensor';
@@ -0,0 +1,91 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { makeMutable } from '../core';
3
+ import NativeReanimated from '../NativeReanimated';
4
+ import { SensorValue3D, SensorValueRotation } from '../commonTypes';
5
+
6
+ export enum SensorType {
7
+ ACCELEROMETER = 1,
8
+ GYROSCOPE = 2,
9
+ GRAVITY = 3,
10
+ MAGNETIC_FIELD = 4,
11
+ ROTATION = 5,
12
+ }
13
+
14
+ export type SensorConfig = {
15
+ interval: number;
16
+ };
17
+
18
+ export type AnimatedSensor = {
19
+ sensor: SensorValue3D | SensorValueRotation | null;
20
+ unregister: () => void;
21
+ isAvailable: boolean;
22
+ config: {
23
+ interval: number;
24
+ };
25
+ };
26
+
27
+ export function useAnimatedSensor(
28
+ sensorType: SensorType,
29
+ userConfig?: SensorConfig
30
+ ): AnimatedSensor {
31
+ const ref = useRef({
32
+ sensor: null,
33
+ unregister: () => {
34
+ // NOOP
35
+ },
36
+ isAvailable: false,
37
+ config: {
38
+ interval: 0,
39
+ },
40
+ });
41
+
42
+ if (ref.current.sensor === null) {
43
+ ref.current.config = { interval: 10, ...userConfig };
44
+ let sensorData;
45
+ if (sensorType === SensorType.ROTATION) {
46
+ sensorData = {
47
+ qw: 0,
48
+ qx: 0,
49
+ qy: 0,
50
+ qz: 0,
51
+ yaw: 0,
52
+ pitch: 0,
53
+ roll: 0,
54
+ };
55
+ } else {
56
+ sensorData = {
57
+ x: 0,
58
+ y: 0,
59
+ z: 0,
60
+ };
61
+ }
62
+ ref.current.sensor = makeMutable(sensorData) as any;
63
+ }
64
+
65
+ useEffect(() => {
66
+ ref.current.config = { interval: 10, ...userConfig };
67
+ const id = NativeReanimated.registerSensor(
68
+ sensorType,
69
+ ref.current.config.interval,
70
+ ref.current.sensor as any
71
+ );
72
+
73
+ if (id !== -1) {
74
+ // if sensor is available
75
+ ref.current.unregister = () => NativeReanimated.unregisterSensor(id);
76
+ ref.current.isAvailable = true;
77
+ } else {
78
+ // if sensor is unavailable
79
+ ref.current.unregister = () => {
80
+ // NOOP
81
+ };
82
+ ref.current.isAvailable = false;
83
+ }
84
+
85
+ return () => {
86
+ ref.current.unregister();
87
+ };
88
+ }, [sensorType, userConfig]);
89
+
90
+ return ref.current;
91
+ }
@@ -187,7 +187,8 @@ export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
187
187
  'worklet';
188
188
  const propsToCheck: NestedObjectValues<AnimationObject>[] = [prop];
189
189
  while (propsToCheck.length > 0) {
190
- const currentProp: NestedObjectValues<AnimationObject> = propsToCheck.pop() as NestedObjectValues<AnimationObject>;
190
+ const currentProp: NestedObjectValues<AnimationObject> =
191
+ propsToCheck.pop() as NestedObjectValues<AnimationObject>;
191
192
  if (Array.isArray(currentProp)) {
192
193
  for (const item of currentProp) {
193
194
  propsToCheck.push(item);
@@ -58,13 +58,13 @@ const getInterpolateRGB = (
58
58
  const a = [];
59
59
  for (let i = 0; i < colors.length; ++i) {
60
60
  const color = colors[i];
61
- const proocessedColor = processColor(color);
61
+ const processedColor = processColor(color);
62
62
  // explicit check in case if processedColor is 0
63
- if (proocessedColor !== null && proocessedColor !== undefined) {
64
- r.push(red(proocessedColor));
65
- g.push(green(proocessedColor));
66
- b.push(blue(proocessedColor));
67
- a.push(opacity(proocessedColor));
63
+ if (processedColor !== null && processedColor !== undefined) {
64
+ r.push(red(processedColor));
65
+ g.push(green(processedColor));
66
+ b.push(blue(processedColor));
67
+ a.push(opacity(processedColor));
68
68
  }
69
69
  }
70
70
  return { r, g, b, a };
@@ -85,11 +85,11 @@ const getInterpolateHSV = (
85
85
  const v = [];
86
86
  for (let i = 0; i < colors.length; ++i) {
87
87
  const color = colors[i];
88
- const proocessedColor = RGBtoHSV(processColor(color) as any);
89
- if (proocessedColor) {
90
- h.push(proocessedColor.h);
91
- s.push(proocessedColor.s);
92
- v.push(proocessedColor.v);
88
+ const processedColor = RGBtoHSV(processColor(color) as any);
89
+ if (processedColor) {
90
+ h.push(processedColor.h);
91
+ s.push(processedColor.s);
92
+ v.push(processedColor.v);
93
93
  }
94
94
  }
95
95
  return { h, s, v };
@@ -123,12 +123,8 @@ function internalInterpolate(
123
123
  extrapolationConfig: RequiredExtrapolationConfig
124
124
  ) {
125
125
  'worklet';
126
- const {
127
- leftEdgeInput,
128
- rightEdgeInput,
129
- leftEdgeOutput,
130
- rightEdgeOutput,
131
- } = narrowedInput;
126
+ const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput } =
127
+ narrowedInput;
132
128
  if (rightEdgeInput - leftEdgeInput === 0) return leftEdgeOutput;
133
129
  const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
134
130
  const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
@@ -1,6 +1,17 @@
1
1
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
2
  // @ts-nocheck
3
- const MockDate = require('mockdate');
3
+ import { jestResetJsReanimatedModule } from './core';
4
+
5
+ declare global {
6
+ // eslint-disable-next-line @typescript-eslint/no-namespace
7
+ namespace jest {
8
+ interface Matchers<R> {
9
+ toHaveAnimatedStyle(
10
+ style: Record<string, unknown>[] | Record<string, unknown>
11
+ ): R;
12
+ }
13
+ }
14
+ }
4
15
 
5
16
  let config = {
6
17
  fps: 60,
@@ -129,26 +140,30 @@ const compareStyle = (received, expectedStyle, config) => {
129
140
 
130
141
  let frameTime = 1000 / config.fps;
131
142
  let requestAnimationFrameCopy;
143
+ let currentTimestamp = 0;
132
144
 
133
145
  const requestAnimationFrame = (callback) => {
134
146
  setTimeout(callback, frameTime);
135
147
  };
136
148
 
137
149
  const beforeTest = () => {
150
+ jestResetJsReanimatedModule();
138
151
  requestAnimationFrameCopy = global.requestAnimationFrame;
139
152
  global.requestAnimationFrame = requestAnimationFrame;
140
- MockDate.set(0);
153
+ global.ReanimatedDataMock = {
154
+ now: () => currentTimestamp,
155
+ };
156
+ currentTimestamp = 0;
141
157
  jest.useFakeTimers();
142
158
  };
143
159
 
144
160
  const afterTest = () => {
145
- MockDate.reset();
146
161
  jest.useRealTimers();
147
162
  global.requestAnimationFrame = requestAnimationFrameCopy;
148
163
  };
149
164
 
150
165
  const tickTravel = () => {
151
- MockDate.set(new Date(Date.now() + frameTime));
166
+ currentTimestamp += frameTime;
152
167
  jest.advanceTimersByTime(frameTime);
153
168
  };
154
169
 
@@ -174,6 +189,7 @@ export const advanceAnimationByFrame = (count) => {
174
189
 
175
190
  export const setUpTests = (userConfig = {}) => {
176
191
  const expect = require('expect');
192
+ require('setimmediate');
177
193
  frameTime = Math.round(1000 / config.fps);
178
194
 
179
195
  config = {
@@ -3,6 +3,7 @@ import Mapper from './Mapper';
3
3
  import MutableValue from './MutableValue';
4
4
  import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
5
5
  import { Timestamp, NestedObjectValues } from '../commonTypes';
6
+ import { isJest } from '../PlatformChecker';
6
7
 
7
8
  export default class JSReanimated extends NativeReanimated {
8
9
  _valueSetter?: <T>(value: T) => void = undefined;
@@ -14,8 +15,8 @@ export default class JSReanimated extends NativeReanimated {
14
15
 
15
16
  constructor() {
16
17
  super(false);
17
- if (process.env.JEST_WORKER_ID) {
18
- this.timeProvider = { now: () => Date.now() };
18
+ if (isJest()) {
19
+ this.timeProvider = { now: () => global.ReanimatedDataMock.now() };
19
20
  } else {
20
21
  this.timeProvider = { now: () => window.performance.now() };
21
22
  }
@@ -103,4 +104,26 @@ export default class JSReanimated extends NativeReanimated {
103
104
  '[Reanimated] enableLayoutAnimations is not available for WEB yet'
104
105
  );
105
106
  }
107
+
108
+ registerSensor(): number {
109
+ console.warn('[Reanimated] useAnimatedSensor is not available on web yet.');
110
+ return -1;
111
+ }
112
+
113
+ unregisterSensor(): void {
114
+ // noop
115
+ }
116
+
117
+ jestResetModule() {
118
+ if (isJest()) {
119
+ /**
120
+ * If someone used timers to stop animation before the end,
121
+ * then _renderRequested was set as true
122
+ * and any new update from another test wasn't applied.
123
+ */
124
+ this._renderRequested = false;
125
+ } else {
126
+ throw Error('This method can be only use in Jest testing.');
127
+ }
128
+ }
106
129
  }
@@ -20,7 +20,7 @@ if (shouldBeUseWeb()) {
20
20
  };
21
21
  global._measure = () => {
22
22
  console.warn(
23
- "[Reanimated] You can't use 'measue' method with Chrome Debugger or with web version"
23
+ "[Reanimated] You can't use `measure` with Chrome Debugger or with web version"
24
24
  );
25
25
  return {
26
26
  x: 0,
@@ -33,12 +33,12 @@ if (shouldBeUseWeb()) {
33
33
  };
34
34
  global._scrollTo = () => {
35
35
  console.warn(
36
- "[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version"
36
+ "[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version"
37
37
  );
38
38
  };
39
39
  global._setGestureState = () => {
40
40
  console.warn(
41
- "[Reanimated] You can't use 'setGestureState' method with Chrome Debugger or with web version"
41
+ "[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version"
42
42
  );
43
43
  };
44
44
  }