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
@@ -0,0 +1,46 @@
1
+ import { withSequence, withTiming } from '../../animation';
2
+ import { BaseAnimationBuilder } from '../animationBuilder';
3
+ export class SequencedTransition extends BaseAnimationBuilder {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.reversed = false;
7
+ this.build = () => {
8
+ var _a;
9
+ const delayFunction = this.getDelayFunction();
10
+ const callback = this.callbackV;
11
+ const delay = this.getDelay();
12
+ const sequenceDuration = ((_a = this.durationV) !== null && _a !== void 0 ? _a : 500) / 2;
13
+ const config = { duration: sequenceDuration };
14
+ const reverse = this.reversed;
15
+ return (values) => {
16
+ 'worklet';
17
+ return {
18
+ initialValues: {
19
+ originX: values.boriginX,
20
+ originY: values.boriginY,
21
+ width: values.bwidth,
22
+ height: values.bheight,
23
+ },
24
+ animations: {
25
+ originX: delayFunction(delay, withSequence(withTiming(reverse ? values.boriginX : values.originX, config), withTiming(values.originX, config))),
26
+ originY: delayFunction(delay, withSequence(withTiming(reverse ? values.originY : values.boriginY, config), withTiming(values.originY, config))),
27
+ width: delayFunction(delay, withSequence(withTiming(reverse ? values.bwidth : values.width, config), withTiming(values.width, config))),
28
+ height: delayFunction(delay, withSequence(withTiming(reverse ? values.height : values.bheight, config), withTiming(values.height, config))),
29
+ },
30
+ callback: callback,
31
+ };
32
+ };
33
+ };
34
+ }
35
+ static createInstance() {
36
+ return new SequencedTransition();
37
+ }
38
+ static reverse() {
39
+ const instance = SequencedTransition.createInstance();
40
+ return instance.reverse();
41
+ }
42
+ reverse() {
43
+ this.reversed = !this.reversed;
44
+ return this;
45
+ }
46
+ }
@@ -0,0 +1,6 @@
1
+ export * from './LinearTransition';
2
+ export * from './FadingTransition';
3
+ export * from './SequencedTransition';
4
+ export * from './JumpingTransition';
5
+ export * from './CurvedTransition';
6
+ export * from './EntryExitTransition';
@@ -1,3 +1,4 @@
1
1
  import './LayoutAnimationRepository';
2
2
  export * from './animationBuilder';
3
3
  export * from './defaultAnimations';
4
+ export * from './defaultTransitions';
@@ -6,14 +6,16 @@ const NOOP = () => {
6
6
  // noop
7
7
  };
8
8
  const ID = (t) => t;
