react-native-reanimated 3.0.0-rc.9 → 3.0.1

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 (331) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +30 -12
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +2 -0
  3. package/Common/cpp/Fabric/FabricUtils.cpp +3 -107
  4. package/Common/cpp/Fabric/FabricUtils.h +3 -24
  5. package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +54 -37
  6. package/Common/cpp/LayoutAnimations/LayoutAnimationType.h +8 -0
  7. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +81 -26
  8. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +20 -3
  9. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +105 -109
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.h +19 -12
  11. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +6 -2
  13. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +20 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +9 -0
  15. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +5 -1
  16. package/Common/cpp/Registries/EventHandlerRegistry.cpp +8 -34
  17. package/Common/cpp/Registries/EventHandlerRegistry.h +7 -13
  18. package/Common/cpp/SharedItems/Shareables.cpp +9 -63
  19. package/Common/cpp/SharedItems/Shareables.h +77 -72
  20. package/Common/cpp/Tools/CollectionUtils.h +14 -0
  21. package/Common/cpp/Tools/JsiUtils.cpp +26 -0
  22. package/Common/cpp/Tools/JsiUtils.h +176 -0
  23. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +5 -5
  24. package/Common/cpp/Tools/ReanimatedVersion.cpp +17 -0
  25. package/Common/cpp/Tools/ReanimatedVersion.h +11 -0
  26. package/Common/cpp/Tools/RuntimeDecorator.cpp +49 -230
  27. package/Common/cpp/Tools/RuntimeDecorator.h +0 -2
  28. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -2
  29. package/Common/cpp/Tools/WorkletEventHandler.h +14 -6
  30. package/README.md +1 -1
  31. package/RNReanimated.podspec +2 -1
  32. package/android/CMakeLists.txt +188 -181
  33. package/android/build.gradle +362 -311
  34. package/android/proguard-rules.pro +2 -0
  35. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +63 -295
  36. package/android/src/main/cpp/LayoutAnimations.cpp +35 -5
  37. package/android/src/main/cpp/LayoutAnimations.h +23 -6
  38. package/android/src/main/cpp/NativeProxy.cpp +143 -98
  39. package/android/src/main/cpp/NativeProxy.h +22 -28
  40. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +5 -4
  41. package/android/src/main/java/com/swmansion/reanimated/Utils.java +7 -1
  42. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +10 -3
  43. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +218 -35
  44. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +43 -17
  45. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +6 -2
  46. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedElement.java +19 -0
  47. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedTransitionManager.java +610 -0
  48. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +93 -23
  49. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/AnimationFrameCallback.java +19 -0
  50. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +35 -0
  51. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/KeyboardEventDataUpdater.java +16 -0
  52. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +206 -0
  53. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/SensorSetter.java +17 -0
  54. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +9 -3
  55. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +3 -4
  56. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -7
  57. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +90 -307
  58. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/70/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +16 -0
  59. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +63 -0
  60. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +271 -0
  61. package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +76 -20
  62. package/ios/LayoutReanimation/REAAnimationsManager.h +28 -4
  63. package/ios/LayoutReanimation/REAAnimationsManager.m +216 -61
  64. package/ios/LayoutReanimation/REAFrame.h +10 -0
  65. package/ios/LayoutReanimation/REAFrame.m +15 -0
  66. package/ios/LayoutReanimation/REAScreensHelper.h +19 -0
  67. package/ios/LayoutReanimation/REAScreensHelper.m +106 -0
  68. package/ios/LayoutReanimation/REASharedElement.h +15 -0
  69. package/ios/LayoutReanimation/REASharedElement.m +16 -0
  70. package/ios/LayoutReanimation/REASharedTransitionManager.h +17 -0
  71. package/ios/LayoutReanimation/REASharedTransitionManager.m +632 -0
  72. package/ios/LayoutReanimation/REASnapshot.h +1 -0
  73. package/ios/LayoutReanimation/REASnapshot.m +96 -11
  74. package/ios/LayoutReanimation/REAUIManager.mm +64 -17
  75. package/ios/REAModule.mm +2 -7
  76. package/ios/REANodesManager.mm +1 -21
  77. package/ios/keyboardObserver/REAKeyboardEventObserver.m +72 -36
  78. package/ios/native/NativeProxy.mm +75 -114
  79. package/ios/native/REAInitializer.mm +2 -7
  80. package/ios/native/REAJSIUtils.h +60 -2
  81. package/ios/sensor/ReanimatedSensor.h +6 -2
  82. package/ios/sensor/ReanimatedSensor.m +43 -7
  83. package/ios/sensor/ReanimatedSensorContainer.h +4 -1
  84. package/ios/sensor/ReanimatedSensorContainer.m +8 -2
  85. package/lib/commonjs/createAnimatedComponent.js +244 -28
  86. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  87. package/lib/commonjs/reanimated2/Colors.js +43 -22
  88. package/lib/commonjs/reanimated2/Colors.js.map +1 -1
  89. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +16 -33
  90. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  91. package/lib/commonjs/reanimated2/animation/styleAnimation.js +5 -1
  92. package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
  93. package/lib/commonjs/reanimated2/animation/util.js +17 -15
  94. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  95. package/lib/commonjs/reanimated2/commonTypes.js +33 -1
  96. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  97. package/lib/commonjs/reanimated2/core.js +33 -14
  98. package/lib/commonjs/reanimated2/core.js.map +1 -1
  99. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  100. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  101. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  102. package/lib/commonjs/reanimated2/hook/index.js +0 -6
  103. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  104. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  105. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  106. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
  107. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  108. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
  109. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  110. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +91 -15
  111. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  112. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -40
  113. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  114. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
  115. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  116. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
  117. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  118. package/lib/commonjs/reanimated2/hook/utils.js +18 -65
  119. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  120. package/lib/commonjs/reanimated2/index.js +13 -0
  121. package/lib/commonjs/reanimated2/index.js.map +1 -1
  122. package/lib/commonjs/reanimated2/initializers.js +71 -32
  123. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  124. package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
  125. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  126. package/lib/commonjs/reanimated2/jestUtils.js +1 -1
  127. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  128. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +103 -13
  129. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  130. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
  131. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  132. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
  133. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  134. package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  135. package/lib/commonjs/reanimated2/js-reanimated/global.js +0 -2
  136. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  137. package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
  138. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  139. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
  140. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  141. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
  142. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  143. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +22 -9
  144. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  145. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
  146. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  147. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
  148. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  149. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
  150. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  151. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
  152. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  153. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
  154. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  155. package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
  156. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  157. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
  158. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  159. package/lib/commonjs/reanimated2/mappers.js +18 -6
  160. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  161. package/lib/commonjs/reanimated2/mock.js +20 -1
  162. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  163. package/lib/commonjs/reanimated2/mutables.js +4 -2
  164. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  165. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
  166. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
  167. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
  168. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  169. package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
  170. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
  171. package/lib/commonjs/reanimated2/shareables.js +36 -15
  172. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  173. package/lib/commonjs/reanimated2/threads.js +114 -7
  174. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  175. package/lib/commonjs/reanimated2/utils.js +7 -0
  176. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  177. package/lib/commonjs/reanimated2/valueSetter.js +1 -3
  178. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  179. package/lib/module/createAnimatedComponent.js +241 -29
  180. package/lib/module/createAnimatedComponent.js.map +1 -1
  181. package/lib/module/reanimated2/Colors.js +35 -19
  182. package/lib/module/reanimated2/Colors.js.map +1 -1
  183. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +16 -32
  184. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  185. package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
  186. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  187. package/lib/module/reanimated2/animation/util.js +17 -16
  188. package/lib/module/reanimated2/animation/util.js.map +1 -1
  189. package/lib/module/reanimated2/commonTypes.js +29 -0
  190. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  191. package/lib/module/reanimated2/core.js +32 -7
  192. package/lib/module/reanimated2/core.js.map +1 -1
  193. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  194. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  195. package/lib/module/reanimated2/globals.d.js.map +1 -1
  196. package/lib/module/reanimated2/hook/index.js +1 -1
  197. package/lib/module/reanimated2/hook/index.js.map +1 -1
  198. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  199. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  200. package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
  201. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  202. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  203. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  204. package/lib/module/reanimated2/hook/useAnimatedSensor.js +90 -13
  205. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  206. package/lib/module/reanimated2/hook/useAnimatedStyle.js +46 -43
  207. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  208. package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
  209. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  210. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
  211. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  212. package/lib/module/reanimated2/hook/utils.js +17 -60
  213. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  214. package/lib/module/reanimated2/index.js +1 -0
  215. package/lib/module/reanimated2/index.js.map +1 -1
  216. package/lib/module/reanimated2/initializers.js +72 -33
  217. package/lib/module/reanimated2/initializers.js.map +1 -1
  218. package/lib/module/reanimated2/interpolateColor.js +96 -19
  219. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  220. package/lib/module/reanimated2/jestUtils.js +1 -1
  221. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  222. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +103 -13
  223. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  224. package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
  225. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  226. package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
  227. package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  228. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  229. package/lib/module/reanimated2/js-reanimated/global.js +0 -2
  230. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  231. package/lib/module/reanimated2/js-reanimated/index.js +0 -1
  232. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  233. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
  234. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  235. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
  236. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  237. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +20 -8
  238. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  239. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
  240. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  241. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
  242. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  243. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  244. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  245. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
  246. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  247. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
  248. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  249. package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
  250. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  251. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
  252. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  253. package/lib/module/reanimated2/mappers.js +16 -6
  254. package/lib/module/reanimated2/mappers.js.map +1 -1
  255. package/lib/module/reanimated2/mock.js +20 -1
  256. package/lib/module/reanimated2/mock.js.map +1 -1
  257. package/lib/module/reanimated2/mutables.js +4 -2
  258. package/lib/module/reanimated2/mutables.js.map +1 -1
  259. package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
  260. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
  261. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
  262. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  263. package/lib/module/reanimated2/pluginUtils.js +4 -0
  264. package/lib/module/reanimated2/pluginUtils.js.map +1 -0
  265. package/lib/module/reanimated2/shareables.js +36 -12
  266. package/lib/module/reanimated2/shareables.js.map +1 -1
  267. package/lib/module/reanimated2/threads.js +105 -7
  268. package/lib/module/reanimated2/threads.js.map +1 -1
  269. package/lib/module/reanimated2/utils.js +5 -0
  270. package/lib/module/reanimated2/utils.js.map +1 -1
  271. package/lib/module/reanimated2/valueSetter.js +1 -2
  272. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  273. package/mock.js +1 -211
  274. package/package.json +10 -10
  275. package/{plugin.js → plugin/index.js} +128 -249
  276. package/react-native-reanimated.d.ts +55 -417
  277. package/scripts/reanimated_utils.rb +15 -2
  278. package/src/createAnimatedComponent.tsx +247 -28
  279. package/src/reanimated2/Colors.ts +38 -11
  280. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +52 -39
  281. package/src/reanimated2/animation/styleAnimation.ts +8 -1
  282. package/src/reanimated2/animation/util.ts +29 -16
  283. package/src/reanimated2/commonTypes.ts +28 -1
  284. package/src/reanimated2/core.ts +42 -9
  285. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
  286. package/src/reanimated2/globals.d.ts +12 -15
  287. package/src/reanimated2/hook/index.ts +1 -1
  288. package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
  289. package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
  290. package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
  291. package/src/reanimated2/hook/useAnimatedSensor.ts +90 -11
  292. package/src/reanimated2/hook/useAnimatedStyle.ts +44 -36
  293. package/src/reanimated2/hook/useDerivedValue.ts +8 -1
  294. package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
  295. package/src/reanimated2/hook/utils.ts +15 -61
  296. package/src/reanimated2/index.ts +1 -0
  297. package/src/reanimated2/initializers.ts +76 -35
  298. package/src/reanimated2/interpolateColor.ts +104 -20
  299. package/src/reanimated2/jestUtils.ts +1 -1
  300. package/src/reanimated2/js-reanimated/JSReanimated.ts +98 -15
  301. package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
  302. package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
  303. package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
  304. package/src/reanimated2/js-reanimated/global.ts +0 -1
  305. package/src/reanimated2/js-reanimated/index.ts +0 -1
  306. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
  307. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  308. package/src/reanimated2/layoutReanimation/animationsManager.ts +20 -9
  309. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
  310. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
  311. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
  312. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
  313. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
  314. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  315. package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
  316. package/src/reanimated2/mappers.ts +17 -6
  317. package/src/reanimated2/mock.ts +25 -2
  318. package/src/reanimated2/mutables.ts +2 -0
  319. package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
  320. package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
  321. package/src/reanimated2/pluginUtils.ts +8 -0
  322. package/src/reanimated2/shareables.ts +45 -16
  323. package/src/reanimated2/threads.ts +103 -4
  324. package/src/reanimated2/utils.ts +6 -0
  325. package/src/reanimated2/valueSetter.ts +1 -2
  326. package/lib/commonjs/reanimated2/time.js +0 -55
  327. package/lib/commonjs/reanimated2/time.js.map +0 -1
  328. package/lib/module/reanimated2/time.js +0 -37
  329. package/lib/module/reanimated2/time.js.map +0 -1
  330. package/src/reanimated2/time.ts +0 -30
  331. /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
