react-native-reanimated 2.3.3 → 2.5.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 (249) 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/Tools/RuntimeDecorator.cpp +2 -0
  5. package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
  6. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
  7. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
  8. package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
  9. package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
  10. package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
  11. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
  12. package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
  13. package/LICENSE +1 -1
  14. package/README.md +2 -2
  15. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  16. package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
  17. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  18. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  19. package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
  20. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  21. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  22. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  23. package/android/.gradle/7.2/gc.properties +0 -0
  24. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  25. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  26. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  27. package/android/.gradle/checksums/checksums.lock +0 -0
  28. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  29. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  30. package/android/.gradle/vcs-1/gc.properties +0 -0
  31. package/android/CMakeLists.txt +198 -0
  32. package/android/README.md +15 -0
  33. package/android/build.gradle +686 -73
  34. package/android/empty.cpp +1 -0
  35. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  36. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  37. package/android/gradle.properties +25 -0
  38. package/android/gradlew +234 -0
  39. package/android/gradlew.bat +89 -0
  40. package/android/react-native-reanimated-64-hermes.aar +0 -0
  41. package/android/react-native-reanimated-64-jsc.aar +0 -0
  42. package/android/react-native-reanimated-65-hermes.aar +0 -0
  43. package/android/react-native-reanimated-65-jsc.aar +0 -0
  44. package/android/react-native-reanimated-66-hermes.aar +0 -0
  45. package/android/react-native-reanimated-66-jsc.aar +0 -0
  46. package/android/react-native-reanimated-67-hermes.aar +0 -0
  47. package/android/react-native-reanimated-67-jsc.aar +0 -0
  48. package/android/react-native-reanimated-68-hermes.aar +0 -0
  49. package/android/react-native-reanimated-68-jsc.aar +0 -0
  50. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
  51. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  52. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  53. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  54. package/android/rnVersionPatch/65/.gitkeep +0 -0
  55. package/android/rnVersionPatch/66/.gitkeep +0 -0
  56. package/android/rnVersionPatch/67/.gitkeep +0 -0
  57. package/android/rnVersionPatch/68/.gitkeep +0 -0
  58. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  59. package/android/settings.gradle +1 -0
  60. package/android/spotless.gradle +9 -0
  61. package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
  62. package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
  63. package/android/src/main/cpp/AndroidLogger.cpp +27 -0
  64. package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
  65. package/android/src/main/cpp/JNIHelper.cpp +59 -0
  66. package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
  67. package/android/src/main/cpp/NativeProxy.cpp +327 -0
  68. package/android/src/main/cpp/OnLoad.cpp +17 -0
  69. package/android/src/main/cpp/TurboModule.cpp +44 -0
  70. package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
  71. package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
  72. package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
  73. package/android/src/main/cpp/headers/JNIHelper.h +30 -0
  74. package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
  75. package/android/src/main/cpp/headers/NativeProxy.h +170 -0
  76. package/android/src/main/cpp/headers/TurboModule.h +70 -0
  77. package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
  78. package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
  79. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
  80. package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
  81. package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
  82. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
  83. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
  84. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
  85. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
  86. package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
  87. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
  88. package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
  89. package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
  90. package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
  91. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
  92. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
  93. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
  94. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
  95. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  96. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
  97. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
  98. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
  99. package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
  100. package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
  101. package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
  102. package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
  103. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
  104. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
  105. package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
  106. package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
  107. package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
  108. package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
  109. package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
  110. package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
  111. package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
  112. package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
  113. package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
  114. package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
  115. package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
  116. package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
  117. package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
  118. package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
  119. package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
  120. package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
  121. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
  122. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
  123. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
  124. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
  125. package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
  126. package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
  127. package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
  128. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
  129. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
  130. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  131. package/ios/LayoutReanimation/REAAnimationsManager.m +18 -4
  132. package/ios/REAModule.m +8 -9
  133. package/ios/REANodesManager.h +4 -1
  134. package/ios/REANodesManager.m +75 -3
  135. package/ios/native/NativeMethods.h +1 -1
  136. package/ios/native/NativeProxy.mm +85 -5
  137. package/ios/sensor/ReanimatedSensor.h +21 -0
  138. package/ios/sensor/ReanimatedSensor.m +169 -0
  139. package/ios/sensor/ReanimatedSensorContainer.h +13 -0
  140. package/ios/sensor/ReanimatedSensorContainer.m +41 -0
  141. package/ios/sensor/ReanimatedSensorType.h +7 -0
  142. package/lib/ConfigHelper.js +2 -2
  143. package/lib/createAnimatedComponent.js +3 -4
  144. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  145. package/lib/reanimated1/derived/interpolate.js +2 -4
  146. package/lib/reanimated2/Colors.js +3 -98
  147. package/lib/reanimated2/Easing.js +5 -0
  148. package/lib/reanimated2/NativeMethods.js +15 -5
  149. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
  150. package/lib/reanimated2/NativeReanimated/index.js +2 -6
  151. package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
  152. package/lib/reanimated2/animation/styleAnimation.js +2 -1
  153. package/lib/reanimated2/core.js +30 -24
  154. package/lib/reanimated2/globals.d.ts +6 -0
  155. package/lib/reanimated2/hook/index.js +1 -0
  156. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
  157. package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
  158. package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
  159. package/lib/reanimated2/hook/utils.js +14 -11
  160. package/lib/reanimated2/index.js +2 -0
  161. package/lib/reanimated2/interpolateColor.js +98 -0
  162. package/lib/reanimated2/interpolation.js +1 -1
  163. package/lib/reanimated2/jestUtils.js +9 -4
  164. package/lib/reanimated2/js-reanimated/JSReanimated.js +24 -3
  165. package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
  166. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
  167. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
  168. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
  169. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
  170. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
  171. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
  172. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
  173. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  174. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
  175. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
  176. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
  177. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
  178. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
  179. package/lib/reanimated2/mock.js +3 -2
  180. package/mock.js +6 -4
  181. package/package.json +44 -36
  182. package/plugin.js +3 -0
  183. package/react-native-reanimated.d.ts +102 -15
  184. package/src/ConfigHelper.ts +4 -4
  185. package/src/createAnimatedComponent.tsx +3 -3
  186. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  187. package/src/reanimated1/derived/interpolate.js +2 -4
  188. package/src/reanimated2/Colors.ts +8 -151
  189. package/src/reanimated2/Easing.ts +11 -0
  190. package/src/reanimated2/NativeMethods.ts +19 -6
  191. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -14
  192. package/src/reanimated2/NativeReanimated/index.ts +2 -8
  193. package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
  194. package/src/reanimated2/animation/commonTypes.ts +44 -40
  195. package/src/reanimated2/animation/decay.ts +1 -1
  196. package/src/reanimated2/animation/delay.ts +2 -16
  197. package/src/reanimated2/animation/index.ts +8 -8
  198. package/src/reanimated2/animation/repeat.ts +2 -12
  199. package/src/reanimated2/animation/sequence.ts +3 -10
  200. package/src/reanimated2/animation/spring.ts +1 -1
  201. package/src/reanimated2/animation/styleAnimation.ts +11 -25
  202. package/src/reanimated2/animation/timing.ts +4 -2
  203. package/src/reanimated2/animation/util.ts +22 -20
  204. package/src/reanimated2/commonTypes.ts +68 -1
  205. package/src/reanimated2/component/FlatList.tsx +2 -1
  206. package/src/reanimated2/core.ts +35 -29
  207. package/src/reanimated2/globals.d.ts +6 -0
  208. package/src/reanimated2/hook/commonTypes.ts +5 -0
  209. package/src/reanimated2/hook/index.ts +1 -0
  210. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
  211. package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
  212. package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
  213. package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
  214. package/src/reanimated2/hook/utils.ts +20 -18
  215. package/src/reanimated2/index.ts +2 -0
  216. package/src/reanimated2/interpolateColor.ts +178 -0
  217. package/src/reanimated2/interpolation.ts +2 -6
  218. package/src/reanimated2/jestUtils.ts +9 -4
  219. package/src/reanimated2/js-reanimated/JSReanimated.ts +28 -6
  220. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  221. package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
  222. package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
  223. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
  224. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
  225. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
  226. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
  227. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
  228. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
  229. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
  230. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
  231. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
  232. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
  233. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
  234. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
  235. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
  236. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +32 -21
  237. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
  238. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
  239. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
  240. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
  241. package/src/reanimated2/mock.ts +3 -2
  242. package/src/reanimated2/utils.ts +1 -1
  243. package/android/react-native-reanimated-63-hermes.aar +0 -0
  244. package/android/react-native-reanimated-63-jsc.aar +0 -0
  245. package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
  246. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  247. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  248. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  249. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
