react-native-reanimated 2.3.0-alpha.3 → 2.3.0-beta.4

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 (264) hide show
  1. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +176 -154
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +49 -33
  4. package/Common/cpp/Registries/EventHandlerRegistry.cpp +14 -7
  5. package/Common/cpp/Registries/MapperRegistry.cpp +24 -20
  6. package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
  7. package/Common/cpp/SharedItems/FrozenObject.cpp +17 -8
  8. package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
  9. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
  10. package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
  11. package/Common/cpp/SharedItems/ShareableValue.cpp +211 -160
  12. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  13. package/Common/cpp/Tools/JSIStoreValueUser.cpp +25 -6
  14. package/Common/cpp/Tools/Mapper.cpp +30 -30
  15. package/Common/cpp/Tools/RuntimeDecorator.cpp +124 -86
  16. package/Common/cpp/Tools/Scheduler.cpp +6 -5
  17. package/Common/cpp/Tools/WorkletEventHandler.cpp +4 -2
  18. package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
  19. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +50 -31
  20. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +34 -16
  21. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +15 -8
  22. package/Common/cpp/headers/Registries/MapperRegistry.h +5 -4
  23. package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
  24. package/Common/cpp/headers/SharedItems/FrozenObject.h +19 -11
  25. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +8 -4
  26. package/Common/cpp/headers/SharedItems/MutableValue.h +23 -12
  27. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +12 -7
  28. package/Common/cpp/headers/SharedItems/RemoteObject.h +19 -8
  29. package/Common/cpp/headers/SharedItems/RuntimeManager.h +26 -25
  30. package/Common/cpp/headers/SharedItems/ShareableValue.h +32 -27
  31. package/Common/cpp/headers/SharedItems/SharedParent.h +10 -7
  32. package/Common/cpp/headers/SharedItems/ValueWrapper.h +95 -72
  33. package/Common/cpp/headers/SpecTools/ErrorHandler.h +18 -19
  34. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  35. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +13 -16
  36. package/Common/cpp/headers/Tools/Mapper.h +19 -16
  37. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +17 -7
  38. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -11
  39. package/Common/cpp/headers/Tools/RuntimeDecorator.h +36 -27
  40. package/Common/cpp/headers/Tools/Scheduler.h +30 -35
  41. package/Common/cpp/headers/Tools/WorkletEventHandler.h +11 -8
  42. package/Common/cpp/hidden_headers/Logger.h +14 -14
  43. package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
  44. package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
  45. package/README.md +1 -1
  46. package/RNReanimated.podspec +24 -6
  47. package/android/build.gradle +38 -29
  48. package/android/react-native-reanimated-63-hermes.aar +0 -0
  49. package/android/react-native-reanimated-63-jsc.aar +0 -0
  50. package/android/react-native-reanimated-64-hermes.aar +0 -0
  51. package/android/react-native-reanimated-64-jsc.aar +0 -0
  52. package/android/react-native-reanimated-65-hermes.aar +0 -0
  53. package/android/react-native-reanimated-65-jsc.aar +0 -0
  54. package/android/react-native-reanimated-66-hermes.aar +0 -0
  55. package/android/react-native-reanimated-66-jsc.aar +0 -0
  56. package/android/react-native-reanimated-67-hermes.aar +0 -0
  57. package/android/react-native-reanimated-67-jsc.aar +0 -0
  58. package/ios/LayoutReanimation/REAAnimationsManager.h +10 -8
  59. package/ios/LayoutReanimation/REAAnimationsManager.m +91 -87
  60. package/ios/LayoutReanimation/REASnapshot.h +2 -2
  61. package/ios/LayoutReanimation/REASnapshot.m +8 -7
  62. package/ios/LayoutReanimation/REAUIManager.h +4 -4
  63. package/ios/LayoutReanimation/REAUIManager.mm +116 -70
  64. package/ios/Nodes/REAAlwaysNode.m +14 -15
  65. package/ios/Nodes/REABezierNode.m +8 -7
  66. package/ios/Nodes/REABlockNode.m +1 -1
  67. package/ios/Nodes/REACallFuncNode.h +0 -1
  68. package/ios/Nodes/REACallFuncNode.m +10 -8
  69. package/ios/Nodes/REAClockNodes.m +22 -20
  70. package/ios/Nodes/REAConcatNode.h +0 -1
  71. package/ios/Nodes/REAConcatNode.m +2 -2
  72. package/ios/Nodes/REACondNode.m +7 -5
  73. package/ios/Nodes/READebugNode.m +5 -4
  74. package/ios/Nodes/REAEventNode.m +1 -1
  75. package/ios/Nodes/REAFunctionNode.h +0 -1
  76. package/ios/Nodes/REAFunctionNode.m +2 -2
  77. package/ios/Nodes/REAJSCallNode.m +4 -5
  78. package/ios/Nodes/REANode.h +3 -4
  79. package/ios/Nodes/REANode.m +9 -11
  80. package/ios/Nodes/REAOperatorNode.m +68 -67
  81. package/ios/Nodes/REAParamNode.h +1 -3
  82. package/ios/Nodes/REAParamNode.m +15 -17
  83. package/ios/Nodes/REAPropsNode.h +1 -3
  84. package/ios/Nodes/REAPropsNode.m +19 -22
  85. package/ios/Nodes/REASetNode.h +0 -1
  86. package/ios/Nodes/REASetNode.m +7 -5
  87. package/ios/Nodes/REAStyleNode.h +0 -1
  88. package/ios/Nodes/REAStyleNode.m +2 -4
  89. package/ios/Nodes/REATransformNode.h +0 -1
  90. package/ios/Nodes/REATransformNode.m +3 -5
  91. package/ios/Nodes/REAValueNode.m +5 -7
  92. package/ios/REAEventDispatcher.m +4 -4
  93. package/ios/REAModule.h +0 -2
  94. package/ios/REAModule.m +29 -38
  95. package/ios/REANodesManager.h +11 -19
  96. package/ios/REANodesManager.m +106 -130
  97. package/ios/REAUtils.h +5 -3
  98. package/ios/RNGestureHandlerStateManager.h +5 -0
  99. package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
  100. package/ios/Transitioning/REAAllTransitions.h +2 -2
  101. package/ios/Transitioning/REAAllTransitions.m +14 -25
  102. package/ios/Transitioning/REATransition.h +8 -7
  103. package/ios/Transitioning/REATransition.m +19 -16
  104. package/ios/Transitioning/REATransitionAnimation.h +1 -1
  105. package/ios/Transitioning/REATransitionAnimation.m +2 -3
  106. package/ios/Transitioning/REATransitionManager.m +3 -3
  107. package/ios/native/NativeMethods.h +20 -5
  108. package/ios/native/NativeMethods.mm +14 -6
  109. package/ios/native/NativeProxy.h +4 -2
  110. package/ios/native/NativeProxy.mm +84 -63
  111. package/ios/native/REAIOSErrorHandler.h +13 -10
  112. package/ios/native/REAIOSErrorHandler.mm +19 -15
  113. package/ios/native/REAIOSLogger.h +8 -8
  114. package/ios/native/REAIOSLogger.mm +10 -6
  115. package/ios/native/REAIOSScheduler.h +5 -5
  116. package/ios/native/REAIOSScheduler.mm +17 -10
  117. package/ios/native/REAInitializer.h +5 -7
  118. package/ios/native/REAInitializer.mm +43 -31
  119. package/ios/native/UIResponder+Reanimated.mm +2 -2
  120. package/lib/Animated.js +9 -1
  121. package/lib/ConfigHelper.js +121 -138
  122. package/lib/ReanimatedEventEmitter.js +0 -1
  123. package/lib/ReanimatedModule.js +0 -1
  124. package/lib/ReanimatedModule.macos.js +0 -1
  125. package/lib/ReanimatedModule.native.js +5 -6
  126. package/lib/ReanimatedModule.windows.js +0 -1
  127. package/lib/ReanimatedModuleCompat.js +64 -35
  128. package/lib/createAnimatedComponent.js +468 -487
  129. package/lib/index.js +9 -1
  130. package/lib/reanimated2/NativeMethods.js +7 -12
  131. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +37 -0
  132. package/lib/reanimated2/NativeReanimated/index.js +15 -0
  133. package/lib/reanimated2/PropAdapters.js +0 -1
  134. package/lib/reanimated2/UpdateProps.js +6 -7
  135. package/lib/reanimated2/ViewDescriptorsSet.js +4 -4
  136. package/lib/reanimated2/WorkletEventHandler.js +15 -13
  137. package/lib/reanimated2/animation/delay.js +8 -2
  138. package/lib/reanimated2/animation/spring.js +2 -0
  139. package/lib/reanimated2/animation/styleAnimation.js +7 -3
  140. package/lib/reanimated2/animation/util.js +25 -2
  141. package/lib/reanimated2/core.js +41 -17
  142. package/lib/reanimated2/globals.d.ts +21 -1
  143. package/lib/reanimated2/hook/useAnimatedRef.js +1 -1
  144. package/lib/reanimated2/hook/useAnimatedStyle.js +3 -3
  145. package/lib/reanimated2/index.js +1 -0
  146. package/lib/reanimated2/interpolation.js +95 -87
  147. package/lib/reanimated2/js-reanimated/JSReanimated.js +13 -10
  148. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  149. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  150. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  151. package/lib/reanimated2/js-reanimated/index.js +10 -8
  152. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +33 -2
  153. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +27 -124
  154. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
  155. package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +1 -2
  156. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +115 -45
  157. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +7 -2
  158. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +21 -21
  159. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +25 -25
  160. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +19 -17
  161. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +5 -5
  162. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +9 -9
  163. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +17 -17
  164. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +19 -19
  165. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +9 -9
  166. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +33 -33
  167. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
  168. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
  169. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
  170. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
  171. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
  172. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
  173. package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
  174. package/lib/reanimated2/layoutReanimation/index.js +1 -0
  175. package/lib/reanimated2/mock.js +3 -1
  176. package/lib/reanimated2/utils.js +9 -0
  177. package/lib/setAndForwardRef.js +14 -48
  178. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  179. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  180. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  181. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
  182. package/mock.js +1 -1
  183. package/package.json +28 -17
  184. package/plugin.js +220 -39
  185. package/react-native-reanimated.d.ts +542 -547
  186. package/src/Animated.js +9 -1
  187. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  188. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  189. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  190. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  191. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  192. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  193. package/src/ReanimatedModuleCompat.ts +51 -0
  194. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +285 -126
  195. package/src/reanimated2/NativeMethods.ts +34 -13
  196. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +72 -0
  197. package/src/reanimated2/NativeReanimated/index.ts +18 -0
  198. package/src/reanimated2/PropAdapters.ts +0 -1
  199. package/src/reanimated2/UpdateProps.ts +31 -15
  200. package/src/reanimated2/ViewDescriptorsSet.ts +15 -12
  201. package/src/reanimated2/WorkletEventHandler.ts +41 -23
  202. package/src/reanimated2/animation/commonTypes.ts +4 -4
  203. package/src/reanimated2/animation/decay.ts +2 -2
  204. package/src/reanimated2/animation/delay.ts +11 -5
  205. package/src/reanimated2/animation/index.ts +7 -7
  206. package/src/reanimated2/animation/repeat.ts +4 -4
  207. package/src/reanimated2/animation/sequence.ts +2 -2
  208. package/src/reanimated2/animation/spring.ts +6 -5
  209. package/src/reanimated2/animation/styleAnimation.ts +27 -15
  210. package/src/reanimated2/animation/timing.ts +5 -5
  211. package/src/reanimated2/animation/util.ts +47 -8
  212. package/src/reanimated2/commonTypes.ts +3 -0
  213. package/src/reanimated2/core.ts +80 -34
  214. package/src/reanimated2/globals.d.ts +21 -1
  215. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -1
  216. package/src/reanimated2/hook/useAnimatedRef.ts +13 -15
  217. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -3
  218. package/src/reanimated2/hook/useAnimatedStyle.ts +7 -7
  219. package/src/reanimated2/hook/utils.ts +4 -3
  220. package/src/reanimated2/index.ts +1 -0
  221. package/src/reanimated2/interpolation.ts +170 -103
  222. package/src/reanimated2/js-reanimated/JSReanimated.ts +37 -23
  223. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  224. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  225. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  226. package/src/reanimated2/js-reanimated/index.ts +31 -14
  227. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +75 -0
  228. package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +29 -159
  229. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
  230. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -2
  231. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +3 -9
  232. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -5
  233. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +162 -82
  234. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +7 -2
  235. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +32 -32
  236. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +38 -38
  237. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +34 -32
  238. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -8
  239. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +14 -14
  240. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +26 -26
  241. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +28 -28
  242. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +14 -14
  243. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +50 -50
  244. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
  245. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
  246. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
  247. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
  248. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
  249. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
  250. package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
  251. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  252. package/src/reanimated2/mock.ts +3 -1
  253. package/src/reanimated2/utils.ts +21 -0
  254. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  255. package/android/react-native-reanimated-62-hermes.aar +0 -0
  256. package/android/react-native-reanimated-62-jsc.aar +0 -0
  257. package/lib/reanimated2/NativeReanimated.js +0 -48
  258. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.js +0 -55
  259. package/lib/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.js +0 -165
  260. package/src/ReanimatedModuleCompat.js +0 -37
  261. package/src/reanimated2/NativeReanimated.ts +0 -70
  262. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +0 -41
  263. package/src/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.ts +0 -82
  264. package/src/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.ts +0 -217
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Image, ScrollView, Text, View } from 'react-native';
1
+ import { Image, ScrollView, Text, View, LogBox } from 'react-native';
2
2
  import createAnimatedComponent from './createAnimatedComponent';