@@ -7,7 +7,14 @@ import {
7
7
  StyleLayoutAnimation,
8
8
  } from './commonTypes';
9
9
  /* global _WORKLET */
10
- import { ParsedColorArray, convertToHSVA, isColor, toRGBA } from '../Colors';
10
+ import {
11
+ ParsedColorArray,
12
+ isColor,
13
+ convertToRGBA,
14
+ rgbaArrayToRGBAColor,
15
+ toGammaSpace,
16
+ toLinearSpace,
17
+ } from '../Colors';
11
18
 
12
19
  import {
13
20
  AnimatedStyle,
@@ -126,55 +133,59 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
126
133
  return res;
127
134
  };
128
135
 
129
- const tab = ['H', 'S', 'V', 'A'];
136
+ const tab = ['R', 'G', 'B', 'A'];
130
137
  const colorOnStart = (
131
138
  animation: Animation<AnimationObject>,
132
139
  value: string | number,
133
140
  timestamp: Timestamp,
134
141
  previousAnimation: Animation<AnimationObject>
135
142
  ): void => {
136
- let HSVAValue: ParsedColorArray;
137
- let HSVACurrent: ParsedColorArray;
138
- let HSVAToValue: ParsedColorArray;
143
+ let RGBAValue: ParsedColorArray;
144
+ let RGBACurrent: ParsedColorArray;
145
+ let RGBAToValue: ParsedColorArray;
139
146
  const res: Array<number> = [];
140
147
  if (isColor(value)) {
141
- HSVACurrent = convertToHSVA(animation.current);
142
- HSVAValue = convertToHSVA(value);
148
+ RGBACurrent = toLinearSpace(convertToRGBA(animation.current));
149
+ RGBAValue = toLinearSpace(convertToRGBA(value));
143
150
  if (animation.toValue) {
144
- HSVAToValue = convertToHSVA(animation.toValue);
151
+ RGBAToValue = toLinearSpace(convertToRGBA(animation.toValue));
145
152
  }
146
153
  }
147
154
  tab.forEach((i, index) => {
148
155
  animation[i] = Object.assign({}, animationCopy);
149
- animation[i].current = HSVACurrent[index];
150
- animation[i].toValue = HSVAToValue ? HSVAToValue[index] : undefined;
156
+ animation[i].current = RGBACurrent[index];
157
+ animation[i].toValue = RGBAToValue ? RGBAToValue[index] : undefined;
151
158
  animation[i].onStart(
152
159
  animation[i],
153
- HSVAValue[index],
160
+ RGBAValue[index],
154
161
  timestamp,
155
162
  previousAnimation ? previousAnimation[i] : undefined
156
163
  );
157
164
  res.push(animation[i].current);
158
165
  });
159
166
 
160
- animation.current = toRGBA(res as ParsedColorArray);
167
+ animation.current = rgbaArrayToRGBAColor(
168
+ toGammaSpace(res as ParsedColorArray)
169
+ );
161
170
  };
