react-native-reanimated 2.4.1 → 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 (220) 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/README.md +2 -2
  14. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  15. package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
  16. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  17. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  18. package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
  19. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  20. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  21. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  22. package/android/.gradle/7.2/gc.properties +0 -0
  23. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  24. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  25. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  26. package/android/.gradle/checksums/checksums.lock +0 -0
  27. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  28. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  29. package/android/.gradle/vcs-1/gc.properties +0 -0
  30. package/android/CMakeLists.txt +198 -0
  31. package/android/README.md +15 -0
  32. package/android/build.gradle +686 -73
  33. package/android/empty.cpp +1 -0
  34. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  35. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  36. package/android/gradle.properties +25 -0
  37. package/android/gradlew +234 -0
  38. package/android/gradlew.bat +89 -0
  39. package/android/react-native-reanimated-64-hermes.aar +0 -0
  40. package/android/react-native-reanimated-64-jsc.aar +0 -0
  41. package/android/react-native-reanimated-65-hermes.aar +0 -0
  42. package/android/react-native-reanimated-65-jsc.aar +0 -0
  43. package/android/react-native-reanimated-66-hermes.aar +0 -0
  44. package/android/react-native-reanimated-66-jsc.aar +0 -0
  45. package/android/react-native-reanimated-67-hermes.aar +0 -0
  46. package/android/react-native-reanimated-67-jsc.aar +0 -0
  47. package/android/react-native-reanimated-68-hermes.aar +0 -0
  48. package/android/react-native-reanimated-68-jsc.aar +0 -0
  49. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
  50. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  51. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  52. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  53. package/android/rnVersionPatch/65/.gitkeep +0 -0
  54. package/android/rnVersionPatch/66/.gitkeep +0 -0
  55. package/android/rnVersionPatch/67/.gitkeep +0 -0
  56. package/android/rnVersionPatch/68/.gitkeep +0 -0
  57. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  58. package/android/settings.gradle +1 -0
  59. package/android/spotless.gradle +9 -0
  60. package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
  61. package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
  62. package/android/src/main/cpp/AndroidLogger.cpp +27 -0
  63. package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
  64. package/android/src/main/cpp/JNIHelper.cpp +59 -0
  65. package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
  66. package/android/src/main/cpp/NativeProxy.cpp +327 -0
  67. package/android/src/main/cpp/OnLoad.cpp +17 -0
  68. package/android/src/main/cpp/TurboModule.cpp +44 -0
  69. package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
  70. package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
  71. package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
  72. package/android/src/main/cpp/headers/JNIHelper.h +30 -0
  73. package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
  74. package/android/src/main/cpp/headers/NativeProxy.h +170 -0
  75. package/android/src/main/cpp/headers/TurboModule.h +70 -0
  76. package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
  77. package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
  78. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
  79. package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
  80. package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
  81. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
  82. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
  83. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
  84. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
  85. package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
  86. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
  87. package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
  88. package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
  89. package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
  90. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
  91. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
  92. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
  93. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
  94. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  95. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
  96. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
  97. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
  98. package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
  99. package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
  100. package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
  101. package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
  102. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
  103. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
  104. package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
  105. package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
  106. package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
  107. package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
  108. package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
  109. package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
  110. package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
  111. package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
  112. package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
  113. package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
  114. package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
  115. package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
  116. package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
  117. package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
  118. package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
  119. package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
  120. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
  121. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
  122. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
  123. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
  124. package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
  125. package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
  126. package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
  127. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
  128. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
  129. package/ios/LayoutReanimation/REAAnimationsManager.m +14 -4
  130. package/ios/REAModule.m +8 -9
  131. package/ios/REANodesManager.h +4 -1
  132. package/ios/REANodesManager.m +75 -3
  133. package/ios/native/NativeProxy.mm +76 -4
  134. package/ios/sensor/ReanimatedSensor.h +21 -0
  135. package/ios/sensor/ReanimatedSensor.m +169 -0
  136. package/ios/sensor/ReanimatedSensorContainer.h +13 -0
  137. package/ios/sensor/ReanimatedSensorContainer.m +41 -0
  138. package/ios/sensor/ReanimatedSensorType.h +7 -0
  139. package/lib/ConfigHelper.js +2 -2
  140. package/lib/createAnimatedComponent.js +3 -4
  141. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  142. package/lib/reanimated1/derived/interpolate.js +2 -4
  143. package/lib/reanimated2/Colors.js +2 -1
  144. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
  145. package/lib/reanimated2/NativeReanimated/index.js +0 -4
  146. package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
  147. package/lib/reanimated2/animation/styleAnimation.js +2 -1
  148. package/lib/reanimated2/core.js +30 -24
  149. package/lib/reanimated2/globals.d.ts +6 -0
  150. package/lib/reanimated2/hook/index.js +1 -0
  151. package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
  152. package/lib/reanimated2/interpolation.js +1 -1
  153. package/lib/reanimated2/jestUtils.js +9 -4
  154. package/lib/reanimated2/js-reanimated/JSReanimated.js +23 -2
  155. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
  156. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
  157. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
  158. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
  159. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
  160. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
  161. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
  162. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  163. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
  164. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
  165. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
  166. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
  167. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
  168. package/lib/reanimated2/mock.js +3 -2
  169. package/mock.js +4 -4
  170. package/package.json +42 -36
  171. package/plugin.js +2 -0
  172. package/react-native-reanimated.d.ts +41 -12
  173. package/src/ConfigHelper.ts +4 -4
  174. package/src/createAnimatedComponent.tsx +3 -3
  175. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  176. package/src/reanimated1/derived/interpolate.js +2 -4
  177. package/src/reanimated2/Colors.ts +2 -1
  178. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -15
  179. package/src/reanimated2/NativeReanimated/index.ts +0 -6
  180. package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
  181. package/src/reanimated2/animation/index.ts +1 -0
  182. package/src/reanimated2/animation/styleAnimation.ts +10 -7
  183. package/src/reanimated2/animation/timing.ts +3 -1
  184. package/src/reanimated2/animation/util.ts +10 -11
  185. package/src/reanimated2/commonTypes.ts +20 -0
  186. package/src/reanimated2/component/FlatList.tsx +2 -1
  187. package/src/reanimated2/core.ts +34 -26
  188. package/src/reanimated2/globals.d.ts +6 -0
  189. package/src/reanimated2/hook/index.ts +1 -0
  190. package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
  191. package/src/reanimated2/hook/utils.ts +2 -1
  192. package/src/reanimated2/interpolation.ts +2 -6
  193. package/src/reanimated2/jestUtils.ts +9 -4
  194. package/src/reanimated2/js-reanimated/JSReanimated.ts +25 -2
  195. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
  196. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
  197. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
  198. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
  199. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
  200. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
  201. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
  202. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
  203. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
  204. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
  205. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
  206. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
  207. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
  208. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +26 -19
  209. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
  210. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
  211. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
  212. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
  213. package/src/reanimated2/mock.ts +3 -2
  214. package/android/react-native-reanimated-63-hermes.aar +0 -0
  215. package/android/react-native-reanimated-63-jsc.aar +0 -0
  216. package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
  217. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  218. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  219. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  220. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