3
3
  import {
4
4
  addWhitelistedNativeProps,
@@ -23,3 +23,11 @@ const Animated = {
23
23
  export * from './reanimated2';
24
24
  export * from './reanimated1';
25
25
  export default Animated;
26
+
27
+ // I think we can ignore this message as long as Gesture Handler doesn't
28
+ // try to load the Reanimated module. I figured it should be here instead of
29
+ // RNGH because this prevents the message from being displayed for all
30
+ // versions of RNGH.
31
+ LogBox.ignoreLogs([
32
+ 'RCTBridge required dispatch_sync to load RNGestureHandlerModule. This may lead to deadlocks',
33
+ ]);
@@ -1,20 +1,8 @@
1
- /* global _WORKLET _measure _scrollTo */
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
1
  import { findNodeHandle } from 'react-native';
5
2
  import { isChromeDebugger } from './PlatformChecker';
6
3
  export function getTag(view) {
7
4
  return findNodeHandle(view);
8
5
  }
9
- /**
10
- * fields that can be accessed:
11
- * x
12
- * y
13
- * width
14
- * height
15
- * pageX
16
- * pageY
17
- */
18
6
  export function measure(animatedRef) {
19
7
  'worklet';
20
8
  if (!_WORKLET && !isChromeDebugger()) {
@@ -35,3 +23,10 @@ export function scrollTo(animatedRef, x, y, animated) {
35
23
  const viewTag = animatedRef();
36
24
  _scrollTo(viewTag, x, y, animated);
37
25
  }
26
+ export function setGestureState(handlerTag, newState) {
27
+ 'worklet';
28
+ if (!_WORKLET && !isChromeDebugger()) {
29
+ console.warn('[Reanimated] You can not use setGestureState in non-worklet function.');
30
+ }
31
+ _setGestureState(handlerTag, newState);
32
+ }
@@ -0,0 +1,37 @@
1
+ const InnerNativeModule = global.__reanimatedModuleProxy;
2
+ export class NativeReanimated {
3
+ constructor(native = true) {
4
+ this.native = native;
5
+ this.useOnlyV1 = InnerNativeModule === null;
6
+ }
7
+ installCoreFunctions(valueSetter) {
8
+ return InnerNativeModule.installCoreFunctions(valueSetter);
9
+ }
10
+ makeShareable(value) {
11
+ return InnerNativeModule.makeShareable(value);
12
+ }
13
+ makeMutable(value) {
14
+ return InnerNativeModule.makeMutable(value);
15
+ }
16
+ makeRemote(object = {}) {
17
+ return InnerNativeModule.makeRemote(object);
18
+ }
19
+ startMapper(mapper, inputs = [], outputs = [], updater, viewDescriptors) {
20
+ return InnerNativeModule.startMapper(mapper, inputs, outputs, updater, viewDescriptors);
21
+ }
22
+ stopMapper(mapperId) {
23
+ return InnerNativeModule.stopMapper(mapperId);
24
+ }
25
+ registerEventHandler(eventHash, eventHandler) {
26
+ return InnerNativeModule.registerEventHandler(eventHash, eventHandler);
27
+ }
28
+ unregisterEventHandler(id) {
29
+ return InnerNativeModule.unregisterEventHandler(id);
30
+ }
31
+ getViewProp(viewTag, propName, callback) {
32
+ return InnerNativeModule.getViewProp(viewTag, propName, callback);
33
+ }
34
+ enableLayoutAnimations(flag) {
35
+ InnerNativeModule.enableLayoutAnimations(flag);
36
+ }
37
+ }
@@ -0,0 +1,15 @@
1
+ import reanimatedJS from '../js-reanimated';
2
+ import { nativeShouldBeMock } from '../PlatformChecker';
3
+ import { Platform } from 'react-native';
4
+ import { NativeReanimated } from './NativeReanimated';
5
+ let exportedModule;
6
+ if (nativeShouldBeMock()) {
7
+ exportedModule = reanimatedJS;
8
+ }
9
+ else {
10
+ exportedModule = new NativeReanimated();
11
+ if (exportedModule.useOnlyV1 && Platform.OS === 'android') {
12
+ console.warn(`If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/installation`);
13
+ }
14
+ }
15
+ export default exportedModule;
@@ -1,4 +1,3 @@
1
- // @ts-ignore JS file
2
1
  import { addWhitelistedNativeProps } from '../ConfigHelper';
3
2
  export function createAnimatedPropAdapter(adapter, nativeProps) {
4
3
  const nativePropsToAdd = {};
@@ -1,6 +1,3 @@
1
- /* global _updateProps */
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
1
  import { processColor } from './Colors';
5
2
  import { makeShareable, isConfigured } from './core';
6
3
  import { _updatePropsJS } from './js-reanimated';
@@ -22,14 +19,16 @@ export const colorProps = [
22
19
  'textShadowColor',
23
20
  'overlayColor',
24
21
  ];
25
- const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
22
+ export const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
26
23
  let updatePropsByPlatform;
27
24
  if (shouldBeUseWeb()) {
28
25
  updatePropsByPlatform = (_, updates, maybeViewRef) => {
29
26
  'worklet';
30
- maybeViewRef.items.forEach((item, _) => {
31
- _updatePropsJS(updates, item);
32
- });
27
+ if (maybeViewRef) {
28
+ maybeViewRef.items.forEach((item, _) => {
29
+ _updatePropsJS(updates, item);
30
+ });
31
+ }
33
32
  };
34
33
  }
35
34
  else {
@@ -1,7 +1,7 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  import { useRef } from 'react';
4
2
  import { makeMutable } from './core';
3
+ import { Platform } from 'react-native';
4
+ const scheduleUpdates = Platform.OS === 'web' ? requestAnimationFrame : setImmediate;
5
5
  export function makeViewDescriptorsSet() {
6
6
  const ref = useRef(null);
7
7
  if (ref.current === null) {
@@ -20,7 +20,7 @@ export function makeViewDescriptorsSet() {
20
20
  data.items.push(item);
21
21
  if (!data.waitForInsertSync) {
22
22
  data.waitForInsertSync = true;
23
- setImmediate(() => {
23
+ scheduleUpdates(() => {
24
24
  data.sharableViewDescriptors.value = data.items;
25
25
  data.waitForInsertSync = false;
26
26
  });
@@ -30,7 +30,7 @@ export function makeViewDescriptorsSet() {
30
30
  data.batchToRemove.add(viewTag);
31
31
  if (!data.waitForRemoveSync) {
32
32
  data.waitForRemoveSync = true;
33
- setImmediate(() => {
33
+ scheduleUpdates(() => {
34
34
  const items = [];
35
35
  for (const item of data.items) {
36
36
  if (data.batchToRemove.has(item.tag)) {
@@ -1,15 +1,18 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- import NativeModule from './NativeReanimated';
4
- const jsListener = (eventName, handler) => (evt) => {
5
- handler(Object.assign(Object.assign({}, evt.nativeEvent), { eventName }));
6
- };
1
+ import NativeReanimatedModule from './NativeReanimated';
2
+ function jsListener(eventName, handler) {
3
+ return (evt) => {
4
+ handler(Object.assign(Object.assign({}, evt.nativeEvent), { eventName }));
5
+ };
6
+ }
7
7
  export default class WorkletEventHandler {
8
8
  constructor(worklet, eventNames = []) {
9
9
  this.worklet = worklet;
10
10
  this.eventNames = eventNames;
11
11
  this.reattachNeeded = false;
12
- if (!NativeModule.native) {
12
+ this.listeners = {};
13
+ this.viewTag = undefined;
14
+ this.registrations = [];
15
+ if (!NativeReanimatedModule.native) {
13
16
  this.listeners = eventNames.reduce((acc, eventName) => {
14
17
  acc[eventName] = jsListener(eventName, worklet);
15
18
  return acc;
@@ -20,16 +23,15 @@ export default class WorkletEventHandler {
20
23
  this.worklet = newWorklet;
21
24
  this.reattachNeeded = true;
22
25
  }
23
- registerForEvents(viewTag, fallbackEventName = undefined) {
26
+ registerForEvents(viewTag, fallbackEventName) {
24
27
  this.viewTag = viewTag;
25
- this.registrations = this.eventNames.map((eventName) => NativeModule.registerEventHandler(viewTag + eventName, this.worklet));
28
+ this.registrations = this.eventNames.map((eventName) => NativeReanimatedModule.registerEventHandler(viewTag + eventName, this.worklet));
26
29
  if (this.registrations.length === 0 && fallbackEventName) {
27
- this.registrations.push(NativeModule.registerEventHandler(viewTag + fallbackEventName, this.worklet));
30
+ this.registrations.push(NativeReanimatedModule.registerEventHandler(viewTag + fallbackEventName, this.worklet));
28
31
  }
29
32
  }
30
33
  unregisterFromEvents() {
31
- this.registrations &&
32
- this.registrations.forEach((id) => NativeModule.unregisterEventHandler(id));
33
- this.registrations = undefined;
34
+ this.registrations.forEach((id) => NativeReanimatedModule.unregisterEventHandler(id));
35
+ this.registrations = [];
34
36
  }
35
37
  }
@@ -17,7 +17,8 @@ export function withDelay(delayMs, _nextAnimation) {
17
17
  return finished;
18
18
  }
19
19
  else if (previousAnimation) {
20
- const finished = previousAnimation.onFrame(previousAnimation, now);
20
+ const finished = previousAnimation.finished ||
21
+ previousAnimation.onFrame(previousAnimation, now);
21
22
  animation.current = previousAnimation.current;
22
23
  if (finished) {
23
24
  animation.previousAnimation = null;
@@ -29,7 +30,12 @@ export function withDelay(delayMs, _nextAnimation) {
29
30
  animation.startTime = now;
30
31
  animation.started = false;
31
32
  animation.current = value;
32
- animation.previousAnimation = previousAnimation;
33
+ if (previousAnimation === animation) {
34
+ animation.previousAnimation = previousAnimation.previousAnimation;
35
+ }
36
+ else {
37
+ animation.previousAnimation = previousAnimation;
38
+ }
33
39
  }
34
40
  const callback = (finished) => {
35
41
  if (nextAnimation.callback) {
@@ -73,6 +73,8 @@ export function withSpring(toValue, userConfig, callback) {
73
73
  animation.velocity = 0;
74
74
  animation.current = toValue;
75
75
  }
76
+ // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
77
+ animation.lastTimestamp = 0;
76
78
  return true;
77
79
  }
78
80
  return false;
@@ -1,8 +1,10 @@
1
1
  import { defineAnimation } from './util';
2
2
  import { withTiming } from './timing';
3
+ import { ColorProperties } from '../UpdateProps';
4
+ import { processColor } from '../Colors';
3
5
  // resolves path to value for nested objects
4
6
  // if path cannot be resolved returns undefined
5
- function resolvePath(obj, path) {
7
+ export function resolvePath(obj, path) {
6
8
  'worklet';
7
9
  const keys = Array.isArray(path) ? path : [path];
8
10
  return keys.reduce((acc, current) => {
@@ -15,8 +17,7 @@ function resolvePath(obj, path) {
15
17
  return undefined;
16
18
  }, obj);
17
19
  }
18
- // set value at given path
19
- function setPath(obj, path, value) {
20
+ export function setPath(obj, path, value) {
20
21
  'worklet';
21
22
  const keys = Array.isArray(path) ? path : [path];
22
23
  let currObj = obj;
@@ -80,6 +81,9 @@ export function withStyleAnimation(styleAnimations) {
80
81
  else {
81
82
  stillGoing = true;
82
83
  }
84
+ if (ColorProperties.includes(currentEntry.path[0])) {
85
+ currentStyleAnimation.current = processColor(currentStyleAnimation.current);
86
+ }
83
87
  setPath(animation.current, currentEntry.path, currentStyleAnimation.current);
84
88
  }
85
89
  }
@@ -1,6 +1,6 @@
1
1
  /* global _WORKLET */
2
2
  import { convertToHSVA, isColor, toRGBA } from '../Colors';
3
- import NativeReanimated from '../NativeReanimated';
3
+ import NativeReanimatedModule from '../NativeReanimated';
4
4
  let IN_STYLE_UPDATER = false;
5
5
  export function initialUpdaterRun(updater) {
6
6
  IN_STYLE_UPDATER = true;
@@ -107,12 +107,35 @@ function decorateAnimation(animation) {
107
107
  animation.current = toRGBA(res);
108
108
  return finished;
109
109
  };
110
+ const arrayOnStart = (animation, value, timestamp, previousAnimation) => {
111
+ value.forEach((v, i) => {
112
+ animation[i] = Object.assign({}, animationCopy);
113
+ animation[i].current = v;
114
+ animation[i].toValue = animation.toValue[i];
115
+ animation[i].onStart(animation[i], v, timestamp, previousAnimation ? previousAnimation[i] : undefined);
116
+ });
117
+ animation.current = value;
118
+ };
119
+ const arrayOnFrame = (animation, timestamp) => {
120
+ let finished = true;
121
+ animation.current.forEach((v, i) => {
122
+ // @ts-ignore: disable-next-line
123
+ finished &= animation[i].onFrame(animation[i], timestamp);
124
+ animation.current[i] = animation[i].current;
125
+ });
126
+ return finished;
127
+ };
110
128
  animation.onStart = (animation, value, timestamp, previousAnimation) => {
111
129
  if (isColor(value)) {
112
130
  colorOnStart(animation, value, timestamp, previousAnimation);
113
131
  animation.onFrame = colorOnFrame;
114
132
  return;
115
133
  }
134
+ else if (Array.isArray(value)) {
135
+ arrayOnStart(animation, value, timestamp, previousAnimation);
136
+ animation.onFrame = arrayOnFrame;
137
+ return;
138
+ }
116
139
  else if (typeof value === 'string') {
117
140
  prefNumberSuffOnStart(animation, value, timestamp, previousAnimation);
118
141
  animation.onFrame = prefNumberSuffOnFrame;
@@ -132,7 +155,7 @@ export function defineAnimation(starting, factory) {
132
155
  decorateAnimation(animation);
133
156
  return animation;
134
157
  };
135
- if (_WORKLET || !NativeReanimated.native) {
158
+ if (_WORKLET || !NativeReanimatedModule.native) {
136
159
  return create();
137
160
  }
138
161
  // @ts-ignore: eslint-disable-line
@@ -1,5 +1,5 @@
1
1
  /* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp, _setGlobalConsole */
2
- import NativeReanimated from './NativeReanimated';
2
+ import NativeReanimatedModule from './NativeReanimated';
3
3
  import { Platform } from 'react-native';
4
4
  import { nativeShouldBeMock, shouldBeUseWeb } from './PlatformChecker';
5
5
  global.__reanimatedWorkletInit = function (worklet) {
@@ -24,11 +24,11 @@ export const checkPluginState = (throwError = true) => {
24
24
  return true;
25
25
  };
26
26
  export const isConfigured = (throwError = false) => {
27
- return checkPluginState(throwError) && !NativeReanimated.useOnlyV1;
27
+ return checkPluginState(throwError) && !NativeReanimatedModule.useOnlyV1;
28
28
  };
29
29
  export const isConfiguredCheck = () => {
30
30
  if (!isConfigured(true)) {
31
- throw new Error('If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/installation');
31
+ throw new Error('If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation');
32
32
  }
33
33
  };
34
34
  function _toArrayReanimated(object) {
@@ -65,11 +65,11 @@ global.__reanimatedWorkletInit = function (worklet) {
65
65
  }
66
66
  };
67
67
  function pushFrame(frame) {
68
- NativeReanimated.pushFrame(frame);
68
+ NativeReanimatedModule.pushFrame(frame);
69
69
  }
70
70
  export function requestFrame(frame) {
71
71
  'worklet';
72
- if (NativeReanimated.native) {
72
+ if (NativeReanimatedModule.native) {
73
73
  requestAnimationFrame(frame);
74
74
  }
75
75
  else {
@@ -85,11 +85,11 @@ export function runOnUI(worklet) {
85
85
  }
86
86
  export function makeShareable(value) {
87
87
  isConfiguredCheck();
88
- return NativeReanimated.makeShareable(value);
88
+ return NativeReanimatedModule.makeShareable(value);
89
89
  }
90
90
  export function getViewProp(viewTag, propName) {
91
91
  return new Promise((resolve, reject) => {
92
- return NativeReanimated.getViewProp(viewTag, propName, (result) => {
92
+ return NativeReanimatedModule.getViewProp(viewTag, propName, (result) => {
93
93
  if (typeof result === 'string' && result.substr(0, 6) === 'error:') {
94
94
  reject(result);
95
95
  }
@@ -102,7 +102,7 @@ export function getViewProp(viewTag, propName) {
102
102
  let _getTimestamp;
103
103
  if (nativeShouldBeMock()) {
104
104
  _getTimestamp = () => {
105
- return NativeReanimated.getTimestamp();
105
+ return NativeReanimatedModule.getTimestamp();
106
106
  };
107
107
  }
108
108
  else {
@@ -120,7 +120,7 @@ else {
120
120
  export function getTimestamp() {
121
121
  'worklet';
122
122
  if (Platform.OS === 'web') {
123
- return NativeReanimated.getTimestamp();
123
+ return NativeReanimatedModule.getTimestamp();
124
124
  }
125
125
  return _getTimestamp();
126
126
  }
@@ -135,7 +135,9 @@ function workletValueSetter(value) {
135
135
  (value !== null &&
136
136
  typeof value === 'object' &&
137
137
  value.onFrame !== undefined)) {
138
- const animation = typeof value === 'function' ? value() : value;
138
+ const animation = typeof value === 'function'
139
+ ? value()
140
+ : value;
139
141
  // prevent setting again to the same value
140
142
  // and triggering the mappers that treat this value as an input
141
143
  // this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)
@@ -196,7 +198,9 @@ function workletValueSetterJS(value) {
196
198
  typeof value === 'object' &&
197
199
  value.onFrame)) {
198
200
  // animated set
199
- const animation = typeof value === 'function' ? value() : value;
201
+ const animation = typeof value === 'function'
202
+ ? value()
203
+ : value;
200
204
  let initializeAnimation = (timestamp) => {
201
205
  animation.onStart(animation, this.value, timestamp, previousAnimation);
202
206
  };
@@ -228,20 +232,20 @@ function workletValueSetterJS(value) {
228
232
  }
229
233
  export function makeMutable(value) {
230
234
  isConfiguredCheck();
231
- return NativeReanimated.makeMutable(value);
235
+ return NativeReanimatedModule.makeMutable(value);
232
236
  }
233
237
  export function makeRemote(object = {}) {
234
238
  isConfiguredCheck();
235
- return NativeReanimated.makeRemote(object);
239
+ return NativeReanimatedModule.makeRemote(object);
236
240
  }
237
241
  export function startMapper(mapper, inputs = [], outputs = [], updater = () => {
238
242
  // noop
239
243
  }, viewDescriptors = []) {
240
244
  isConfiguredCheck();
241
- return NativeReanimated.startMapper(mapper, inputs, outputs, updater, viewDescriptors);
245
+ return NativeReanimatedModule.startMapper(mapper, inputs, outputs, updater, viewDescriptors);
242
246
  }
243
247
  export function stopMapper(mapperId) {
244
- NativeReanimated.stopMapper(mapperId);
248
+ NativeReanimatedModule.stopMapper(mapperId);
245
249
  }
246
250
  export function runOnJS(fun) {
247
251
  'worklet';
@@ -255,8 +259,10 @@ export function runOnJS(fun) {
255
259
  return fun.__callAsync;
256
260
  }
257
261
  }
258
- if (!NativeReanimated.useOnlyV1) {
259
- NativeReanimated.installCoreFunctions(NativeReanimated.native ? workletValueSetter : workletValueSetterJS);
262
+ if (!NativeReanimatedModule.useOnlyV1) {
263
+ NativeReanimatedModule.installCoreFunctions(NativeReanimatedModule.native
264
+ ? workletValueSetter
265
+ : workletValueSetterJS);
260
266
  const capturableConsole = console;
261
267
  isConfigured() &&
262
268
  runOnUI(() => {
@@ -271,3 +277,21 @@ if (!NativeReanimated.useOnlyV1) {
271
277
  _setGlobalConsole(console);
272
278
  })();
273
279
  }
280
+ let featuresConfig = {
281
+ enableLayoutAnimations: false,
282
+ setByUser: false,
283
+ };
284
+ export function enableLayoutAnimations(flag, isCallByUser = true) {
285
+ if (isCallByUser) {
286
+ featuresConfig = {
287
+ enableLayoutAnimations: flag,
288
+ setByUser: true,
289
+ };
290
+ NativeReanimatedModule.enableLayoutAnimations(flag);
291
+ }
292
+ else if (!featuresConfig.setByUser &&
293
+ featuresConfig.enableLayoutAnimations !== flag) {
294
+ featuresConfig.enableLayoutAnimations = flag;
295
+ NativeReanimatedModule.enableLayoutAnimations(flag);
296
+ }
297
+ }
@@ -1,5 +1,7 @@
1
- import { WorkletFunction } from './commonTypes';
1
+ import { AnimatedStyle, StyleProps, WorkletFunction } from './commonTypes';
2
2
  import { ReanimatedConsole } from './core';
3
+ import { MeasuredDimensions } from './NativeMethods';
4
+ import { NativeReanimated } from './NativeReanimated/NativeReanimated';
3
5
  declare global {
4
6
  const _WORKLET: boolean;
5
7
  const _frameTimestamp: number;
@@ -11,12 +13,30 @@ declare global {
11
13
  tag: number,
12
14
  flag: { value: boolean; _value: boolean }
13
15
  ) => void;
16
+ const _setGestureState: (handlerTag: number, newState: number) => void;
17
+ const _updateProps: (
18
+ tag: number,
19
+ name: string,
20
+ updates: StyleProps | AnimatedStyle
21
+ ) => void;
22
+ const _measure: (viewTag: number) => MeasuredDimensions;
23
+ const _scrollTo: (
24
+ viewTag: number,
25
+ x: number,
26
+ y: number,
27
+ animated: boolean
28
+ ) => void;
14
29
  namespace NodeJS {
15
30
  interface Global {
16
31
  __reanimatedWorkletInit: (worklet: WorkletFunction) => void;
17
32
  _setGlobalConsole: (console?: ReanimatedConsole) => void;
18
33
  _log: (s: string) => void;
34
+ _setGestureState: () => void;
19
35
  _WORKLET: boolean;
36
+ __reanimatedModuleProxy: NativeReanimated;
37
+ _frameTimestamp: number | null;
38
+ _measure: () => MeasuredDimensions;
39
+ _scrollTo: () => void;
20
40
  LayoutAnimationRepository: {
21
41
  configs: Record<string, unknown>;
22
42
  registerConfig(tag: number, config: Record<string, unknown>): void;
@@ -5,7 +5,7 @@ export function useAnimatedRef() {
5
5
  const tag = useSharedValue(-1);
6
6
  const ref = useRef();
7
7
  if (!ref.current) {
8
- const fun = (function (component) {
8
+ const fun = ((component) => {
9
9
  'worklet';
10
10
  // enters when ref is set by attaching to a component
11
11
  if (component) {
@@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react';
3
3
  import { startMapper, stopMapper, makeRemote, requestFrame, getTimestamp, makeMutable, } from '../core';
4
4
  import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
5
5
  import { initialUpdaterRun } from '../animation';
6
- import NativeReanimated from '../NativeReanimated';
6
+ import NativeReanimatedModule from '../NativeReanimated';
7
7
  import { useSharedValue } from './useSharedValue';
8
8
  import { buildWorkletsHash, canApplyOptimalisation, getStyleWithoutAnimations, hasColorProps, isAnimated, parseColors, styleDiff, validateAnimatedStyles, } from './utils';
9
9
  import { makeViewDescriptorsSet, makeViewsRefSet, } from '../ViewDescriptorsSet';
@@ -290,6 +290,7 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
290
290
  initRef.current = {
291
291
  initial: {
292
292
  value: initialStyle,
293
+ updater: updater,
293
294
  },
294
295
  remoteState: makeRemote({ last: initialStyle }),
295
296
  sharableViewDescriptors: makeMutable([]),
@@ -301,8 +302,7 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
301
302
  dependencies.push((_b = initRef.current) === null || _b === void 0 ? void 0 : _b.sharableViewDescriptors.value);
302
303
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
303
304
  const { initial, remoteState, sharableViewDescriptors } = initRef.current;
304
- const maybeViewRef = NativeReanimated.native ? undefined : viewsRef;
305
- initial.value = initialUpdaterRun(updater);
305
+ const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
306
306
  useEffect(() => {
307
307
  let fun;
308
308
  let upadterFn = updater;
@@ -7,3 +7,4 @@ export * from './NativeMethods';
7
7
  export * from './Colors';
8
8
  export * from './PropAdapters';
9
9
  export * from './layoutReanimation';
10
+ export * from './utils';