react-native-reanimated 2.3.0-beta.1 → 2.3.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 (174) hide show
  1. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +12 -3
  2. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +13 -0
  3. package/Common/cpp/Registries/EventHandlerRegistry.cpp +2 -2
  4. package/Common/cpp/Registries/MapperRegistry.cpp +5 -5
  5. package/Common/cpp/SharedItems/FrozenObject.cpp +1 -3
  6. package/Common/cpp/SharedItems/ShareableValue.cpp +8 -10
  7. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  8. package/Common/cpp/Tools/JSIStoreValueUser.cpp +8 -8
  9. package/Common/cpp/Tools/Mapper.cpp +1 -1
  10. package/Common/cpp/Tools/RuntimeDecorator.cpp +40 -4
  11. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -1
  12. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +5 -0
  13. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +6 -1
  14. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +1 -0
  15. package/Common/cpp/headers/Registries/MapperRegistry.h +1 -0
  16. package/Common/cpp/headers/SharedItems/FrozenObject.h +4 -0
  17. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +2 -0
  18. package/Common/cpp/headers/SharedItems/MutableValue.h +2 -0
  19. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +3 -1
  20. package/Common/cpp/headers/SharedItems/RemoteObject.h +4 -1
  21. package/Common/cpp/headers/SharedItems/ShareableValue.h +2 -0
  22. package/Common/cpp/headers/SharedItems/SharedParent.h +9 -9
  23. package/Common/cpp/headers/SharedItems/ValueWrapper.h +32 -28
  24. package/Common/cpp/headers/SpecTools/ErrorHandler.h +1 -0
  25. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  26. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +2 -5
  27. package/Common/cpp/headers/Tools/Mapper.h +2 -0
  28. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +5 -0
  29. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +1 -5
  30. package/Common/cpp/headers/Tools/RuntimeDecorator.h +10 -7
  31. package/Common/cpp/headers/Tools/Scheduler.h +2 -0
  32. package/Common/cpp/headers/Tools/WorkletEventHandler.h +2 -1
  33. package/Common/cpp/hidden_headers/Logger.h +2 -2
  34. package/Common/cpp/hidden_headers/LoggerInterface.h +1 -1
  35. package/RNReanimated.podspec +24 -6
  36. package/android/build.gradle +33 -13
  37. package/android/expo/linking.gradle +34 -0
  38. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  39. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  40. package/android/react-native-reanimated-63-hermes.aar +0 -0
  41. package/android/react-native-reanimated-63-jsc.aar +0 -0
  42. package/android/react-native-reanimated-64-hermes.aar +0 -0
  43. package/android/react-native-reanimated-64-jsc.aar +0 -0
  44. package/android/react-native-reanimated-65-hermes.aar +0 -0
  45. package/android/react-native-reanimated-65-jsc.aar +0 -0
  46. package/android/react-native-reanimated-66-hermes.aar +0 -0
  47. package/android/react-native-reanimated-66-jsc.aar +0 -0
  48. package/android/react-native-reanimated-67-hermes.aar +0 -0
  49. package/android/react-native-reanimated-67-jsc.aar +0 -0
  50. package/expo-module.config.json +3 -0
  51. package/ios/LayoutReanimation/REAAnimationsManager.m +65 -19
  52. package/ios/LayoutReanimation/REAUIManager.mm +114 -70
  53. package/ios/REAEventDispatcher.m +1 -1
  54. package/ios/REAModule.h +0 -2
  55. package/ios/REAModule.m +0 -3
  56. package/ios/REANodesManager.m +1 -0
  57. package/ios/RNGestureHandlerStateManager.h +5 -0
  58. package/ios/native/NativeMethods.h +5 -0
  59. package/ios/native/NativeMethods.mm +14 -6
  60. package/ios/native/NativeProxy.h +1 -0
  61. package/ios/native/NativeProxy.mm +84 -63
  62. package/ios/native/REAIOSErrorHandler.mm +19 -15
  63. package/ios/native/REAIOSLogger.mm +10 -6
  64. package/ios/native/REAIOSScheduler.mm +17 -10
  65. package/ios/native/REAInitializer.mm +42 -31
  66. package/ios/native/UIResponder+Reanimated.mm +2 -2
  67. package/lib/Animated.js +11 -5
  68. package/lib/ConfigHelper.js +121 -138
  69. package/lib/ReanimatedEventEmitter.js +0 -1
  70. package/lib/ReanimatedModule.js +0 -1
  71. package/lib/ReanimatedModule.macos.js +0 -1
  72. package/lib/ReanimatedModule.native.js +5 -6
  73. package/lib/ReanimatedModule.windows.js +0 -1
  74. package/lib/ReanimatedModuleCompat.js +64 -35
  75. package/lib/createAnimatedComponent.js +469 -499
  76. package/lib/index.js +11 -5
  77. package/lib/reanimated1/core/Core.test.js +1 -1
  78. package/lib/reanimated2/NativeMethods.js +7 -0
  79. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +3 -0
  80. package/lib/reanimated2/PropAdapters.js +0 -1
  81. package/lib/reanimated2/UpdateProps.js +1 -1
  82. package/lib/reanimated2/ViewDescriptorsSet.js +4 -2
  83. package/lib/reanimated2/animation/spring.js +2 -0
  84. package/lib/reanimated2/animation/styleAnimation.js +5 -1
  85. package/lib/reanimated2/animation/util.js +23 -0
  86. package/lib/reanimated2/component/FlatList.js +30 -0
  87. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  88. package/lib/reanimated2/component/index.js +4 -0
  89. package/lib/reanimated2/core.js +30 -3
  90. package/lib/reanimated2/globals.d.ts +8 -0
  91. package/lib/reanimated2/index.js +1 -0
  92. package/lib/reanimated2/js-reanimated/JSReanimated.js +4 -0
  93. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  94. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  95. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  96. package/lib/reanimated2/js-reanimated/index.js +10 -8
  97. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +14 -5
  98. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  99. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  100. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +4 -2
  101. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
  102. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -16
  103. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
  104. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
  105. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +3 -3
  106. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
  107. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
  108. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
  109. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
  110. package/lib/reanimated2/mock.js +3 -1
  111. package/lib/reanimated2/utils.js +9 -0
  112. package/lib/setAndForwardRef.js +14 -48
  113. package/mock.js +1 -1
  114. package/package.json +27 -23
  115. package/plugin.js +111 -110
  116. package/react-native-reanimated.d.ts +63 -25
  117. package/src/Animated.js +11 -5
  118. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  119. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  120. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  121. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  122. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  123. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  124. package/src/ReanimatedModuleCompat.ts +51 -0
  125. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +278 -124
  126. package/src/reanimated1/core/Core.test.js +1 -1
  127. package/src/reanimated2/NativeMethods.ts +13 -1
  128. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +5 -11
  129. package/src/reanimated2/PropAdapters.ts +0 -1
  130. package/src/reanimated2/UpdateProps.ts +1 -1
  131. package/src/reanimated2/ViewDescriptorsSet.ts +6 -2
  132. package/src/reanimated2/animation/commonTypes.ts +4 -4
  133. package/src/reanimated2/animation/decay.ts +2 -2
  134. package/src/reanimated2/animation/delay.ts +3 -3
  135. package/src/reanimated2/animation/index.ts +7 -7
  136. package/src/reanimated2/animation/repeat.ts +4 -4
  137. package/src/reanimated2/animation/sequence.ts +2 -2
  138. package/src/reanimated2/animation/spring.ts +6 -5
  139. package/src/reanimated2/animation/styleAnimation.ts +24 -12
  140. package/src/reanimated2/animation/timing.ts +5 -5
  141. package/src/reanimated2/animation/util.ts +45 -6
  142. package/src/reanimated2/component/FlatList.tsx +44 -0
  143. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  144. package/src/reanimated2/component/index.ts +9 -0
  145. package/src/reanimated2/core.ts +58 -14
  146. package/src/reanimated2/globals.d.ts +8 -0
  147. package/src/reanimated2/hook/useAnimatedStyle.ts +2 -2
  148. package/src/reanimated2/index.ts +1 -0
  149. package/src/reanimated2/js-reanimated/JSReanimated.ts +15 -26
  150. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  151. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  152. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  153. package/src/reanimated2/js-reanimated/index.ts +31 -14
  154. package/src/reanimated2/layoutReanimation/{LayoutAnimationRepository.tsx → LayoutAnimationRepository.ts} +18 -5
  155. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  156. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  157. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  158. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  159. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +10 -2
  160. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  161. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +49 -34
  162. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  163. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  164. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +9 -9
  165. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  166. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  167. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  168. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  169. package/src/reanimated2/mock.ts +3 -1
  170. package/src/reanimated2/utils.ts +21 -0
  171. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  172. package/android/react-native-reanimated-62-hermes.aar +0 -0
  173. package/android/react-native-reanimated-62-jsc.aar +0 -0
  174. package/src/ReanimatedModuleCompat.js +0 -37
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',
@@ -145,61 +146,22 @@ const gestureHandlerGestureObjects = new Set([
145
146
  'LongPress',
146
147
  'ForceTouch',
147
148
  'Native',
149
+ 'Manual',
148
150
  'Race',
149
151
  'Simultaneous',
150
152
  'Exclusive',
151
153
  ]);