@@ -128,15 +128,13 @@ export default function interpolate(value, config) {
128
128
  const right = extrapolateRight || extrapolate;
129
129
  let output = interpolateInternal(value, inputRange, outputRange);
130
130
 
131
- if (left === Extrapolate.EXTEND) {
132
- } else if (left === Extrapolate.CLAMP) {
131
+ if (left === Extrapolate.CLAMP) {
133
132
  output = cond(lessThan(value, inputRange[0]), outputRange[0], output);
134
133
  } else if (left === Extrapolate.IDENTITY) {
135
134
  output = cond(lessThan(value, inputRange[0]), value, output);
136
135
  }
137
136
 
138
- if (right === Extrapolate.EXTEND) {
139
- } else if (right === Extrapolate.CLAMP) {
137
+ if (right === Extrapolate.CLAMP) {
140
138
  output = cond(
141
139
  greaterThan(value, inputRange[inputRange.length - 1]),
142
140
  outputRange[outputRange.length - 1],
@@ -64,7 +64,8 @@ function getMatchers(): Matchers {
64
64
  'hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)
65
65
  );
66
66
  cachedMatchers.hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
67
- 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})$/;
68
69
  cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
69
70
  cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
70
71
  }
@@ -1,31 +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
-
6
9
  export class NativeReanimated {
7
10
  native: boolean;
8
- useOnlyV1: boolean;
11
+ private InnerNativeModule: any;
9
12
 
10
13
  constructor(native = true) {
14
+ if (global.__reanimatedModuleProxy === undefined) {
15
+ const { ReanimatedModule } = NativeModules;
16
+ ReanimatedModule?.installTurboModule();
17
+ }
18
+ this.InnerNativeModule = global.__reanimatedModuleProxy;
11
19
  this.native = native;
12
- this.useOnlyV1 = InnerNativeModule === null;
13
20
  }
14
21
 
15
22
  installCoreFunctions(valueSetter: <T>(value: T) => void): void {
16
- return InnerNativeModule.installCoreFunctions(valueSetter);
23
+ return this.InnerNativeModule.installCoreFunctions(valueSetter);
17
24
  }
18
25
 
19
26
  makeShareable<T>(value: T): T {
20
- return InnerNativeModule.makeShareable(value);
27
+ return this.InnerNativeModule.makeShareable(value);
21
28
  }
22
29
 
23
30
  makeMutable<T>(value: T): SharedValue<T> {
24
- return InnerNativeModule.makeMutable(value);
31
+ return this.InnerNativeModule.makeMutable(value);
25
32
  }
26
33
 
27
34
  makeRemote<T>(object = {}): T {
28
- 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);
29
52
  }
30
53
 
31
54
  startMapper(
@@ -35,7 +58,7 @@ export class NativeReanimated {
35
58
  updater: () => void,
36
59
  viewDescriptors: Descriptor[] | SharedValue<Descriptor[]>
37
60
  ): number {
38
- return InnerNativeModule.startMapper(
61
+ return this.InnerNativeModule.startMapper(
39
62
  mapper,
40
63
  inputs,
41
64
  outputs,
@@ -45,18 +68,18 @@ export class NativeReanimated {
45
68
  }
46
69
 
47
70
  stopMapper(mapperId: number): void {
48
- return InnerNativeModule.stopMapper(mapperId);
71
+ return this.InnerNativeModule.stopMapper(mapperId);
49
72
  }
50
73
 
51
74
  registerEventHandler<T>(
52
75
  eventHash: string,
53
76
  eventHandler: (event: T) => void
54
77
  ): string {
55
- return InnerNativeModule.registerEventHandler(eventHash, eventHandler);
78
+ return this.InnerNativeModule.registerEventHandler(eventHash, eventHandler);
56
79
  }
57
80
 
58
81
  unregisterEventHandler(id: string): void {
59
- return InnerNativeModule.unregisterEventHandler(id);
82
+ return this.InnerNativeModule.unregisterEventHandler(id);
60
83
  }
61
84
 
62
85
  getViewProp<T>(
@@ -64,10 +87,14 @@ export class NativeReanimated {
64
87
  propName: string,
65
88
  callback?: (result: T) => void
66
89
  ): Promise<T> {
67
- return InnerNativeModule.getViewProp(viewTag, propName, callback);
90
+ return this.InnerNativeModule.getViewProp(viewTag, propName, callback);
68
91
  }
69
92
 
70
93
  enableLayoutAnimations(flag: boolean): void {
71
- InnerNativeModule.enableLayoutAnimations(flag);
94
+ this.InnerNativeModule.enableLayoutAnimations(flag);
95
+ }
96
+
97
+ configureProps(uiProps: string[], nativeProps: string[]): void {
98
+ this.InnerNativeModule.configureProps(uiProps, nativeProps);
72
99
  }
73
100
  }
@@ -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
@@ -126,3 +126,23 @@ export type AnimationCallback = (
126
126
  ) => void;
127
127
 
128
128
  export type Timestamp = number;
129
+
130
+ export type Value3D = {
131
+ x: number;
132
+ y: number;
133
+ z: number;
134
+ };
135
+
136
+ export type SensorValue3D = SharedValue<Value3D>;
137
+
138
+ export type ValueRotation = {
139
+ qw: number;
140
+ qx: number;
141
+ qy: number;
142
+ qz: number;
143
+ yaw: number;
144
+ pitch: number;
145
+ roll: number;
146
+ };
147
+
148
+ 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
  );
@@ -63,7 +63,7 @@ export const checkPluginState: (throwError: boolean) => boolean = (
63
63
  export const isConfigured: (throwError?: boolean) => boolean = (
64
64
  throwError = false
65
65
  ) => {
66
- return checkPluginState(throwError) && !NativeReanimatedModule.useOnlyV1;
66
+ return checkPluginState(throwError);
67
67
  };
68
68
 
69
69
  export const isConfiguredCheck: () => void = () => {
@@ -362,32 +362,30 @@ export function runOnJS<A extends any[], R>(
362
362
  }
363
363
  }
364
364
 
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
- );
365
+ NativeReanimatedModule.installCoreFunctions(
366
+ NativeReanimatedModule.native
367
+ ? (workletValueSetter as <T>(value: T) => void)
368
+ : (workletValueSetterJS as <T>(value: T) => void)
369
+ );
371
370
 
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
- }
371
+ if (!isWeb() && isConfigured()) {
372
+ const capturableConsole = console;
373
+ runOnUI(() => {
374
+ 'worklet';
375
+ const console = {
376
+ debug: runOnJS(capturableConsole.debug),
377
+ log: runOnJS(capturableConsole.log),
378
+ warn: runOnJS(capturableConsole.warn),
379
+ error: runOnJS(capturableConsole.error),
380
+ info: runOnJS(capturableConsole.info),
381
+ };
382
+ _setGlobalConsole(console);
383
+ if (global.performance == null) {
384
+ global.performance = {
385
+ now: global._chronoNow,
386
+ } as any; // due to conflict with lib.dom.d.ts -> Performance
387
+ }
388
+ })();
391
389
  }
392
390
 
393
391
  type FeaturesConfig = {
@@ -418,3 +416,13 @@ export function enableLayoutAnimations(
418
416
  NativeReanimatedModule.enableLayoutAnimations(flag);
419
417
  }
420
418
  }
419
+
420
+ export function configureProps(uiProps: string[], nativeProps: string[]): void {
421
+ if (!nativeShouldBeMock()) {
422
+ NativeReanimatedModule.configureProps(uiProps, nativeProps);
423
+ }
424
+ }
425
+
426
+ export function jestResetJsReanimatedModule() {
427
+ (NativeReanimatedModule as JSReanimated).jestResetModule();
428
+ }
@@ -27,6 +27,9 @@ 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
35
  __reanimatedWorkletInit: (worklet: WorkletFunction) => void;
@@ -50,6 +53,9 @@ declare global {
50
53
  yogaValues: unknown
51
54
  ): void;
52
55
  };
56
+ ReanimatedDataMock: {
57
+ now: () => number;
58
+ };
53
59
  }
54
60
  }
55
61
  }