@@ -9,11 +9,8 @@
9
9
  /* eslint no-bitwise: 0 */
10
10
  import { Platform } from 'react-native';
11
11
  import { makeRemote, makeShareable, isConfigured } from './core';
12
- import { interpolate } from './interpolation';
13
- // @ts-ignore JS file
14
- import { Extrapolate } from '../reanimated1/derived';
15
12
 
16
- interface RBG {
13
+ interface RGB {
17
14
  r: number;
18
15
  g: number;
19
16
  b: number;
@@ -67,7 +64,8 @@ function getMatchers(): Matchers {
67
64
  'hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)
68
65
  );
69
66
  cachedMatchers.hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
70
- cachedMatchers.hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
67
+ cachedMatchers.hex4 =
68
+ /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
71
69
  cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
72
70
  cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
73
71
  }
@@ -475,9 +473,9 @@ export const rgbaColor = (
475
473
  * 0 <= r, g, b <= 255
476
474
  * returns 0 <= h, s, v <= 1
477
475
  */
478
- function RGBtoHSV(rgb: RBG): HSV;
479
- function RGBtoHSV(r: number, g: number, b: number): HSV;
480
- function RGBtoHSV(r: any, g?: any, b?: any): HSV {
476
+ export function RGBtoHSV(rgb: RGB): HSV;
477
+ export function RGBtoHSV(r: number, g: number, b: number): HSV;
478
+ export function RGBtoHSV(r: any, g?: any, b?: any): HSV {
481
479
  'worklet';
482
480
  /* eslint-disable */
483
481
  if (arguments.length === 1) {
@@ -528,8 +526,8 @@ function RGBtoHSV(r: any, g?: any, b?: any): HSV {
528
526
  * 0 <= h, s, v <= 1
529
527
  * returns 0 <= r, g, b <= 255
530
528
  */
531
- function HSVtoRGB(hsv: HSV): RBG;
532
- function HSVtoRGB(h: number, s: number, v: number): RBG;
529
+ function HSVtoRGB(hsv: HSV): RGB;
530
+ function HSVtoRGB(h: number, s: number, v: number): RGB;
533
531
  function HSVtoRGB(h: any, s?: any, v?: any) {
534
532
  'worklet';
535
533
  /* eslint-disable */
@@ -652,144 +650,3 @@ export function toRGBA(HSVA: ParsedColorArray): string {
652
650
  const { r, g, b } = HSVtoRGB(HSVA[0], HSVA[1], HSVA[2]);
653
651
  return `rgba(${r}, ${g}, ${b}, ${HSVA[3]})`;
654
652
  }
655
-
656
- const interpolateColorsHSV = (
657
- value: number,
658
- inputRange: readonly number[],
659
- colors: InterpolateCacheHSV
660
- ) => {
661
- 'worklet';
662
- const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
663
- const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
664
- const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
665
- return hsvToColor(h, s, v);
666
- };
667
-
668
- const interpolateColorsRGB = (
669
- value: number,
670
- inputRange: readonly number[],
671
- colors: InterpolateCacheRGBA
672
- ) => {
673
- 'worklet';
674
- const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);
675
- const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);
676
- const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);
677
- const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
678
- return rgbaColor(r, g, b, a);
679
- };
680
-
681
- interface InterpolateCacheRGBA {
682
- r: number[];
683
- g: number[];
684
- b: number[];
685
- a: number[];
686
- }
687
-
688
- const BUFFER_SIZE = 200;
689
- const hashOrderRGBA: any = new ArrayBuffer(BUFFER_SIZE);
690
- let curentHashIndexRGBA = 0;
691
- const interpolateCacheRGBA: { [name: string]: InterpolateCacheRGBA } = {};
692
-
693
- const getInterpolateCacheRGBA = (
694
- colors: readonly (string | number)[]
695
- ): InterpolateCacheRGBA => {
696
- 'worklet';
697
- const hash = colors.join('');
698
- const cache = interpolateCacheRGBA[hash];
699
- if (cache !== undefined) {
700
- return cache;
701
- }
702
-
703
- const r = [];
704
- const g = [];
705
- const b = [];
706
- const a = [];
707
- for (let i = 0; i < colors.length; ++i) {
708
- const color = colors[i];
709
- const proocessedColor = processColor(color);
710
- // explicit check in case if processedColor is 0
711
- if (proocessedColor !== null && proocessedColor !== undefined) {
712
- r.push(red(proocessedColor));
713
- g.push(green(proocessedColor));
714
- b.push(blue(proocessedColor));
715
- a.push(opacity(proocessedColor));
716
- }
717
- }
718
- const newCache = { r, g, b, a };
719
- const overrideHash = hashOrderRGBA[curentHashIndexRGBA];
720
- if (overrideHash) {
721
- delete interpolateCacheRGBA[overrideHash];
722
- }
723
- interpolateCacheRGBA[hash] = newCache;
724
- hashOrderRGBA[curentHashIndexRGBA] = hash;
725
- curentHashIndexRGBA = (curentHashIndexRGBA + 1) % BUFFER_SIZE;
726
- return newCache;
727
- };
728
-
729
- interface InterpolateCacheHSV {
730
- h: number[];
731
- s: number[];
732
- v: number[];
733
- }
734
-
735
- const hashOrderHSV: any = new ArrayBuffer(BUFFER_SIZE);
736
- let curentHashIndexHSV = 0;
737
- const interpolateCacheHSV: { [name: string]: InterpolateCacheHSV } = {};
738
-
739
- const getInterpolateCacheHSV = (
740
- colors: readonly (string | number)[]
741
- ): InterpolateCacheHSV => {
742
- 'worklet';
743
- const hash = colors.join('');
744
- const cache = interpolateCacheHSV[hash];
745
- if (cache !== undefined) {
746
- return cache;
747
- }
748
-
749
- const h = [];
750
- const s = [];
751
- const v = [];
752
- for (let i = 0; i < colors.length; ++i) {
753
- const color = colors[i];
754
- const proocessedColor = RGBtoHSV(processColor(color) as any);
755
- if (proocessedColor) {
756
- h.push(proocessedColor.h);
757
- s.push(proocessedColor.s);
758
- v.push(proocessedColor.v);
759
- }
760
- }
761
- const newCache = { h, s, v };
762
- const overrideHash = hashOrderHSV[curentHashIndexHSV];
763
- if (overrideHash) {
764
- delete interpolateCacheHSV[overrideHash];
765
- }
766
- interpolateCacheHSV[hash] = newCache;
767
- hashOrderHSV[curentHashIndexHSV] = hash;
768
- curentHashIndexHSV = (curentHashIndexHSV + 1) % BUFFER_SIZE;
769
- return newCache;
770
- };
771
-
772
- export const interpolateColor = (
773
- value: number,
774
- inputRange: readonly number[],
775
- outputRange: readonly (string | number)[],
776
- colorSpace: 'RGB' | 'HSV' = 'RGB'
777
- ): string | number => {
778
- 'worklet';
779
- if (colorSpace === 'HSV') {
780
- return interpolateColorsHSV(
781
- value,
782
- inputRange,
783
- getInterpolateCacheHSV(outputRange)
784
- );
785
- } else if (colorSpace === 'RGB') {
786
- return interpolateColorsRGB(
787
- value,
788
- inputRange,
789
- getInterpolateCacheRGBA(outputRange)
790
- );
791
- }
792
- throw new Error(
793
- `invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`
794
- );
795
- };
@@ -221,6 +221,16 @@ function bezier(
221
221
  };
222
222
  }
223
223
 
224
+ function bezierFn(
225
+ x1: number,
226
+ y1: number,
227
+ x2: number,
228
+ y2: number
229
+ ): (x: number) => number {
230
+ 'worklet';
231
+ return Bezier(x1, y1, x2, y2);
232
+ }
233
+
224
234
  /**
225
235
  * Runs an easing function forwards.
226
236
  */
@@ -269,6 +279,7 @@ const EasingObject = {
269
279
  back,
270
280
  bounce,
271
281
  bezier,
282
+ bezierFn,
272
283
  in: in_,
273
284
  out,
274
285
  inOut,
@@ -3,8 +3,8 @@
3
3
  // @ts-nocheck
4
4
  import { Component } from 'react';
5
5
  import { findNodeHandle } from 'react-native';
6
- import { RefObjectFunction } from './hook/useAnimatedRef';
7
- import { isChromeDebugger } from './PlatformChecker';
6
+ import { RefObjectFunction } from './commonTypes';
7
+ import { shouldBeUseWeb } from './PlatformChecker';
8
8
 
9
9
  export function getTag(
10
10
  view: null | number | React.Component<any, any> | React.ComponentClass<any>
@@ -21,12 +21,24 @@ export interface MeasuredDimensions {
21
21
  pageY: number;
22
22
  }
23
23
 
24
+ const isNativeIndefined = shouldBeUseWeb();
25
+
24
26
  export function measure(
25
27
  animatedRef: RefObjectFunction<Component>
26
28
  ): MeasuredDimensions {
27
29
  'worklet';
28
- if (!_WORKLET && !isChromeDebugger()) {
29
- throw new Error('(measure) method cannot be used on RN side!');
30
+ if (!_WORKLET || isNativeIndefined) {
31
+ console.warn(
32
+ '[reanimated.measure] method cannot be used for web or Chrome Debugger'
33
+ );
34
+ return {
35
+ x: NaN,
36
+ y: NaN,
37
+ width: NaN,
38
+ height: NaN,
39
+ pageX: NaN,
40
+ pageY: NaN,
41
+ };
30
42
  }
31
43
  const viewTag = animatedRef();
32
44
  const result = _measure(viewTag);
@@ -43,7 +55,7 @@ export function scrollTo(
43
55
  animated: boolean
44
56
  ): void {
45
57
  'worklet';
46
- if (!_WORKLET && !isChromeDebugger()) {
58
+ if (!_WORKLET || isNativeIndefined) {
47
59
  return;
48
60
  }
49
61
  const viewTag = animatedRef();
@@ -52,10 +64,11 @@ export function scrollTo(
52
64
 
53
65
  export function setGestureState(handlerTag: number, newState: number): void {
54
66
  'worklet';
55
- if (!_WORKLET && !isChromeDebugger()) {
67
+ if (!_WORKLET || isNativeIndefined) {
56
68
  console.warn(
57
69
  '[Reanimated] You can not use setGestureState in non-worklet function.'
58
70
  );
71
+ return;
59
72
  }
60
73
  _setGestureState(handlerTag, newState);
61
74
  }
@@ -1,30 +1,54 @@
1
- import { SharedValue } from '../commonTypes';
1
+ import { NativeModules } from 'react-native';
2
+ import {
3
+ SharedValue,
4
+ SensorValue3D,
5
+ SensorValueRotation,
6
+ } from '../commonTypes';
2
7
  import { Descriptor } from '../hook/commonTypes';
3
8
 
4
- const InnerNativeModule = global.__reanimatedModuleProxy;
5
9
  export class NativeReanimated {
6
10
  native: boolean;
7
- useOnlyV1: boolean;
11
+ private InnerNativeModule: any;
8
12
 
9
13
  constructor(native = true) {
14
+ if (global.__reanimatedModuleProxy === undefined) {
15
+ const { ReanimatedModule } = NativeModules;
16
+ ReanimatedModule?.installTurboModule();
17
+ }
18
+ this.InnerNativeModule = global.__reanimatedModuleProxy;
10
19
  this.native = native;
11
- this.useOnlyV1 = InnerNativeModule === null;
12
20
  }
13
21
 
14
22
  installCoreFunctions(valueSetter: <T>(value: T) => void): void {
15
- return InnerNativeModule.installCoreFunctions(valueSetter);
23
+ return this.InnerNativeModule.installCoreFunctions(valueSetter);
16
24
  }
17
25
 
18
26
  makeShareable<T>(value: T): T {
19
- return InnerNativeModule.makeShareable(value);
27
+ return this.InnerNativeModule.makeShareable(value);
20
28
  }
21
29
 
22
30
  makeMutable<T>(value: T): SharedValue<T> {
23
- return InnerNativeModule.makeMutable(value);
31
+ return this.InnerNativeModule.makeMutable(value);
24
32
  }
25
33
 
26
34
  makeRemote<T>(object = {}): T {
27
- return InnerNativeModule.makeRemote(object);
35
+ return this.InnerNativeModule.makeRemote(object);
36
+ }
37
+
38
+ registerSensor(
39
+ sensorType: number,
40
+ interval: number,
41
+ sensorData: SensorValue3D | SensorValueRotation
42
+ ) {
43
+ return this.InnerNativeModule.registerSensor(
44
+ sensorType,
45
+ interval,
46
+ sensorData
47
+ );
48
+ }
49
+
50
+ unregisterSensor(sensorId: number) {
51
+ return this.InnerNativeModule.unregisterSensor(sensorId);
28
52
  }
29
53
 
30
54
  startMapper(
@@ -34,7 +58,7 @@ export class NativeReanimated {
34
58
  updater: () => void,
35
59
  viewDescriptors: Descriptor[] | SharedValue<Descriptor[]>
36
60
  ): number {
37
- return InnerNativeModule.startMapper(
61
+ return this.InnerNativeModule.startMapper(
38
62
  mapper,
39
63
  inputs,
40
64
  outputs,
@@ -44,18 +68,18 @@ export class NativeReanimated {
44
68
  }
45
69
 
46
70
  stopMapper(mapperId: number): void {
47
- return InnerNativeModule.stopMapper(mapperId);
71
+ return this.InnerNativeModule.stopMapper(mapperId);
48
72
  }
49
73
 
50
74
  registerEventHandler<T>(
51
75
  eventHash: string,
52
76
  eventHandler: (event: T) => void
53
77
  ): string {
54
- return InnerNativeModule.registerEventHandler(eventHash, eventHandler);
78
+ return this.InnerNativeModule.registerEventHandler(eventHash, eventHandler);
55
79
  }
56
80
 
57
81
  unregisterEventHandler(id: string): void {
58
- return InnerNativeModule.unregisterEventHandler(id);
82
+ return this.InnerNativeModule.unregisterEventHandler(id);
59
83
  }
60
84
 
61
85
  getViewProp<T>(
@@ -63,10 +87,14 @@ export class NativeReanimated {
63
87
  propName: string,
64
88
  callback?: (result: T) => void
65
89
  ): Promise<T> {
66
- return InnerNativeModule.getViewProp(viewTag, propName, callback);
90
+ return this.InnerNativeModule.getViewProp(viewTag, propName, callback);
67
91
  }
68
92
 
69
93
  enableLayoutAnimations(flag: boolean): void {
70
- InnerNativeModule.enableLayoutAnimations(flag);
94
+ this.InnerNativeModule.enableLayoutAnimations(flag);
95
+ }
96
+
97
+ configureProps(uiProps: string[], nativeProps: string[]): void {
98
+ this.InnerNativeModule.configureProps(uiProps, nativeProps);
71
99
  }
72
100
  }
@@ -1,18 +1,12 @@
1
1
  import reanimatedJS from '../js-reanimated';
2
- import { nativeShouldBeMock } from '../PlatformChecker';
3
- import { Platform } from 'react-native';
2
+ import { shouldBeUseWeb } from '../PlatformChecker';
4
3
  import { NativeReanimated } from './NativeReanimated';
5
4
 
6
5
  let exportedModule;
7
- if (nativeShouldBeMock()) {
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,48 +1,52 @@
1
- export type AnimatableValue = number | string | Array<number>;
1
+ import {
2
+ AnimatedStyle,
3
+ StyleProps,
4
+ AnimatableValue,
5
+ AnimationObject,
6
+ Animation,
7
+ Timestamp,
8
+ AnimationCallback,
9
+ } from '../commonTypes';
2
10
 
3
- export interface AnimationObject {
4
- [key: string]: any;
5
- callback: AnimationCallback;
6
- current?: AnimatableValue;
7
- toValue?: AnimationObject['current'];
8
- startValue?: AnimationObject['current'];
9
- finished?: boolean;
10
- strippedCurrent?: number;
11
- cancelled?: boolean;
12
-
13
- __prefix?: string;
14
- __suffix?: string;
15
- onFrame: (animation: any, timestamp: Timestamp) => boolean;
16
- onStart: (
17
- nextAnimation: any,
18
- current: any,
19
- timestamp: Timestamp,
20
- previousAnimation: any
21
- ) => void;
11
+ export interface HigherOrderAnimation {
12
+ isHigherOrder?: boolean;
22
13
  }
23
14
 
24
- export interface Animation<T extends AnimationObject> extends AnimationObject {
25
- onFrame: (animation: T, timestamp: Timestamp) => boolean;
26
- onStart: (
27
- nextAnimation: T,
28
- current: T extends NumericAnimation ? number : AnimatableValue,
29
- timestamp: Timestamp,
30
- previousAnimation: T
31
- ) => void;
32
- }
15
+ export type NextAnimation<T extends AnimationObject> = T | (() => T);
33
16
 
34
- export interface NumericAnimation {
35
- current?: number;
36
- }
37
- export interface HigherOrderAnimation {
38
- isHigherOrder?: boolean;
17
+ export interface DelayAnimation
18
+ extends Animation<DelayAnimation>,
19
+ HigherOrderAnimation {
20
+ startTime: Timestamp;
21
+ started: boolean;
22
+ previousAnimation: DelayAnimation | null;
23
+ current: AnimatableValue;
39
24
  }
40
25
 
41
- export type AnimationCallback = (
42
- finished?: boolean,
43
- current?: AnimatableValue
44
- ) => void;
26
+ export interface RepeatAnimation
27
+ extends Animation<RepeatAnimation>,
28
+ HigherOrderAnimation {
29
+ reps: number;
30
+ startValue: AnimatableValue;
31
+ toValue?: AnimatableValue;
32
+ previousAnimation?: RepeatAnimation;
33
+ }
45
34
 
46
- export type NextAnimation<T extends AnimationObject> = T | (() => T);
35
+ export interface SequenceAnimation
36
+ extends Animation<SequenceAnimation>,
37
+ HigherOrderAnimation {
38
+ animationIndex: number;
39
+ }
47
40
 
48
- export type Timestamp = number;
41
+ export interface StyleLayoutAnimation extends HigherOrderAnimation {
42
+ current: StyleProps;
43
+ styleAnimations: AnimatedStyle;
44
+ onFrame: (animation: StyleLayoutAnimation, timestamp: Timestamp) => boolean;
45
+ onStart: (
46
+ nextAnimation: StyleLayoutAnimation,
47
+ current: AnimatedStyle,
48
+ timestamp: Timestamp,
49
+ previousAnimation: StyleLayoutAnimation
50
+ ) => void;
51
+ callback?: AnimationCallback;
52
+ }
@@ -5,7 +5,7 @@ import {
5
5
  AnimationObject,
6
6
  AnimatableValue,
7
7
  Timestamp,
8
- } from './commonTypes';
8
+ } from '../commonTypes';
9
9
  import { Platform } from 'react-native';
10
10
 
11
11
  interface DecayConfig {
@@ -1,20 +1,6 @@
1
1
  import { defineAnimation } from './util';
2
- import {
3
- Animation,
4
- NextAnimation,
5
- Timestamp,
6
- HigherOrderAnimation,
7
- AnimatableValue,
8
- } from './commonTypes';
9
-
10
- export interface DelayAnimation
11
- extends Animation<DelayAnimation>,
12
- HigherOrderAnimation {
13
- startTime: Timestamp;
14
- started: boolean;
15
- previousAnimation: DelayAnimation | null;
16
- current: AnimatableValue;
17
- }
2
+ import { Animation, Timestamp, AnimatableValue } from '../commonTypes';
3
+ import { NextAnimation, DelayAnimation } from './commonTypes';
18
4
 
19
5
  export function withDelay(
20
6
  delayMs: number,
@@ -1,16 +1,16 @@
1
1
  export {
2
- AnimationObject,
3
- Animation,
4
2
  HigherOrderAnimation,
5
- AnimationCallback,
6
3
  NextAnimation,
7
- Timestamp,
4
+ DelayAnimation,
5
+ RepeatAnimation,
6
+ SequenceAnimation,
7
+ StyleLayoutAnimation,
8
8
  } from './commonTypes';
9
9
  export { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';
10
10
  export { withTiming, TimingAnimation } from './timing';
11
11
  export { withSpring, SpringAnimation } from './spring';
12
12
  export { withDecay, DecayAnimation } from './decay';
13
- export { withDelay, DelayAnimation } from './delay';
14
- export { withRepeat, RepeatAnimation } from './repeat';
15
- export { withSequence, SequenceAnimation } from './sequence';
16
- export { withStyleAnimation, StyleLayoutAnimation } from './styleAnimation';
13
+ export { withDelay } from './delay';
14
+ export { withRepeat } from './repeat';
15
+ export { withSequence } from './sequence';
16
+ export { withStyleAnimation } from './styleAnimation';
@@ -2,20 +2,10 @@ import { defineAnimation } from './util';
2
2
  import {
3
3
  Animation,
4
4
  AnimationCallback,
5
- NextAnimation,
6
5
  AnimatableValue,
7
6
  Timestamp,
8
- HigherOrderAnimation,
9
- } from './commonTypes';
10
-
11
- export interface RepeatAnimation
12
- extends Animation<RepeatAnimation>,
13
- HigherOrderAnimation {
14
- reps: number;
15
- startValue: AnimatableValue;
16
- toValue?: AnimatableValue;
17
- previousAnimation?: RepeatAnimation;
18
- }
7
+ } from '../commonTypes';
8
+ import { NextAnimation, RepeatAnimation } from './commonTypes';
19
9
 
20
10
  export interface InnerRepeatAnimation
21
11
  extends Omit<RepeatAnimation, 'toValue' | 'startValue'> {
@@ -1,18 +1,11 @@
1
1
  import { defineAnimation } from './util';
2
+ import { NextAnimation, SequenceAnimation } from './commonTypes';
2
3
  import {
3
4
  Animation,
4
- Timestamp,
5
- NextAnimation,
6
5
  AnimatableValue,
7
- HigherOrderAnimation,
8
6
  AnimationObject,
9
- } from './commonTypes';
10
-
11
- export interface SequenceAnimation
12
- extends Animation<SequenceAnimation>,
13
- HigherOrderAnimation {
14
- animationIndex: number;
15
- }
7
+ Timestamp,
8
+ } from '../commonTypes';
16
9
 
17
10
  export function withSequence(
18
11
  ..._animations: NextAnimation<AnimationObject>[]
@@ -4,7 +4,7 @@ import {
4
4
  AnimationCallback,
5
5
  AnimatableValue,
6
6
  Timestamp,
7
- } from './commonTypes';
7
+ } from '../commonTypes';
8
8
 
9
9
  interface SpringConfig {
10
10
  mass?: number;