162
171
 
163
172
  const colorOnFrame = (
164
173
  animation: Animation<AnimationObject>,
165
174
  timestamp: Timestamp
166
175
  ): boolean => {
167
- const HSVACurrent = convertToHSVA(animation.current);
176
+ const RGBACurrent = toLinearSpace(convertToRGBA(animation.current));
168
177
  const res: Array<number> = [];
169
178
  let finished = true;
170
179
  tab.forEach((i, index) => {
171
- animation[i].current = HSVACurrent[index];
180
+ animation[i].current = RGBACurrent[index];
172
181
  // @ts-ignore: disable-next-line
173
182
  finished &= animation[i].onFrame(animation[i], timestamp);
174
183
  res.push(animation[i].current);
175
184
  });
176
185
 
177
- animation.current = toRGBA(res as ParsedColorArray);
186
+ animation.current = rgbaArrayToRGBAColor(
187
+ toGammaSpace(res as ParsedColorArray)
188
+ );
178
189
  return finished;
179
190
  };
180
191
 
@@ -247,6 +258,8 @@ type AnimationToDecoration<T extends AnimationObject | StyleLayoutAnimation> =
247
258
  ? NextAnimation<SequenceAnimation>
248
259
  : AnimatableValue | T;
249
260
 
261
+ const IS_NATIVE = NativeReanimatedModule.native;
262
+
250
263
  export function defineAnimation<