@@ -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);
@@ -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,6 @@
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
4
 
5
5
  let config = {
6
6
  fps: 60,
@@ -129,26 +129,30 @@ const compareStyle = (received, expectedStyle, config) => {
129
129
 
130
130
  let frameTime = 1000 / config.fps;
131
131
  let requestAnimationFrameCopy;
132
+ let currentTimestamp = 0;
132
133
 
133
134
  const requestAnimationFrame = (callback) => {
134
135
  setTimeout(callback, frameTime);
135
136
  };
136
137
 
137
138
  const beforeTest = () => {
139
+ jestResetJsReanimatedModule();
138
140
  requestAnimationFrameCopy = global.requestAnimationFrame;
139
141
  global.requestAnimationFrame = requestAnimationFrame;
140
- MockDate.set(0);
142
+ global.ReanimatedDataMock = {
143
+ now: () => currentTimestamp,
144
+ };
145
+ currentTimestamp = 0;
141
146
  jest.useFakeTimers();
142
147
  };
143
148
 
144
149
  const afterTest = () => {
145
- MockDate.reset();
146
150
  jest.useRealTimers();
147
151
  global.requestAnimationFrame = requestAnimationFrameCopy;
148
152
  };
149
153
 
150
154
  const tickTravel = () => {
151
- MockDate.set(new Date(Date.now() + frameTime));
155
+ currentTimestamp += frameTime;
152
156
  jest.advanceTimersByTime(frameTime);
153
157
  };
154
158
 
@@ -174,6 +178,7 @@ export const advanceAnimationByFrame = (count) => {
174
178
 
175
179
  export const setUpTests = (userConfig = {}) => {
176
180
  const expect = require('expect');
181
+ require('setimmediate');
177
182
  frameTime = Math.round(1000 / config.fps);
178
183
 
179
184
  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
  }
@@ -6,6 +6,8 @@ import {
6
6
  } from './commonTypes';
7
7
  import { EasingFn } from '../../Easing';
8
8
  import { BaseAnimationBuilder } from './BaseAnimationBuilder';
9
+ import { StyleProps } from '../../commonTypes';
10
+
9
11
  export class ComplexAnimationBuilder extends BaseAnimationBuilder {
10
12
  easingV?: EasingFn;
11
13
  rotateV?: string;
@@ -16,6 +18,7 @@ export class ComplexAnimationBuilder extends BaseAnimationBuilder {
16
18
  overshootClampingV?: number;
17
19
  restDisplacementThresholdV?: number;
18
20
  restSpeedThresholdV?: number;
21
+ initialValues?: StyleProps;
19
22
 
20
23
  static createInstance: () => ComplexAnimationBuilder;
21
24
 
@@ -115,6 +118,16 @@ export class ComplexAnimationBuilder extends BaseAnimationBuilder {
115
118
  return this;
116
119
  }
117
120
 
121
+ static withInitialValues(values: StyleProps): BaseAnimationBuilder {
122
+ const instance = this.createInstance();
123
+ return instance.withInitialValues(values);
124
+ }
125
+
126
+ withInitialValues(values: StyleProps): BaseAnimationBuilder {
127
+ this.initialValues = values;
128
+ return this;
129
+ }
130
+
118
131
  getAnimationAndConfig(): LayoutAnimationAndConfig {
119
132
  const duration = this.durationV;
120
133
  const easing = this.easingV;