9
+ const IMMEDIATE_CB_INVOCATION = (cb) => cb();
9
10
  const ReanimatedV2 = {
10
11
  useSharedValue: (v) => ({ value: v }),
11
12
  useDerivedValue: (a) => ({ value: a() }),
12
13
  useAnimatedScrollHandler: () => NOOP,
13
14
  useAnimatedGestureHandler: () => NOOP,
14
- useAnimatedStyle: (style) => style,
15
+ useAnimatedStyle: IMMEDIATE_CB_INVOCATION,
15
16
  useAnimatedRef: () => ({ current: null }),
16
17
  useAnimatedReaction: NOOP,
18
+ useAnimatedProps: IMMEDIATE_CB_INVOCATION,
17
19
  withTiming: (toValue, _, cb) => {
18
20
  cb && cb(true);
19
21
  return toValue;
@@ -0,0 +1,9 @@
1
+ import { measure } from './NativeMethods';
2
+ export function getRelativeCoords(parentRef, x, y) {
3
+ 'worklet';
4
+ const parentCoords = measure(parentRef);
5
+ return {
6
+ x: x - parentCoords.x,
7
+ y: y - parentCoords.y,
8
+ };
9
+ }
@@ -1,53 +1,19 @@
1
1
  /**
2
2
  * imported from react-native
3
3
  */
4
-
5
- /**
6
- * This is a helper function for when a component needs to be able to forward a ref
7
- * to a child component, but still needs to have access to that component as part of
8
- * its implementation.
9
- *
10
- * Its main use case is in wrappers for native components.
11
- *
12
- * Usage:
13
- *
14
- * class MyView extends React.Component {
15
- * _nativeRef = null;
16
- *
17
- * _setNativeRef = setAndForwardRef({
18
- * getForwardedRef: () => this.props.forwardedRef,
19
- * setLocalRef: ref => {
20
- * this._nativeRef = ref;
21
- * },
22
- * });
23
- *
24
- * render() {
25
- * return <View ref={this._setNativeRef} />;
26
- * }
27
- * }
28
- *
29
- * const MyViewWithRef = React.forwardRef((props, ref) => (
30
- * <MyView {...props} forwardedRef={ref} />
31
- * ));
32
- *
33
- * module.exports = MyViewWithRef;
34
- */
35
-
36
- function setAndForwardRef({ getForwardedRef, setLocalRef }) {
37
- return function forwardRef(ref) {
38
- const forwardedRef = getForwardedRef();
39
-
40
- setLocalRef(ref);
41
-
42
- // Forward to user ref prop (if one has been specified)
43
- if (typeof forwardedRef === 'function') {
44
- // Handle function-based refs. String-based refs are handled as functions.
45
- forwardedRef(ref);
46
- } else if (typeof forwardedRef === 'object' && forwardedRef != null) {
47
- // Handle createRef-based refs
48
- forwardedRef.current = ref;
49
- }
50
- };
4
+ function setAndForwardRef({ getForwardedRef, setLocalRef, }) {
5
+ return function forwardRef(ref) {
6
+ const forwardedRef = getForwardedRef();
7
+ setLocalRef(ref);
8
+ // Forward to user ref prop (if one has been specified)
9
+ if (typeof forwardedRef === 'function') {
10
+ // Handle function-based refs. String-based refs are handled as functions.
11
+ forwardedRef(ref);
12
+ }
13
+ else if (typeof forwardedRef === 'object' && forwardedRef != null) {
14
+ // Handle createRef-based refs
15
+ forwardedRef.current = ref;
16
+ }
17
+ };
51
18
  }
52
-
53
19
  export default setAndForwardRef;
Binary file
package/mock.js CHANGED
@@ -86,7 +86,7 @@ function createTransitioningComponent(Component) {
86
86
  }
87
87
 
88
88
  render() {
89
- return <Component {...this.props} />;
89
+ return React.createElement(Component, this.props);
90
90
  }
91
91
  };
92
92
  }
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "react-native-reanimated",
3
- "version": "2.3.0-alpha.3",
3
+ "version": "2.3.0-beta.4",
4
4
  "description": "More powerful alternative to Animated library for React Native.",
5
5
  "scripts": {
6
6
  "start": "node node_modules/react-native/local-cli/cli.js start",
7
- "test": "yarn run format && yarn run lint-check && yarn run test:unit",
7
+ "test": "yarn run format:js && yarn run lint:js && yarn run test:unit",
8
8
  "test:unit": "jest",
9
- "format": "prettier --write --list-different './src/'",
10
- "lint-check": "eslint --ext '.js,.ts,.tsx' src/ && yarn prettier --check src/",
11
- "lint-check-cpp": "./scripts/cpplint.sh",
9
+ "lint": "yarn lint:js && yarn lint:cpp && yarn lint:java",
10
+ "lint:js": "eslint --ext '.js,.ts,.tsx' src/ && yarn prettier --check src/",
11
+ "lint:java": "./android/gradlew -p android spotlessCheck -q",
12
+ "lint:cpp": "./scripts/cpplint.sh",
13
+ "format": "yarn format:js && yarn format:java && yarn format:ios && yarn format:android && yarn format:common",
14
+ "format:js": "prettier --write --list-different './src/'",
15
+ "format:java": "node ./scripts/format-java.js",
16
+ "format:ios": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm -o -iname *.cpp | xargs clang-format -i",
17
+ "format:android": "find android/src/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
18
+ "format:common": "find Common/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
12
19
  "release": "npm login && release-it",
13
20
  "type:check": "yarn tsc --noEmit",
14
21
  "type:generate": "yarn type:generate:clean && yarn type:generate:cp-js-src && yarn type:generate:tsc && yarn type:generate:remove.ts && yarn type:generate:remove.tsx",
@@ -16,7 +23,8 @@
16
23
  "type:generate:cp-js-src": "cp -RL src/ lib/",
17
24
  "type:generate:tsc": "yarn tsc",
18
25
  "type:generate:remove.ts": "find ./lib -type f -name \"*.ts\" -and -not -name \"*.d.ts\" -delete",
19
- "type:generate:remove.tsx": "find ./lib -type f -name \"*.tsx\" -and -not -name \"*.d.ts\" -delete"
26
+ "type:generate:remove.tsx": "find ./lib -type f -name \"*.tsx\" -and -not -name \"*.d.ts\" -delete",
27
+ "prepare": "husky install"
20
28
  },
21
29
  "main": "lib/Animated.js",
22
30
  "module": "lib/Animated",
@@ -27,6 +35,7 @@
27
35
  "Common/",
28
36
  "src/",
29
37
  "lib/",
38
+ "libSo/",
30
39
  "android/src/main/AndroidManifest.xml",
31
40
  "android/src/main/java/",
32
41
  "android/build.gradle",
@@ -59,6 +68,7 @@
59
68
  "homepage": "https://github.com/software-mansion/react-native-reanimated#readme",
60
69
  "dependencies": {
61
70
  "@babel/plugin-transform-object-assign": "^7.10.4",
71
+ "@types/invariant": "^2.2.35",
62
72
  "invariant": "^2.2.4",
63
73
  "lodash.isequal": "^4.5.0",
64
74
  "mockdate": "^3.0.2",
@@ -85,12 +95,13 @@
85
95
  "@types/babel__generator": "^7.6.2",
86
96
  "@types/babel__traverse": "^7.0.15",
87
97
  "@types/jest": "^26.0.15",
88
- "@types/react-native": "^0.64.2",
98
+ "@types/react-native": "^0.65.1",
89
99
  "@typescript-eslint/eslint-plugin": "^4.15.1",
90
100
  "@typescript-eslint/parser": "^4.15.1",
91
101
  "babel-eslint": "^10.0.3",
92
102
  "babel-jest": "^26.6.3",
93
103
  "babel-plugin-module-resolver": "^4.1.0",
104
+ "clang-format": "^1.5.0",
94
105
  "eslint": "^7.31.0",
95
106
  "eslint-config-prettier": "^6.4.0",
96
107
  "eslint-config-standard": "^14.1.0",
@@ -99,28 +110,28 @@
99
110
  "eslint-plugin-node": "^10.0.0",
100
111
  "eslint-plugin-promise": "^4.2.1",
101
112
  "eslint-plugin-standard": "^4.0.1",
102
- "husky": "^4.2.5",
113
+ "husky": "^7.0.0",
103
114
  "jest": "^26.6.3",
104
- "lint-staged": "^10.2.11",
115
+ "lint-staged": "^11.2.0",
105
116
  "prettier": "^2.2.1",
106
117
  "react": "17.0.2",
107
- "react-native": "0.65.1",
118
+ "react-native": "0.67.0-rc.3",
108
119
  "react-native-codegen": "^0.0.7",
109
120
  "react-native-gesture-handler": "^1.6.1",
110
121
  "react-test-renderer": "17.0.2",
111
- "release-it": "^13.1.1",
122
+ "release-it": "^13.7.2",
112
123
  "typescript": "^4.1.3"
113
124
  },
114
125
  "lint-staged": {
115
126
  "*.(js|ts|tsx)": [
116
127
  "eslint --ext '.js,.ts,.tsx' src/ --ignore-pattern src/reanimated1 --ignore-pattern react-native-reanimated.d.ts",
117
128
  "prettier --write"
118
- ]
119
- },
120
- "husky": {
121
- "hooks": {
122
- "pre-commit": "lint-staged"
123
- }
129
+ ],
130
+ "**/*.{h,cpp}": "yarn lint:cpp",
131
+ "android/src/**/*.java": "yarn format:java",
132
+ "android/src/**/*.{h,cpp}": "yarn format:android",
133
+ "ios/**/*.{h,m,mm,cpp}": "yarn format:ios",
134
+ "Common/**/*.{h,cpp}": "yarn format:common"
124
135
  },