152
154
 
153
155
  const gestureHandlerBuilderMethods = new Set([
154
- // BaseGesture
155
- 'withRef',
156
- 'onBegan',
156
+ 'onBegin',
157
157
  'onStart',
158
158
  'onEnd',
159
- 'enabled',
160
- 'shouldCancelWhenOutside',
161
- 'hitSlop',
162
- 'simultaneousWithExternalGesture',
163
- 'requireExternalGestureToFail',
164
-
165
- // ContinousBaseGesture
159
+ 'onFinalize',
166
160
  'onUpdate',
167
-
168
- // TapGesture
169
- 'minPointers',
170
- 'numberOfTaps',
171
- 'maxDistance',
172
- 'maxDuration',
173
- 'maxDelay',
174
- 'maxDeltaX',
175
- 'maxDeltaY',
176
-
177
- // PanGesture
178
- 'activeOffsetY',
179
- 'activeOffsetX',
180
- 'failOffsetY',
181
- 'failOffsetX',
182
- 'minPointers',
183
- 'minDistance',
184
- 'averageTouches',
185
- 'enableTrackpadTwoFingerGesture',
186
-
187
- // FlingGesture
188
- 'numberOfPointers',
189
- 'direction',
190
-
191
- // LongPress
192
- 'minDuration',
193
- 'maxDistance',
194
-
195
- // ForceTouchGesture:
196
- 'minForce',
197
- 'maxForce',
198
- 'feedbackOnActivation',
199
-
200
- // NativeGesture
201
- 'shouldActivateOnStart',
202
- 'disallowInterruption',
161
+ 'onTouchesDown',
162
+ 'onTouchesMove',
163
+ 'onTouchesUp',
164
+ 'onTouchesCancelled',
203
165
  ]);