251
264
  T extends AnimationObject | StyleLayoutAnimation
252
265
  >(starting: AnimationToDecoration<T>, factory: () => T): T {
@@ -261,7 +274,7 @@ export function defineAnimation<
261
274
  return animation;
262
275
  };
263
276
 
264
- if (_WORKLET || !NativeReanimatedModule.native) {
277
+ if (_WORKLET || !IS_NATIVE) {
265
278
  return create();
266
279
  }
267
280
  // @ts-ignore: eslint-disable-line
@@ -79,7 +79,6 @@ export type Context = Record<string, unknown>;
79
79
  export interface WorkletFunction {
80
80
  _closure?: Context;
81
81
  __workletHash?: number;
82
- __optimalization?: number;
83
82
  }
84
83
 
85
84
  export interface BasicWorkletFunction<T> extends WorkletFunction {
@@ -145,6 +144,21 @@ export interface Animation<T extends AnimationObject> extends AnimationObject {
145
144
  ) => void;
146
145
  }
147
146
 
147
+ export enum SensorType {
148
+ ACCELEROMETER = 1,
149
+ GYROSCOPE = 2,
150
+ GRAVITY = 3,
151
+ MAGNETIC_FIELD = 4,
152
+ ROTATION = 5,
153
+ }
154
+ export enum IOSReferenceFrame {
155
+ XArbitraryZVertical,
156
+ XArbitraryCorrectedZVertical,
157
+ XMagneticNorthZVertical,
158
+ XTrueNorthZVertical,
159
+ Auto,
160
+ }
161
+
148
162
  export interface NumericAnimation {
149
163
  current?: number;
150
164
  }
@@ -160,6 +174,7 @@ export type Value3D = {
160
174
  x: number;
161
175
  y: number;
162
176
  z: number;
177
+ interfaceOrientation: InterfaceOrientation;
163
178
  };
164
179
 
165
180
  export type ValueRotation = {
@@ -170,8 +185,16 @@ export type ValueRotation = {
170
185
  yaw: number;
171
186
  pitch: number;
172
187
  roll: number;
188
+ interfaceOrientation: InterfaceOrientation;
173
189
  };
174
190
 
191
+ export enum InterfaceOrientation {
192
+ ROTATION_0 = 0,
193
+ ROTATION_90 = 90,
194
+ ROTATION_180 = 180,
195
+ ROTATION_270 = 270,
196
+ }
197
+
175
198
  export type ShadowNodeWrapper = object;
176
199
 
177
200
  export enum KeyboardState {
@@ -195,3 +218,7 @@ export interface MeasuredDimensions {
195
218
  pageX: number;
196
219
  pageY: number;
197
220
  }
221
+
222
+ export interface AnimatedKeyboardOptions {
223
+ isStatusBarTranslucentAndroid?: boolean;
224
+ }
@@ -1,6 +1,11 @@
1
1
  import NativeReanimatedModule from './NativeReanimated';
2
2
  import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
3
- import { BasicWorkletFunction, Value3D, ValueRotation } from './commonTypes';
3
+ import {
4
+ AnimatedKeyboardOptions,
5
+ BasicWorkletFunction,
6
+ Value3D,
7
+ ValueRotation,
8
+ } from './commonTypes';
4
9
  import {
5
10
  makeShareableCloneRecursive,
6
11
  makeShareable as makeShareableUnwrapped,
@@ -10,12 +15,14 @@ import {
10
15
  makeMutable as makeMutableUnwrapped,
11
16
  makeRemote as makeRemoteUnwrapped,
12
17
  } from './mutables';
13
- import { LayoutAnimationFunction } from './layoutReanimation';
18
+ import {
19
+ LayoutAnimationFunction,
20
+ LayoutAnimationType,
21
+ } from './layoutReanimation';
14
22
  import { initializeUIRuntime } from './initializers';
15
23
 
16
24
  export { stopMapper } from './mappers';
17
25
  export { runOnJS, runOnUI } from './threads';
18
- export { getTimestamp } from './time';
19
26
 
20
27
  export type ReanimatedConsole = Pick<
21
28
  Console,
@@ -110,9 +117,16 @@ export function registerEventHandler<T>(
110
117
  eventHash: string,
111
118
  eventHandler: (event: T) => void
112
119
  ): string {
120
+ function handleAndFlushImmediates(eventTimestamp: number, event: T) {
121
+ 'worklet';
122
+ global.__frameTimestamp = eventTimestamp;
123
+ eventHandler(event);
124
+ global.__flushAnimationFrame(eventTimestamp);
125
+ global.__frameTimestamp = undefined;
126
+ }
113
127
  return NativeReanimatedModule.registerEventHandler(
114
128
  eventHash,
115
- makeShareableCloneRecursive(eventHandler)
129
+ makeShareableCloneRecursive(handleAndFlushImmediates)
116
130
  );
117
131
  }
118
132
 
@@ -121,10 +135,22 @@ export function unregisterEventHandler(id: string): void {
121
135
  }
122
136
 
123
137
  export function subscribeForKeyboardEvents(
124
- eventHandler: (state: number, height: number) => void
138
+ eventHandler: (state: number, height: number) => void,
139
+ options: AnimatedKeyboardOptions
125
140
  ): number {
141
+ // TODO: this should really go with the same code path as other events, that is
142
+ // via registerEventHandler. For now we are copying the code from there.
143
+ function handleAndFlushImmediates(state: number, height: number) {
144
+ 'worklet';
145
+ const now = performance.now();
146
+ global.__frameTimestamp = now;
147
+ eventHandler(state, height);
148
+ global.__flushAnimationFrame(now);
149
+ global.__frameTimestamp = undefined;
150
+ }
126
151
  return NativeReanimatedModule.subscribeForKeyboardEvents(
127
- makeShareableCloneRecursive(eventHandler)
152
+ makeShareableCloneRecursive(handleAndFlushImmediates),
153
+ options.isStatusBarTranslucentAndroid ?? false
128
154
  );
129
155
  }
130
156
 
@@ -135,11 +161,16 @@ export function unsubscribeFromKeyboardEvents(listenerId: number): void {
135
161
  export function registerSensor(
136
162
  sensorType: number,
137
163
  interval: number,
138
- eventHandler: (data: Value3D | ValueRotation) => void
164
+ iosReferenceFrame: number,
165
+ eventHandler: (
166
+ data: Value3D | ValueRotation,
167
+ orientationDegrees: number
168
+ ) => void
139
169
  ): number {
140
170
  return NativeReanimatedModule.registerSensor(
141
171
  sensorType,
142
172
  interval,
173
+ iosReferenceFrame,
143
174
  makeShareableCloneRecursive(eventHandler)
144
175
  );
145
176
  }
@@ -184,12 +215,14 @@ export function enableLayoutAnimations(
184
215
 
185
216
  export function configureLayoutAnimations(
186
217
  viewTag: number,
187
- type: string,
188
- config: LayoutAnimationFunction | Keyframe
218
+ type: LayoutAnimationType,
219
+ config: LayoutAnimationFunction | Keyframe,
220
+ sharedTransitionTag = ''
189
221
  ): void {
190
222
  NativeReanimatedModule.configureLayoutAnimation(
191
223
  viewTag,
192
224
  type,
225
+ sharedTransitionTag,
193
226
  makeShareableCloneRecursive(config)
194
227
  );
195
228
  }
@@ -1,4 +1,4 @@
1
- import { runOnUI } from '../core';
1
+ import { runOnUIImmediately } from '../threads';
2
2
 
3
3
  type CallbackDetails = {
4
4
  callback: (frameInfo: FrameInfo) => void;
@@ -24,7 +24,7 @@ export interface FrameCallbackRegistryUI {
24
24
  manageStateFrameCallback: (callbackId: number, state: boolean) => void;
25
25
  }
26
26
 
27
- export const prepareUIRegistry = runOnUI(() => {
27
+ export const prepareUIRegistry = runOnUIImmediately(() => {
28
28
  'worklet';
29
29
 
30
30
  const frameCallbackRegistry: FrameCallbackRegistryUI = {
@@ -15,8 +15,6 @@ declare global {
15
15
  const _WORKLET: boolean;
16
16
  const _IS_FABRIC: boolean;
17
17
  const _REANIMATED_VERSION_CPP: string;
18
- const _frameTimestamp: number | null;
19
- const _eventTimestamp: number;
20
18
  const __reanimatedModuleProxy: NativeReanimated;
21
19
  const evalWithSourceMap: (
22
20
  js: string,
@@ -26,8 +24,11 @@ declare global {
26
24
  const evalWithSourceUrl: (js: string, sourceURL: string) => any;
27
25
  const _log: (s: string) => void;
28
26
  const _getCurrentTime: () => number;
29
- const _getTimestamp: () => number;
30
- const _notifyAboutProgress: (tag: number, value: number) => void;
27
+ const _notifyAboutProgress: (
28
+ tag: number,
29
+ value: number,
30
+ isSharedTransition: boolean
31
+ ) => void;
31
32
  const _notifyAboutEnd: (
32
33
  tag: number,
33
34
  finished: boolean,
@@ -49,9 +50,7 @@ declare global {
49
50
  shadowNodeWrapper: ShadowNodeWrapper,
50
51
  props: StyleProps | AnimatedStyle
51
52
  ) => void;
52
- const _removeShadowNodeFromRegistry: (
53
- shadowNodeWrapper: ShadowNodeWrapper
54
- ) => void;
53
+ const _removeShadowNodeFromRegistry: (viewTag: number) => void;
55
54
  const _measure: (viewTag: number) => MeasuredDimensions;
56
55
  const _scrollTo: (
57
56
  viewTag: number,
@@ -64,7 +63,6 @@ declare global {
64
63
  commandName: string,
65
64
  args: Array<unknown>
66
65
  ) => void;
67
- const _chronoNow: () => number;
68
66
  const performance: { now: () => number };
69
67
  const ReanimatedDataMock: {
70
68
  now: () => number;
@@ -74,6 +72,7 @@ declare global {
74
72
  };
75
73
  const _frameCallbackRegistry: FrameCallbackRegistryUI;
76
74
  const requestAnimationFrame: (callback: (time: number) => void) => number;
75
+ const setImmediate: (callback: (time: number) => void) => number;
77
76
  const console: Console;
78
77
 
79
78
  namespace NodeJS {
@@ -81,9 +80,8 @@ declare global {
81
80
  _WORKLET: boolean;
82
81
  _IS_FABRIC: boolean;
83
82
  _REANIMATED_VERSION_CPP: string;
84
- _frameTimestamp: number | null;
85
- _eventTimestamp: number;
86
83
  __reanimatedModuleProxy: NativeReanimated;
84
+ __frameTimestamp?: number;
87
85
  evalWithSourceMap: (
88
86
  js: string,
89
87
  sourceURL: string,
@@ -92,7 +90,6 @@ declare global {
92
90
  evalWithSourceUrl: (js: string, sourceURL: string) => any;
93
91
  _log: (s: string) => void;
94
92
  _getCurrentTime: () => number;
95
- _getTimestamp: () => number;
96
93
  _setGestureState: (handlerTag: number, newState: number) => void;
97
94
  _makeShareableClone: (value: any) => any;
98
95
  _updateDataSynchronously: (
@@ -109,9 +106,7 @@ declare global {
109
106
  shadowNodeWrapper: ShadowNodeWrapper,
110
107
  props: StyleProps | AnimatedStyle
111
108
  ) => void;
112
- _removeShadowNodeFromRegistry: (
113
- shadowNodeWrapper: ShadowNodeWrapper
114
- ) => void;
109
+ _removeShadowNodeFromRegistry: (viewTag: number) => void;
115
110
  _measure: (viewTag: number) => MeasuredDimensions;
116
111
  _scrollTo: (
117
112
  viewTag: number,
@@ -124,7 +119,6 @@ declare global {
124
119
  commandName: string,
125
120
  args: Array<unknown>
126
121
  ) => void;
127
- _chronoNow: () => number;
128
122
  performance: { now: () => number };
129
123
  LayoutAnimationsManager: {
130
124
  start: LayoutAnimationStartFunction;
@@ -139,7 +133,10 @@ declare global {
139
133
  __workletsCache?: Map<string, (...args: any[]) => any>;
140
134
  __handleCache?: WeakMap<any, any>;
141
135
  __mapperRegistry?: MapperRegistry;
136
+ __flushImmediates: () => void;
137
+ __flushAnimationFrame: (frameTimestamp: number) => void;
142
138
  requestAnimationFrame: (callback: (time: number) => void) => number;
139
+ setImmediate: (callback: (time: number) => void) => number;
143
140
  console: Console;
144
141
  }
145
142
  }
@@ -20,7 +20,7 @@ export { useAnimatedScrollHandler } from './useAnimatedScrollHandler';
20
20
  export type { ScrollHandler, ScrollHandlers } from './useAnimatedScrollHandler';
21
21
  export { useDerivedValue } from './useDerivedValue';
22
22
  export type { DerivedValue } from './useDerivedValue';
23
- export { useAnimatedSensor, SensorType } from './useAnimatedSensor';
23
+ export { useAnimatedSensor } from './useAnimatedSensor';
24
24
  export { useFrameCallback } from './useFrameCallback';
25
25
  export type { FrameCallback } from './useFrameCallback';
26
26
  export { useAnimatedKeyboard } from './useAnimatedKeyboard';
@@ -4,9 +4,15 @@ import {
4
4
  subscribeForKeyboardEvents,
5
5
  unsubscribeFromKeyboardEvents,
6
6
  } from '../core';
7
- import { AnimatedKeyboardInfo, KeyboardState } from '../commonTypes';
7
+ import {
8
+ AnimatedKeyboardInfo,
9
+ AnimatedKeyboardOptions,
10
+ KeyboardState,
11
+ } from '../commonTypes';
8
12
 
9
- export function useAnimatedKeyboard(): AnimatedKeyboardInfo {
13
+ export function useAnimatedKeyboard(
14
+ options: AnimatedKeyboardOptions = { isStatusBarTranslucentAndroid: false }
15
+ ): AnimatedKeyboardInfo {
10
16
  const ref = useRef<AnimatedKeyboardInfo | null>(null);
11
17
  const listenerId = useRef<number>(-1);
12
18
  const isSubscribed = useRef<boolean>(false);
@@ -20,7 +26,7 @@ export function useAnimatedKeyboard(): AnimatedKeyboardInfo {
20
26
  'worklet';
21
27
  keyboardEventData.state.value = state;
22
28
  keyboardEventData.height.value = height;
23
- });
29
+ }, options);
24
30
  ref.current = keyboardEventData;
25
31
  isSubscribed.current = true;
26
32
  }
@@ -32,7 +38,7 @@ export function useAnimatedKeyboard(): AnimatedKeyboardInfo {
32
38
  'worklet';
33
39
  keyboardEventData.state.value = state;
34
40
  keyboardEventData.height.value = height;
35
- });
41
+ }, options);
36
42
  isSubscribed.current = true;
37
43
  }
38
44
  return () => {
@@ -3,6 +3,7 @@ import { BasicWorkletFunction, WorkletFunction } from '../commonTypes';
3
3
  import { startMapper, stopMapper } from '../core';
4
4
  import { DependencyList } from './commonTypes';
5
5
  import { useSharedValue } from './useSharedValue';
6
+ import { shouldBeUseWeb } from '../PlatformChecker';
6
7
 
7
8
  export interface AnimatedReactionWorkletFunction<T> extends WorkletFunction {
8
9
  (prepared: T, previous: T | null): void;
@@ -19,6 +20,16 @@ export function useAnimatedReaction<T>(
19
20
  dependencies: DependencyList
20
21
  ): void {
21
22
  const previous = useSharedValue<T | null>(null);
23
+
24
+ let inputs = Object.values(prepare._closure ?? {});
25
+
26
+ if (shouldBeUseWeb()) {
27
+ if (!inputs.length && dependencies?.length) {
28
+ // let web work without a Babel/SWC plugin
29
+ inputs = dependencies;
30
+ }
31
+ }
32
+
22
33
  if (dependencies === undefined) {
23
34
  dependencies = [
24
35
  Object.values(prepare._closure ?? {}),
@@ -37,11 +48,7 @@ export function useAnimatedReaction<T>(
37
48
  react(input, previous.value);
38
49
  previous.value = input;
39
50
  };
40
- const mapperId = startMapper(
41
- fun,
42
- Object.values(prepare._closure ?? {}),
43
- []
44
- );
51
+ const mapperId = startMapper(fun, inputs, []);
45
52
  return () => {
46
53
  stopMapper(mapperId);
47
54
  };
@@ -6,16 +6,13 @@ import { getTag } from '../NativeMethods';
6
6
  import { getShadowNodeWrapperFromHostInstance } from '../fabricUtils';
7
7
  import {
8
8
  makeShareableCloneRecursive,
9
- makeShareableShadowNodeWrapper,
10
9
  registerShareableMapping,
11
10
  } from '../shareables';
12
11
 
13
12
  function getShareableShadowNodeFromComponent(
14
13
  component: Component
15
14
  ): ShadowNodeWrapper {
16
- return makeShareableShadowNodeWrapper(
17
- getShadowNodeWrapperFromHostInstance(component)
18
- );
15
+ return getShadowNodeWrapperFromHostInstance(component);
19
16
  }
20
17
 
21
18
  const getTagValueFunction = global._IS_FABRIC
@@ -1,17 +1,18 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  import { makeMutable, registerSensor, unregisterSensor } from '../core';
3
- import { SharedValue, Value3D, ValueRotation } from '../commonTypes';
4
-
5
- export enum SensorType {
6
- ACCELEROMETER = 1,
7
- GYROSCOPE = 2,
8
- GRAVITY = 3,
9
- MAGNETIC_FIELD = 4,
10
- ROTATION = 5,
11
- }
3
+ import {
4
+ SensorType,
5
+ SharedValue,
6
+ Value3D,
7
+ ValueRotation,
8
+ IOSReferenceFrame,
9
+ } from '../commonTypes';
10
+ import { flushImmediates } from '../threads';
12
11
 
13
12
  export type SensorConfig = {
14
13
  interval: number | 'auto';
14
+ adjustToInterfaceOrientation: boolean;
15
+ iosReferenceFrame: IOSReferenceFrame;
15
16
  };
16
17
 
17
18
  export type AnimatedSensor = {
@@ -33,19 +34,81 @@ function initSensorData(
33
34
  yaw: 0,
34
35
  pitch: 0,
35
36
  roll: 0,
37
+ interfaceOrientation: 0,
36
38
  });
37
39
  } else {
38
40
  return makeMutable<Value3D | ValueRotation>({
39
41
  x: 0,
40
42
  y: 0,
41
43
  z: 0,
44
+ interfaceOrientation: 0,
42
45
  });
43
46
  }
44
47
  }
45
48
 
49
+ // euler angles are in order ZXY, z = yaw, x = pitch, y = roll
50
+ // https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L237
51
+ function eulerToQuaternion(pitch: number, roll: number, yaw: number) {
52
+ 'worklet';
53
+ const c1 = Math.cos(pitch / 2);
54
+ const s1 = Math.sin(pitch / 2);
55
+ const c2 = Math.cos(roll / 2);
56
+ const s2 = Math.sin(roll / 2);
57
+ const c3 = Math.cos(yaw / 2);
58
+ const s3 = Math.sin(yaw / 2);
59
+
60
+ return [
61
+ s1 * c2 * c3 - c1 * s2 * s3,
62
+ c1 * s2 * c3 + s1 * c2 * s3,
63
+ c1 * c2 * s3 + s1 * s2 * c3,
64
+ c1 * c2 * c3 - s1 * s2 * s3,
65
+ ];
66
+ }
67
+
68
+ function adjustRotationToInterfaceOrientation(data: ValueRotation) {
69
+ 'worklet';
70
+ const { interfaceOrientation, pitch, roll, yaw } = data;
71
+ if (interfaceOrientation === 90) {
72
+ data.pitch = roll;
73
+ data.roll = -pitch;
74
+ data.yaw = yaw - Math.PI / 2;
75
+ } else if (interfaceOrientation === 270) {
76
+ data.pitch = -roll;
77
+ data.roll = pitch;
78
+ data.yaw = yaw + Math.PI / 2;
79
+ } else if (interfaceOrientation === 180) {
80
+ data.pitch *= -1;
81
+ data.roll *= -1;
82
+ data.yaw *= -1;
83
+ }
84
+
85
+ const q = eulerToQuaternion(data.pitch, data.roll, data.yaw);
86
+ data.qx = q[0];
87
+ data.qy = q[1];
88
+ data.qz = q[2];
89
+ data.qw = q[3];
90
+ return data;
91
+ }
92
+
93
+ function adjustVectorToInterfaceOrientation(data: Value3D) {
94
+ 'worklet';
95
+ const { interfaceOrientation, x, y } = data;
96
+ if (interfaceOrientation === 90) {
97
+ data.x = -y;
98
+ data.y = x;
99
+ } else if (interfaceOrientation === 270) {
100
+ data.x = y;
101
+ data.y = -x;
102
+ } else if (interfaceOrientation === 180) {
103
+ data.x *= -1;
104
+ data.y *= -1;
105
+ }
106
+ return data;
107
+ }
108
+
46
109
  export function useAnimatedSensor(
47
110
  sensorType: SensorType,
48
- userConfig?: SensorConfig
111
+ userConfig?: Partial<SensorConfig>
49
112
  ): AnimatedSensor {
50
113
  const ref = useRef<AnimatedSensor>({
51
114
  sensor: initSensorData(sensorType),
@@ -55,18 +118,34 @@ export function useAnimatedSensor(
55
118
  isAvailable: false,
56
119
  config: {
57
120
  interval: 0,
121
+ adjustToInterfaceOrientation: true,
122
+ iosReferenceFrame: IOSReferenceFrame.Auto,
58
123
  },
59
124
  });
60
125
 
61
126
  useEffect(() => {
62
- ref.current.config = { interval: 'auto', ...userConfig };
127
+ ref.current.config = {
128
+ interval: 'auto',
129
+ adjustToInterfaceOrientation: true,
130
+ iosReferenceFrame: IOSReferenceFrame.Auto,
131
+ ...userConfig,
132
+ };
63
133
  const sensorData = ref.current.sensor!;
64
134
  const id = registerSensor(
65
135
  sensorType,
66
136
  ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval,
137
+ ref.current.config.iosReferenceFrame,
67
138
  (data) => {
68
139
  'worklet';
140
+ if (ref.current.config.adjustToInterfaceOrientation) {
141
+ if (sensorType === SensorType.ROTATION) {
142
+ data = adjustRotationToInterfaceOrientation(data as ValueRotation);
143
+ } else {
144
+ data = adjustVectorToInterfaceOrientation(data as Value3D);
145
+ }
146
+ }
69
147
  sensorData.value = data;
148
+ flushImmediates();
70
149
  }
71
150
  );
72
151