125
136
  "release-it": {
126
137
  "hooks": {
package/plugin.js CHANGED
@@ -69,6 +69,7 @@ const globals = new Set([
69
69
  'global',
70
70
  '_measure',
71
71
  '_scrollTo',
72
+ '_setGestureState',
72
73
  '_getCurrentTime',
73
74
  '_eventTimestamp',
74
75
  '_frameTimestamp',
@@ -135,6 +136,33 @@ const blacklistedFunctions = new Set([
135
136
 
136
137
  const possibleOptFunction = new Set(['interpolate']);
137
138
 
139
+ const gestureHandlerGestureObjects = new Set([
140
+ // from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts
141
+ 'Tap',
142
+ 'Pan',
143
+ 'Pinch',
144
+ 'Rotation',
145
+ 'Fling',
146
+ 'LongPress',
147
+ 'ForceTouch',
148
+ 'Native',
149
+ 'Custom',
150
+ 'Race',
151
+ 'Simultaneous',
152
+ 'Exclusive',
153
+ ]);
154
+
155
+ const gestureHandlerBuilderMethods = new Set([
156
+ 'onBegin',
157
+ 'onStart',
158
+ 'onEnd',
159
+ 'onUpdate',
160
+ 'onTouchesDown',
161
+ 'onTouchesMove',
162
+ 'onTouchesUp',
163
+ 'onTouchesCancelled',
164
+ ]);
165
+
138
166
  class ClosureGenerator {
139
167
  constructor() {
140
168
  this.trie = [{}, false];
@@ -285,20 +313,45 @@ function buildWorkletString(t, fun, closureVariables, name) {
285
313
  return generate(workletFunction, { compact: true }).code;
286
314
  }
287
315
 
288
- function processWorkletFunction(t, fun, fileName) {
289
- if (!t.isFunctionParent(fun)) {
290
- return;
316
+ function makeWorkletName(t, fun) {
317
+ if (t.isObjectMethod(fun)) {
318
+ return fun.node.key.name;
319
+ }
320
+ if (t.isFunctionDeclaration(fun)) {
321
+ return fun.node.id.name;
322
+ }
323
+ if (t.isFunctionExpression(fun) && t.isIdentifier(fun.node.id)) {
324
+ return fun.node.id.name;
291
325
  }
292
- const functionName = fun.node.id ? fun.node.id.name : '_f';
326
+ return '_f'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression
327
+ }
328
+
329
+ function makeWorklet(t, fun, fileName) {
330
+ // Returns a new FunctionExpression which is a workletized version of provided
331
+ // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.
332
+
333
+ const functionName = makeWorkletName(t, fun);
293
334
 
294
335
  const closure = new Map();
295
336
  const outputs = new Set();
296
337
  const closureGenerator = new ClosureGenerator();
297
338
  const options = {};
298
339
 
340
+ // remove 'worklet'; directive before calling .toString()
341
+ fun.traverse({
342
+ DirectiveLiteral(path) {
343
+ if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
344
+ path.parentPath.remove();
345
+ }
346
+ },
347
+ });
348
+
299
349
  // We use copy because some of the plugins don't update bindings and
300
350
  // some even break them
301
- const code = '\n(' + fun.toString() + '\n)';
351
+
352
+ const code =
353
+ '\n(' + (t.isObjectMethod(fun) ? 'function ' : '') + fun.toString() + '\n)';
354
+
302
355
  const transformed = transformSync(code, {
303
356
  filename: fileName,
304
357
  presets: ['@babel/preset-typescript'],
@@ -357,7 +410,7 @@ function processWorkletFunction(t, fun, fileName) {
357
410
  closureGenerator.addPath(name, path);
358
411
  },
359
412
  AssignmentExpression(path) {
360
- // test for <somethin>.value = <something> expressions
413
+ // test for <something>.value = <something> expressions
361
414
  const left = path.node.left;
362
415
  if (
363
416
  t.isMemberExpression(left) &&
@@ -369,13 +422,6 @@ function processWorkletFunction(t, fun, fileName) {
369
422
  },
370
423
  });
371
424
 
372
- fun.traverse({
373
- DirectiveLiteral(path) {
374
- if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
375
- path.parentPath.remove();
376
- }
377
- },
378
- });
379
425
  const variables = Array.from(closure.values());
380
426
 
381
427
  const privateFunctionId = t.identifier('_f');
@@ -391,7 +437,7 @@ function processWorkletFunction(t, fun, fileName) {
391
437
  transformed.ast,
392
438
  variables,
393
439
  functionName
394
- ).replace("'worklet';", '');
440
+ );
395
441
  const workletHash = hash(funString);
396
442
 
397
443
  const loc = fun && fun.node && fun.node.loc && fun.node.loc.start;
@@ -402,7 +448,7 @@ function processWorkletFunction(t, fun, fileName) {
402
448
  }
403
449
  }
404
450
 
405
- const steatmentas = [
451
+ const statements = [
406
452
  t.variableDeclaration('const', [
407
453
  t.variableDeclarator(privateFunctionId, funExpression),
408
454
  ]),
@@ -445,7 +491,7 @@ function processWorkletFunction(t, fun, fileName) {
445
491
  ];
446
492
 
447
493
  if (options && options.optFlags) {
448
- steatmentas.push(
494
+ statements.push(
449
495
  t.expressionStatement(
450
496
  t.assignmentExpression(
451
497
  '=',
@@ -460,7 +506,7 @@ function processWorkletFunction(t, fun, fileName) {
460
506
  );
461
507
  }
462
508
 
463
- steatmentas.push(
509
+ statements.push(
464
510
  t.expressionStatement(
465
511
  t.callExpression(
466
512
  t.memberExpression(
@@ -472,20 +518,30 @@ function processWorkletFunction(t, fun, fileName) {
472
518
  )
473
519
  )
474
520
  );
475
- steatmentas.push(t.returnStatement(privateFunctionId));
521
+ statements.push(t.returnStatement(privateFunctionId));
476
522
 
477
- const newFun = t.functionExpression(
478
- fun.id,
479
- [],
480
- t.blockStatement(steatmentas)
481
- );
523
+ const newFun = t.functionExpression(fun.id, [], t.blockStatement(statements));
524
+
525
+ return newFun;
526
+ }
527
+
528
+ function processWorkletFunction(t, fun, fileName) {
529
+ // Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression
530
+ // with a workletized version of itself.
531
+
532
+ if (!t.isFunctionParent(fun)) {
533
+ return;
534
+ }
535
+
536
+ const newFun = makeWorklet(t, fun, fileName);
482
537
 
483
538
  const replacement = t.callExpression(newFun, []);
539
+
484
540
  // we check if function needs to be assigned to variable declaration.
485
541
  // This is needed if function definition directly in a scope. Some other ways
486
542
  // where function definition can be used is for example with variable declaration:
487
543
  // const ggg = function foo() { }
488
- // ^ in such a case we don't need to definte variable for the function
544
+ // ^ in such a case we don't need to define variable for the function
489
545
  const needDeclaration =
490
546
  t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent);
491
547
  fun.replaceWith(
@@ -497,6 +553,23 @@ function processWorkletFunction(t, fun, fileName) {
497
553
  );
498
554
  }
499
555
 
556
+ function processWorkletObjectMethod(t, path, fileName) {
557
+ // Replaces ObjectMethod with a workletized version of itself.
558
+
559
+ if (!t.isFunctionParent(path)) {
560
+ return;
561
+ }
562
+
563
+ const newFun = makeWorklet(t, path, fileName);
564
+
565
+ const replacement = t.objectProperty(
566
+ t.identifier(path.node.key.name),
567
+ t.callExpression(newFun, [])
568
+ );
569
+
570
+ path.replaceWith(replacement);
571
+ }
572
+
500
573
  function processIfWorkletNode(t, fun, fileName) {
501
574
  fun.traverse({
502
575
  DirectiveLiteral(path) {
@@ -522,6 +595,115 @@ function processIfWorkletNode(t, fun, fileName) {
522
595
  });
523
596
  }
524
597
 
598
+ function processIfGestureHandlerEventCallbackFunctionNode(t, fun, fileName) {
599
+ // Auto-workletizes React Native Gesture Handler callback functions.
600
+ // Detects `Gesture.Tap().onEnd(<fun>)` or similar, but skips `something.onEnd(<fun>)`.
601
+ // Supports method chaining as well, e.g. `Gesture.Tap().onStart(<fun1>).onUpdate(<fun2>).onEnd(<fun3>)`.
602
+
603
+ // Example #1: `Gesture.Tap().onEnd(<fun>)`
604
+ /*
605
+ CallExpression(
606
+ callee: MemberExpression(
607
+ object: CallExpression(
608
+ callee: MemberExpression(
609
+ object: Identifier('Gesture')
610
+ property: Identifier('Tap')
611
+ )
612
+ )
613
+ property: Identifier('onEnd')
614
+ )
615
+ arguments: [fun]
616
+ )
617
+ */
618
+
619
+ // Example #2: `Gesture.Tap().onStart(<fun1>).onUpdate(<fun2>).onEnd(<fun3>)`
620
+ /*
621
+ CallExpression(
622
+ callee: MemberExpression(
623
+ object: CallExpression(
624
+ callee: MemberExpression(
625
+ object: CallExpression(
626
+ callee: MemberExpression(
627
+ object: CallExpression(
628
+ callee: MemberExpression(
629
+ object: Identifier('Gesture')
630
+ property: Identifier('Tap')
631
+ )
632
+ )
633
+ property: Identifier('onStart')
634
+ )
635
+ arguments: [fun1]
636
+ )
637
+ property: Identifier('onUpdate')
638
+ )
639
+ arguments: [fun2]
640
+ )
641
+ property: Identifier('onEnd')
642
+ )
643
+ arguments: [fun3]
644
+ )
645
+ */
646
+
647
+ if (
648
+ t.isCallExpression(fun.parent) &&
649
+ isGestureObjectEventCallbackMethod(t, fun.parent.callee)
650
+ ) {
651
+ processWorkletFunction(t, fun, fileName);
652
+ }
653
+ }
654
+
655
+ function isGestureObjectEventCallbackMethod(t, node) {
656
+ // Checks if node matches the pattern `Gesture.Foo()[*].onBar`
657
+ // where `[*]` represents any number of method calls.
658
+ return (
659
+ t.isMemberExpression(node) &&
660
+ t.isIdentifier(node.property) &&
661
+ gestureHandlerBuilderMethods.has(node.property.name) &&
662
+ containsGestureObject(t, node.object)
663
+ );
664
+ }
665
+
666
+ function containsGestureObject(t, node) {
667
+ // Checks if node matches the pattern `Gesture.Foo()[*]`
668
+ // where `[*]` represents any number of chained method calls, like `.something(42)`.
669
+
670
+ // direct call
671
+ if (isGestureObject(t, node)) {
672
+ return true;
673
+ }
674
+
675
+ // method chaining
676
+ if (
677
+ t.isCallExpression(node) &&
678
+ t.isMemberExpression(node.callee) &&
679
+ containsGestureObject(t, node.callee.object)
680
+ ) {
681
+ return true;
682
+ }
683
+
684
+ return false;
685
+ }
686
+
687
+ function isGestureObject(t, node) {
688
+ // Checks if node matches `Gesture.Tap()` or similar.
689
+ /*
690
+ node: CallExpression(
691
+ callee: MemberExpression(
692
+ object: Identifier('Gesture')
693
+ property: Identifier('Tap')
694
+ )
695
+ )
696
+ */
697
+ return (
698
+ t.isCallExpression(node) &&
699
+ t.isMemberExpression(node.callee) &&
700
+ t.isIdentifier(node.callee.object) &&
701
+ node.callee.object.name === 'Gesture' &&
702
+ t.isIdentifier(node.callee.property) &&
703
+ gestureHandlerGestureObjects.has(node.callee.property.name)
704
+ );
705
+ }
706
+
525
707
  function processWorklets(t, path, fileName) {
526
708
  const name =
527
709
  path.node.callee.type === 'MemberExpression'
@@ -531,17 +713,14 @@ function processWorklets(t, path, fileName) {
531
713
  objectHooks.has(name) &&
532
714
  path.get('arguments.0').type === 'ObjectExpression'
533
715
  ) {
534
- const objectPath = path.get('arguments.0.properties.0');
535
- if (!objectPath) {
536
- // edge case empty object
537
- return;
538
- }
539
- for (let i = 0; i < objectPath.container.length; i++) {
540
- processWorkletFunction(
541
- t,
542
- objectPath.getSibling(i).get('value'),
543
- fileName
544
- );
716
+ const properties = path.get('arguments.0.properties');
717
+ for (const property of properties) {
718
+ if (t.isObjectMethod(property)) {
719
+ processWorkletObjectMethod(t, property, fileName);
720
+ } else {
721
+ const value = property.get('value');
722
+ processWorkletFunction(t, value, fileName);
723
+ }
545
724
  }
546
725
  } else {
547
726
  const indexes = functionArgsToWorkletize.get(name);
@@ -558,7 +737,7 @@ const STATEMENTLESS_FLAG = 0b00000010;
558
737
 
559
738
  function isPossibleOptimization(fun) {
560
739
  let isFunctionCall = false;
561
- let isSteatements = false;
740
+ let isStatement = false;
562
741
  traverse(fun, {
563
742
  CallExpression(path) {
564
743
  if (!possibleOptFunction.has(path.node.callee.name)) {
@@ -566,14 +745,14 @@ function isPossibleOptimization(fun) {
566
745
  }
567
746
  },
568
747
  IfStatement() {
569
- isSteatements = true;
748
+ isStatement = true;
570
749
  },
571
750
  });
572
751
  let flags = 0;
573
752
  if (!isFunctionCall) {
574
753
  flags = flags | FUNCTIONLESS_FLAG;
575
754
  }
576
- if (!isSteatements) {
755
+ if (!isStatement) {
577
756
  flags = flags | STATEMENTLESS_FLAG;
578
757
  }
579
758
  return flags;
@@ -597,7 +776,9 @@ module.exports = function ({ types: t }) {
597
776
  },
598
777
  'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {
599
778
  enter(path, state) {
600
- processIfWorkletNode(t, path, state.file.opts.filename);
779
+ const fileName = state.file.opts.filename;
780
+ processIfWorkletNode(t, path, fileName);
781
+ processIfGestureHandlerEventCallbackFunctionNode(t, path, fileName);
601
782
  },
602
783
  },
603
784
  },