204
166
 
205
167
  class ClosureGenerator {
@@ -352,20 +314,45 @@ function buildWorkletString(t, fun, closureVariables, name) {
352
314
  return generate(workletFunction, { compact: true }).code;
353
315
  }
354
316
 
355
- function processWorkletFunction(t, fun, fileName) {
356
- if (!t.isFunctionParent(fun)) {
357
- return;
317
+ function makeWorkletName(t, fun) {
318
+ if (t.isObjectMethod(fun)) {
319
+ return fun.node.key.name;
358
320
  }
359
- const functionName = fun.node.id ? fun.node.id.name : '_f';
321
+ if (t.isFunctionDeclaration(fun)) {
322
+ return fun.node.id.name;
323
+ }
324
+ if (t.isFunctionExpression(fun) && t.isIdentifier(fun.node.id)) {
325
+ return fun.node.id.name;
326
+ }
327
+ return '_f'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression
328
+ }
329
+
330
+ function makeWorklet(t, fun, fileName) {
331
+ // Returns a new FunctionExpression which is a workletized version of provided
332
+ // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.
333
+
334
+ const functionName = makeWorkletName(t, fun);
360
335
 
361
336
  const closure = new Map();
362
337
  const outputs = new Set();
363
338
  const closureGenerator = new ClosureGenerator();
364
339
  const options = {};
365
340
 
341
+ // remove 'worklet'; directive before calling .toString()
342
+ fun.traverse({
343
+ DirectiveLiteral(path) {
344
+ if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
345
+ path.parentPath.remove();
346
+ }
347
+ },
348
+ });
349
+
366
350
  // We use copy because some of the plugins don't update bindings and
367
351
  // some even break them
368
- const code = '\n(' + fun.toString() + '\n)';
352
+
353
+ const code =
354
+ '\n(' + (t.isObjectMethod(fun) ? 'function ' : '') + fun.toString() + '\n)';
355
+
369
356
  const transformed = transformSync(code, {
370
357
  filename: fileName,
371
358
  presets: ['@babel/preset-typescript'],
@@ -424,7 +411,7 @@ function processWorkletFunction(t, fun, fileName) {
424
411
  closureGenerator.addPath(name, path);
425
412
  },
426
413
  AssignmentExpression(path) {
427
- // test for <somethin>.value = <something> expressions
414
+ // test for <something>.value = <something> expressions
428
415
  const left = path.node.left;
429
416
  if (
430
417
  t.isMemberExpression(left) &&
@@ -436,13 +423,6 @@ function processWorkletFunction(t, fun, fileName) {
436
423
  },
437
424
  });
438
425
 
439
- fun.traverse({
440
- DirectiveLiteral(path) {
441
- if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
442
- path.parentPath.remove();
443
- }
444
- },
445
- });
446
426
  const variables = Array.from(closure.values());
447
427
 
448
428
  const privateFunctionId = t.identifier('_f');
@@ -458,7 +438,7 @@ function processWorkletFunction(t, fun, fileName) {
458
438
  transformed.ast,
459
439
  variables,
460
440
  functionName
461
- ).replace("'worklet';", '');
441
+ );
462
442
  const workletHash = hash(funString);
463
443
 
464
444
  const loc = fun && fun.node && fun.node.loc && fun.node.loc.start;
@@ -469,7 +449,7 @@ function processWorkletFunction(t, fun, fileName) {
469
449
  }
470
450
  }
471
451
 
472
- const steatmentas = [
452
+ const statements = [
473
453
  t.variableDeclaration('const', [
474
454
  t.variableDeclarator(privateFunctionId, funExpression),
475
455
  ]),
@@ -512,7 +492,7 @@ function processWorkletFunction(t, fun, fileName) {
512
492
  ];
513
493
 
514
494
  if (options && options.optFlags) {
515
- steatmentas.push(
495
+ statements.push(
516
496
  t.expressionStatement(
517
497
  t.assignmentExpression(
518
498
  '=',
@@ -527,7 +507,7 @@ function processWorkletFunction(t, fun, fileName) {
527
507
  );
528
508
  }
529
509
 
530
- steatmentas.push(
510
+ statements.push(
531
511
  t.expressionStatement(
532
512
  t.callExpression(
533
513
  t.memberExpression(
@@ -539,20 +519,30 @@ function processWorkletFunction(t, fun, fileName) {
539
519
  )
540
520
  )
541
521
  );
542
- steatmentas.push(t.returnStatement(privateFunctionId));
522
+ statements.push(t.returnStatement(privateFunctionId));
543
523
 
544
- const newFun = t.functionExpression(
545
- fun.id,
546
- [],
547
- t.blockStatement(steatmentas)
548
- );
524
+ const newFun = t.functionExpression(fun.id, [], t.blockStatement(statements));
525
+
526
+ return newFun;
527
+ }
528
+
529
+ function processWorkletFunction(t, fun, fileName) {
530
+ // Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression
531
+ // with a workletized version of itself.
532
+
533
+ if (!t.isFunctionParent(fun)) {
534
+ return;
535
+ }
536
+
537
+ const newFun = makeWorklet(t, fun, fileName);
549
538
 
550
539
  const replacement = t.callExpression(newFun, []);
540
+
551
541
  // we check if function needs to be assigned to variable declaration.
552
542
  // This is needed if function definition directly in a scope. Some other ways
553
543
  // where function definition can be used is for example with variable declaration:
554
544
  // const ggg = function foo() { }
555
- // ^ in such a case we don't need to definte variable for the function
545
+ // ^ in such a case we don't need to define variable for the function
556
546
  const needDeclaration =
557
547
  t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent);
558
548
  fun.replaceWith(
@@ -564,6 +554,23 @@ function processWorkletFunction(t, fun, fileName) {
564
554
  );
565
555
  }
566
556
 
557
+ function processWorkletObjectMethod(t, path, fileName) {
558
+ // Replaces ObjectMethod with a workletized version of itself.
559
+
560
+ if (!t.isFunctionParent(path)) {
561
+ return;
562
+ }
563
+
564
+ const newFun = makeWorklet(t, path, fileName);
565
+
566
+ const replacement = t.objectProperty(
567
+ t.identifier(path.node.key.name),
568
+ t.callExpression(newFun, [])
569
+ );
570
+
571
+ path.replaceWith(replacement);
572
+ }
573
+
567
574
  function processIfWorkletNode(t, fun, fileName) {
568
575
  fun.traverse({
569
576
  DirectiveLiteral(path) {
@@ -648,36 +655,33 @@ function processIfGestureHandlerEventCallbackFunctionNode(t, fun, fileName) {
648
655
 
649
656
  function isGestureObjectEventCallbackMethod(t, node) {
650
657
  // Checks if node matches the pattern `Gesture.Foo()[*].onBar`
651
- // where `[*]` represents any number of `.onBar(...)` or similar method calls.
652
- /*
653
- node: MemberExpression(
654
- object: CallExpression(
655
- callee: MemberExpression(
656
- object: Identifier('Gesture')
657
- property: Identifier('Tap')
658
- )
659
- )
660
- property: Identifier('onEnd')
661
- )
662
- */
663
- if (
658
+ // where `[*]` represents any number of method calls.
659
+ return (
664
660
  t.isMemberExpression(node) &&
665
661
  t.isIdentifier(node.property) &&
666
- gestureHandlerBuilderMethods.has(node.property.name)
667
- ) {
668
- // direct call
669
- if (isGestureObject(t, node.object)) {
670
- return true;
671
- }
662
+ gestureHandlerBuilderMethods.has(node.property.name) &&
663
+ containsGestureObject(t, node.object)
664
+ );
665
+ }
672
666
 
673
- // method chaining
674
- if (
675
- t.isCallExpression(node.object) &&
676
- isGestureObjectEventCallbackMethod(t, node.object.callee)
677
- ) {
678
- return true;
679
- }
667
+ function containsGestureObject(t, node) {
668
+ // Checks if node matches the pattern `Gesture.Foo()[*]`
669
+ // where `[*]` represents any number of chained method calls, like `.something(42)`.
670
+
671
+ // direct call
672
+ if (isGestureObject(t, node)) {
673
+ return true;
680
674
  }
675
+
676
+ // method chaining
677
+ if (
678
+ t.isCallExpression(node) &&
679
+ t.isMemberExpression(node.callee) &&
680
+ containsGestureObject(t, node.callee.object)
681
+ ) {
682
+ return true;
683
+ }
684
+
681
685
  return false;
682
686
  }
683
687
 
@@ -710,17 +714,14 @@ function processWorklets(t, path, fileName) {
710
714
  objectHooks.has(name) &&
711
715
  path.get('arguments.0').type === 'ObjectExpression'
712
716
  ) {
713
- const objectPath = path.get('arguments.0.properties.0');
714
- if (!objectPath) {
715
- // edge case empty object
716
- return;
717
- }
718
- for (let i = 0; i < objectPath.container.length; i++) {
719
- processWorkletFunction(
720
- t,
721
- objectPath.getSibling(i).get('value'),
722
- fileName
723
- );
717
+ const properties = path.get('arguments.0.properties');
718
+ for (const property of properties) {
719
+ if (t.isObjectMethod(property)) {
720
+ processWorkletObjectMethod(t, property, fileName);
721
+ } else {
722
+ const value = property.get('value');
723
+ processWorkletFunction(t, value, fileName);
724
+ }
724
725
  }
725
726
  } else {
726
727
  const indexes = functionArgsToWorkletize.get(name);
@@ -737,7 +738,7 @@ const STATEMENTLESS_FLAG = 0b00000010;
737
738
 
738
739
  function isPossibleOptimization(fun) {
739
740
  let isFunctionCall = false;
740
- let isSteatements = false;
741
+ let isStatement = false;
741
742
  traverse(fun, {
742
743
  CallExpression(path) {
743
744
  if (!possibleOptFunction.has(path.node.callee.name)) {
@@ -745,14 +746,14 @@ function isPossibleOptimization(fun) {
745
746
  }
746
747
  },
747
748
  IfStatement() {
748
- isSteatements = true;
749
+ isStatement = true;
749
750
  },
750
751
  });
751
752
  let flags = 0;
752
753
  if (!isFunctionCall) {
753
754
  flags = flags | FUNCTIONLESS_FLAG;
754
755
  }
755
- if (!isSteatements) {
756
+ if (!isStatement) {
756
757
  flags = flags | STATEMENTLESS_FLAG;
757
758
  }
758
759
  return flags;
@@ -26,6 +26,7 @@ declare module 'react-native-reanimated' {
26
26
  Text as ReactNativeText,
27
27
  Image as ReactNativeImage,
28
28
  ScrollView as ReactNativeScrollView,
29
+ FlatList as ReactNativeFlatList,
29
30
  NativeScrollEvent,
30
31
  NativeSyntheticEvent,
31
32
  ColorValue,
@@ -36,6 +37,18 @@ declare module 'react-native-reanimated' {
36
37
  GestureHandlerGestureEvent,
37
38
  PanGestureHandlerGestureEvent,
38
39
  } from 'react-native-gesture-handler';
40
+
41
+ export {
42
+ Animation,
43
+ TimingAnimation,
44
+ SpringAnimation,
45
+ DecayAnimation,
46
+ DelayAnimation,
47
+ RepeatAnimation,
48
+ SequenceAnimation,
49
+ StyleLayoutAnimation,
50
+ } from './src/reanimated2/animation/index';
51
+
39
52
  namespace Animated {
40
53
  type Nullable<T> = T | null | undefined;
41
54
  class AnimatedNode<T> {
@@ -244,6 +257,10 @@ declare module 'react-native-reanimated' {
244
257
  getNode(): ReactNativeScrollView;
245
258
  }
246
259
  export class Code extends Component<CodeProps> {}
260
+ export class FlatList extends Component<AnimateProps<FlatList>> {
261
+ itemLayoutAnimation: ILayoutAnimationBuilder;
262
+ getNode(): ReactNativeFlatList;
263
+ }
247
264
 
248
265
  type Options<P> = {
249
266
  setNativeProps: (ref: any, props: P) => void;
@@ -439,34 +456,45 @@ declare module 'react-native-reanimated' {
439
456
  animations: AnimateStyle;
440
457
  };
441
458
 
442
- export type EntryExitAnimationsValues = {
443
- originX: number;
444
- originY: number;
445
- width: number;
446
- height: number;
447
- globalOriginX: number;
448
- globalOriginY: number;
449
- };
459
+ export interface EntryAnimationsValues {
460
+ targetOriginX: number;
461
+ targetOriginY: number;
462
+ targetWidth: number;
463
+ targetHeight: number;
464
+ targetGlobalOriginX: number;
465
+ targetGlobalOriginY: number;
466
+ }
467
+
468
+ export interface ExitAnimationsValues {
469
+ currentOriginX: number;
470
+ currentOriginY: number;
471
+ currentWidth: number;
472
+ currentHeight: number;
473
+ currentGlobalOriginX: number;
474
+ currentGlobalOriginY: number;
475
+ }
476
+
450
477
  export type EntryExitAnimationFunction = (
451
- targetValues: EntryExitAnimationsValues
478
+ targetValues: EntryAnimationsValues | ExitAnimationsValues
452
479
  ) => LayoutAnimation;
453
480
 
454
481
  export type LayoutAnimationsValues = {
455
- originX: number;
456
- originY: number;
457
- width: number;
458
- height: number;
459
- globalOriginX: number;
460
- globalOriginY: number;
461
- boriginX: number;
462
- boriginY: number;
463
- bwidth: number;
464
- bheight: number;
465
- bglobalOriginX: number;
466
- bglobalOriginY: number;
482
+ currentOriginX: number;
483
+ currentOriginY: number;
484
+ currentWidth: number;
485
+ currentHeight: number;
486
+ currentGlobalOriginX: number;
487
+ currentGlobalOriginY: number;
488
+ targetOriginX: number;
489
+ targetOriginY: number;
490
+ targetWidth: number;
491
+ targetHeight: number;
492
+ targetGlobalOriginX: number;
493
+ targetGlobalOriginY: number;
467
494
  windowWidth: number;
468
495
  windowHeight: number;
469
496
  };
497
+
470
498
  export type LayoutAnimationFunction = (
471
499
  targetValues: LayoutAnimationsValues
472
500
  ) => LayoutAnimation;
@@ -479,7 +507,7 @@ declare module 'react-native-reanimated' {
479
507
  build: () => EntryExitAnimationFunction;
480
508
  }
481
509
 
482
- export type PrimitiveValue = number | string;
510
+ export type AnimatableValue = number | string | Array<number>;
483
511
 
484
512
  // reanimated2 derived operations
485
513
  export enum Extrapolation {
@@ -511,7 +539,7 @@ declare module 'react-native-reanimated' {
511
539
  // reanimated2 animations
512
540
  export type AnimationCallback = (
513
541
  finished?: boolean,
514
- current?: PrimitiveValue
542
+ current?: AnimatableValue
515
543
  ) => void;
516
544
  export interface WithTimingConfig {
517
545
  duration?: number;
@@ -533,12 +561,12 @@ declare module 'react-native-reanimated' {
533
561
  velocity?: number;
534
562
  }
535
563
  export function withTiming(
536
- toValue: PrimitiveValue,
564
+ toValue: AnimatableValue,
537
565
  userConfig?: WithTimingConfig,
538
566
  callback?: AnimationCallback
539
567
  ): number;
540
568
  export function withSpring(
541
- toValue: PrimitiveValue,
569
+ toValue: AnimatableValue,
542
570
  userConfig?: WithSpringConfig,
543
571
  callback?: AnimationCallback
544
572
  ): number;
@@ -649,6 +677,15 @@ declare module 'react-native-reanimated' {
649
677
  pageY: number;
650
678
  };
651
679
 
680
+ export function getRelativeCoords(
681
+ ref: RefObject<Component>,
682
+ x: number,
683
+ y: number
684
+ ): {
685
+ x: number;
686
+ y: number;
687
+ };
688
+
652
689
  export function scrollTo(
653
690
  ref: RefObject<ReactNativeScrollView | ScrollView>,
654
691
  x: number,
@@ -1050,4 +1087,5 @@ declare module 'react-native-reanimated' {
1050
1087
  export const SpringUtils: typeof Animated.SpringUtils;
1051
1088
  export const useValue: typeof Animated.useValue;
1052
1089
  export const ReverseAnimation: typeof Animated.ReverseAnimation;
1090
+ export function enableLayoutAnimations(flag: boolean): void;
1053
1091
  }
package/src/Animated.js CHANGED
@@ -1,17 +1,15 @@
1
- import { Image, ScrollView, Text, View } from 'react-native';
1
+ import { LogBox } from 'react-native';
2
2
  import createAnimatedComponent from './createAnimatedComponent';
3
3
  import {
4
4
  addWhitelistedNativeProps,
5
5
  addWhitelistedUIProps,
6
6
  } from './ConfigHelper';
7
7
  import * as reanimated1 from './reanimated1';
8
+ import ReanimatedComponents from './reanimated2/component';
8
9
 
9
10
  const Animated = {
10
11
  // components
11
- View: createAnimatedComponent(View),
12
- Text: createAnimatedComponent(Text),
13
- Image: createAnimatedComponent(Image),
14
- ScrollView: createAnimatedComponent(ScrollView),
12
+ ...ReanimatedComponents,
15
13
  createAnimatedComponent,
16
14
  // configuration
17
15
  addWhitelistedNativeProps,
@@ -23,3 +21,11 @@ const Animated = {
23
21
  export * from './reanimated2';
24
22
  export * from './reanimated1';
25
23
  export default Animated;
24
+
25
+ // I think we can ignore this message as long as Gesture Handler doesn't
26
+ // try to load the Reanimated module. I figured it should be here instead of
27
+ // RNGH because this prevents the message from being displayed for all
28
+ // versions of RNGH.
29
+ LogBox.ignoreLogs([
30
+ 'RCTBridge required dispatch_sync to load RNGestureHandlerModule. This may lead to deadlocks',
31
+ ]);
@@ -3,7 +3,7 @@ import ReanimatedModule from './ReanimatedModule';
3
3
  /**
4
4
  * Styles allowed to be direcly updated in UI thread
5
5
  */
6
- let UI_THREAD_PROPS_WHITELIST = {
6
+ let UI_THREAD_PROPS_WHITELIST: Record<string, boolean> = {
7
7
  opacity: true,
8
8
  transform: true,
9
9
  /* colors */
@@ -28,7 +28,7 @@ let UI_THREAD_PROPS_WHITELIST = {
28
28
  /**
29
29
  * Whitelist of view props that can be updated in native thread via UIManagerModule
30
30
  */
31
- let NATIVE_THREAD_PROPS_WHITELIST = {
31
+ let NATIVE_THREAD_PROPS_WHITELIST: Record<string, boolean> = {
32
32
  borderBottomWidth: true,
33
33
  borderEndWidth: true,
34
34
  borderLeftWidth: true,
@@ -106,14 +106,16 @@ let NATIVE_THREAD_PROPS_WHITELIST = {
106
106
  placeholderTextColor: true,
107
107
  };
108
108
 
109
- function configureProps() {
109
+ function configureProps(): void {
110
110
  ReanimatedModule.configureProps(
111
111
  Object.keys(NATIVE_THREAD_PROPS_WHITELIST),
112
112
  Object.keys(UI_THREAD_PROPS_WHITELIST)
113
113
  );
114
114
  }
115
115
 
116
- export function addWhitelistedNativeProps(props) {
116
+ export function addWhitelistedNativeProps(
117
+ props: Record<string, boolean>
118
+ ): void {
117
119
  const oldSize = Object.keys(NATIVE_THREAD_PROPS_WHITELIST).length;
118
120
  NATIVE_THREAD_PROPS_WHITELIST = {
119
121
  ...NATIVE_THREAD_PROPS_WHITELIST,
@@ -124,7 +126,7 @@ export function addWhitelistedNativeProps(props) {
124
126
  }
125
127
  }
126
128
 
127
- export function addWhitelistedUIProps(props) {
129
+ export function addWhitelistedUIProps(props: Record<string, boolean>): void {
128
130
  const oldSize = Object.keys(UI_THREAD_PROPS_WHITELIST).length;
129
131
  UI_THREAD_PROPS_WHITELIST = { ...UI_THREAD_PROPS_WHITELIST, ...props };
130
132
  if (oldSize !== Object.keys(UI_THREAD_PROPS_WHITELIST).length) {
@@ -133,17 +135,23 @@ export function addWhitelistedUIProps(props) {
133
135
  }
134
136
 
135
137
  const PROCESSED_VIEW_NAMES = new Set();
138
+
139
+ interface ViewConfig {
140
+ uiViewClassName: string;
141
+ validAttributes: Record<string, unknown>;
142
+ }
136
143
  /**
137
144
  * updates UI props whitelist for given view host instance
138
145
  * this will work just once for every view name
139
146
  */
140
- export function adaptViewConfig(viewConfig) {
147
+
148
+ export function adaptViewConfig(viewConfig: ViewConfig): void {
141
149
  const viewName = viewConfig.uiViewClassName;
142
150
  const props = viewConfig.validAttributes;
143
151
 
144
152
  // update whitelist of UI props for this view name only once
145
153
  if (!PROCESSED_VIEW_NAMES.has(viewName)) {
146
- const propsToAdd = {};
154
+ const propsToAdd: Record<string, boolean> = {};
147
155
  Object.keys(props).forEach((key) => {
148
156
  // we don't want to add native props as they affect layout
149
157
  // we also skip props which repeat here
@@ -0,0 +1,51 @@
1
+ export default {
2
+ async disconnectNodeFromView(): Promise<void> {
3
+ // noop
4
+ },
5
+ async attachEvent(
6
+ _viewTag: number,
7
+ _eventName: string,
8
+ _nodeID: number
9
+ ): Promise<void> {
10
+ // noop
11
+ },
12
+ async detachEvent(
13
+ _viewTag: number,
14
+ _eventName: string,
15
+ _nodeID: number
16
+ ): Promise<void> {
17
+ // noop
18
+ },
19
+ async createNode(
20
+ _nodeID: number,
21
+ _config: Record<string, unknown>
22
+ ): Promise<void> {
23
+ // noop
24
+ },
25
+ async dropNode(_nodeID: number): Promise<void> {
26
+ // noop
27
+ },
28
+ async configureProps(
29
+ _nativeProps: string[],
30
+ _uiProps: string[]
31
+ ): Promise<void> {
32
+ // noop
33
+ },
34
+ async disconnectNodes(): Promise<void> {
35
+ // noop
36
+ },
37
+ async addListener(): Promise<void> {
38
+ // noop
39
+ },
40
+ async removeListeners(): Promise<void> {
41
+ // noop
42
+ },
43
+ async removeAllListeners(): Promise<void> {
44
+ // noop
45
+ },
46
+ async animateNextTransition(): Promise<void> {
47
+ console.warn(
48
+ 'Reanimated: animateNextTransition is unimplemented on current platform'
49
+ );
50
+ },
51
+ };