react-native-reanimated 2.10.0 → 2.12.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 (146) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +3 -0
  2. package/Common/cpp/{headers/AnimatedSensor → AnimatedSensor}/AnimatedSensorModule.h +0 -0
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
  4. package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +2 -0
  6. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModule.h +5 -0
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +2 -0
  8. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModuleSpec.h +1 -1
  9. package/Common/cpp/{headers/Registries → Registries}/EventHandlerRegistry.h +0 -0
  10. package/Common/cpp/Registries/MapperRegistry.cpp +3 -1
  11. package/Common/cpp/{headers/Registries → Registries}/MapperRegistry.h +0 -0
  12. package/Common/cpp/Registries/WorkletsCache.cpp +3 -0
  13. package/Common/cpp/{headers/Registries → Registries}/WorkletsCache.h +0 -0
  14. package/Common/cpp/{headers/SharedItems → SharedItems}/FrozenObject.h +0 -0
  15. package/Common/cpp/{headers/SharedItems → SharedItems}/HostFunctionHandler.h +0 -0
  16. package/Common/cpp/SharedItems/MutableValue.cpp +2 -0
  17. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValue.h +0 -0
  18. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValueSetterProxy.h +0 -0
  19. package/Common/cpp/{headers/SharedItems → SharedItems}/RemoteObject.h +0 -0
  20. package/Common/cpp/{headers/SharedItems → SharedItems}/RuntimeManager.h +0 -0
  21. package/Common/cpp/SharedItems/ShareableValue.cpp +7 -2
  22. package/Common/cpp/{headers/SharedItems → SharedItems}/ShareableValue.h +0 -0
  23. package/Common/cpp/{headers/SharedItems → SharedItems}/SharedParent.h +0 -0
  24. package/Common/cpp/{headers/SharedItems → SharedItems}/ValueWrapper.h +0 -0
  25. package/Common/cpp/{headers/SpecTools → SpecTools}/ErrorHandler.h +0 -0
  26. package/Common/cpp/{headers/Tools → Tools}/FeaturesConfig.h +0 -0
  27. package/Common/cpp/Tools/JSIStoreValueUser.cpp +2 -2
  28. package/Common/cpp/{headers/Tools → Tools}/JSIStoreValueUser.h +0 -0
  29. package/Common/cpp/{headers/Tools → Tools}/Mapper.h +0 -0
  30. package/Common/cpp/{headers/Tools → Tools}/PlatformDepMethodsHolder.h +0 -0
  31. package/Common/cpp/{headers/Tools → Tools}/ReanimatedHiddenHeaders.h +1 -1
  32. package/Common/cpp/{headers/Tools → Tools}/RuntimeDecorator.h +0 -0
  33. package/Common/cpp/{headers/Tools → Tools}/Scheduler.h +0 -0
  34. package/Common/cpp/Tools/SingleInstanceChecker.h +58 -0
  35. package/Common/cpp/{headers/Tools → Tools}/WorkletEventHandler.h +0 -0
  36. package/RNReanimated.podspec +19 -75
  37. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  38. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  39. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  40. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  41. package/android/.gradle/{7.2 → 7.5.1}/dependencies-accessors/gc.properties +0 -0
  42. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  43. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  44. package/android/.gradle/{7.2 → 7.5.1}/fileChanges/last-build.bin +0 -0
  45. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  46. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  47. package/android/.gradle/{7.2 → 7.5.1}/fileHashes/resourceHashesCache.bin +0 -0
  48. package/android/.gradle/{7.2 → 7.5.1}/gc.properties +0 -0
  49. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  50. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  51. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  52. package/android/.gradle/file-system.probe +0 -0
  53. package/android/CMakeLists.txt +56 -65
  54. package/android/build.gradle +422 -120
  55. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  56. package/android/react-native-reanimated-66-hermes.aar +0 -0
  57. package/android/react-native-reanimated-66-jsc.aar +0 -0
  58. package/android/react-native-reanimated-67-hermes.aar +0 -0
  59. package/android/react-native-reanimated-67-jsc.aar +0 -0
  60. package/android/react-native-reanimated-68-hermes.aar +0 -0
  61. package/android/react-native-reanimated-68-jsc.aar +0 -0
  62. package/android/react-native-reanimated-69-hermes.aar +0 -0
  63. package/android/react-native-reanimated-69-jsc.aar +0 -0
  64. package/android/react-native-reanimated-70-hermes.aar +0 -0
  65. package/android/react-native-reanimated-70-jsc.aar +0 -0
  66. package/android/src/main/cpp/AndroidErrorHandler.cpp +3 -4
  67. package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +1 -4
  68. package/android/src/main/cpp/AndroidLogger.cpp +4 -1
  69. package/android/src/main/cpp/{headers/AndroidLogger.h → AndroidLogger.h} +0 -0
  70. package/android/src/main/cpp/{headers/AndroidScheduler.h → AndroidScheduler.h} +0 -0
  71. package/android/src/main/cpp/{headers/JNIHelper.h → JNIHelper.h} +0 -0
  72. package/android/src/main/cpp/{headers/LayoutAnimations.h → LayoutAnimations.h} +0 -0
  73. package/android/src/main/cpp/NativeProxy.cpp +6 -8
  74. package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +0 -0
  75. package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
  76. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +4 -5
  77. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
  78. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +2 -2
  79. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +1 -1
  80. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/UIImplementation/64/com/swmansion/reanimated}/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  81. package/android/src/{main/java → reactNativeVersionPatch/UIImplementation/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  82. package/android/src/reactNativeVersionPatch/messageQueueThread/67/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  83. package/android/src/reactNativeVersionPatch/messageQueueThread/latest/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  84. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated}/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  85. package/android/src/{main/java → reactNativeVersionPatch/nativeHierarchyManager/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  86. package/ios/{REAModule.m → REAModule.mm} +29 -0
  87. package/ios/keyboardObserver/REAKeyboardEventObserver.m +1 -1
  88. package/ios/native/NativeProxy.mm +4 -2
  89. package/ios/native/REAInitializer.h +2 -2
  90. package/ios/native/REAInitializer.mm +2 -2
  91. package/ios/native/UIResponder+Reanimated.mm +1 -1
  92. package/lib/createAnimatedComponent.js +3 -4
  93. package/lib/index.web.js +2 -0
  94. package/lib/reanimated2/NativeMethods.js +79 -30
  95. package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  96. package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +47 -18
  97. package/lib/reanimated2/globals.d.ts +38 -12
  98. package/lib/reanimated2/hook/index.js +1 -0
  99. package/lib/reanimated2/hook/useScrollViewOffset.js +27 -0
  100. package/lib/reanimated2/utils.js +10 -3
  101. package/lib/types/index.web.d.ts +1 -0
  102. package/lib/types/reanimated2/NativeMethods.d.ts +4 -11
  103. package/lib/types/reanimated2/commonTypes.d.ts +8 -0
  104. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +4 -3
  105. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +17 -7
  106. package/lib/types/reanimated2/hook/index.d.ts +1 -0
  107. package/lib/types/reanimated2/hook/useAnimatedScrollHandler.d.ts +1 -2
  108. package/lib/types/reanimated2/hook/useFrameCallback.d.ts +2 -1
  109. package/lib/types/reanimated2/hook/useScrollViewOffset.d.ts +4 -0
  110. package/lib/types/reanimated2/utils.d.ts +5 -1
  111. package/package.json +8 -6
  112. package/plugin.js +1 -1
  113. package/react-native-reanimated.d.ts +13 -9
  114. package/scripts/reanimated_utils.rb +77 -0
  115. package/src/createAnimatedComponent.tsx +2 -3
  116. package/src/index.web.ts +2 -0
  117. package/src/reanimated2/NativeMethods.ts +104 -48
  118. package/src/reanimated2/commonTypes.ts +9 -0
  119. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
  120. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
  121. package/src/reanimated2/globals.d.ts +38 -12
  122. package/src/reanimated2/hook/index.ts +1 -0
  123. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
  124. package/src/reanimated2/hook/useFrameCallback.ts +2 -1
  125. package/src/reanimated2/hook/useScrollViewOffset.ts +37 -0
  126. package/src/reanimated2/utils.ts +12 -5
  127. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  128. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  129. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  130. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  131. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  132. package/android/.gradle/checksums/checksums.lock +0 -0
  133. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  134. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  135. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  136. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  137. package/android/rnVersionPatch/65/.gitkeep +0 -0
  138. package/android/rnVersionPatch/66/.gitkeep +0 -0
  139. package/android/rnVersionPatch/67/.gitkeep +0 -0
  140. package/android/rnVersionPatch/68/.gitkeep +0 -0
  141. package/android/rnVersionPatch/69/.gitkeep +0 -0
  142. package/android/rnVersionPatch/70/.gitkeep +0 -0
  143. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  144. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
  145. package/lib/reanimated2/__mocks__/NativeReanimated.native.js +0 -20
  146. package/lib/types/reanimated2/__mocks__/NativeReanimated.native.d.ts +0 -13
@@ -1,5 +1,5 @@
1
1
  distributionBase=GRADLE_USER_HOME
2
2
  distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
4
4
  zipStoreBase=GRADLE_USER_HOME
5
5
  zipStorePath=wrapper/dists
@@ -1,5 +1,6 @@
1
1
  #include "AndroidErrorHandler.h"
2
2
  #include <fbjni/fbjni.h>
3
+ #include <exception>
3
4
  #include <string>
4
5
  #include "Logger.h"
5
6
 
@@ -17,11 +18,9 @@ void AndroidErrorHandler::raiseSpec() {
17
18
  return;
18
19
  }
19
20
 
20
- static const auto cls = javaClassStatic();
21
- static auto method = cls->getStaticMethod<void(std::string)>("raise");
22
- method(cls, error->message);
23
-
21
+ // mark error as handled before this method throws exception
24
22
  this->error->handled = true;
23
+ throw std::runtime_error(this->error->message);
25
24
  }
26
25
 
27
26
  std::shared_ptr<Scheduler> AndroidErrorHandler::getScheduler() {
@@ -11,15 +11,12 @@
11
11
 
12
12
  namespace reanimated {
13
13
 
14
- class AndroidErrorHandler : public JavaClass<AndroidErrorHandler>,
15
- public ErrorHandler {
14
+ class AndroidErrorHandler : public ErrorHandler {
16
15
  std::shared_ptr<ErrorWrapper> error;
17
16
  std::shared_ptr<Scheduler> scheduler;
18
17
  void raiseSpec() override;
19
18
 
20
19
  public:
21
- static auto constexpr kJavaDescriptor =
22
- "Lcom/swmansion/reanimated/AndroidErrorHandler;";
23
20
  explicit AndroidErrorHandler(std::shared_ptr<Scheduler> scheduler);
24
21
  std::shared_ptr<Scheduler> getScheduler() override;
25
22
  std::shared_ptr<ErrorWrapper> getError() override;
@@ -1,6 +1,9 @@
1
- #include "AndroidLogger.h"
2
1
  #include <android/log.h>
2
+ #include <memory>
3
+
4
+ #include "AndroidLogger.h"
3
5
  #include "Logger.h"
6
+
4
7
  #define APPNAME "NATIVE_REANIMATED"
5
8
 
6
9
  namespace reanimated {
@@ -73,11 +73,10 @@ void NativeProxy::installJSIBindings() {
73
73
  };
74
74
 
75
75
  auto getCurrentTime = [this]() {
76
- auto method =
77
- javaPart_->getClass()->getMethod<local_ref<JString>()>("getUptime");
78
- local_ref<JString> output = method(javaPart_.get());
79
- return static_cast<double>(
80
- std::strtoll(output->toStdString().c_str(), NULL, 10));
76
+ static const auto method =
77
+ javaPart_->getClass()->getMethod<jlong()>("getCurrentTime");
78
+ jlong output = method(javaPart_.get());
79
+ return static_cast<double>(output);
81
80
  };
82
81
 
83
82
  auto requestRender = [this, getCurrentTime](
@@ -353,11 +352,10 @@ void NativeProxy::configureProps(
353
352
  ReadableNativeArray::javaobject)>("configureProps");
354
353
  method(
355
354
  javaPart_.get(),
356
- ReadableNativeArray::newObjectCxxArgs(
357
- std::move(jsi::dynamicFromValue(rt, uiProps)))
355
+ ReadableNativeArray::newObjectCxxArgs(jsi::dynamicFromValue(rt, uiProps))
358
356
  .get(),
359
357
  ReadableNativeArray::newObjectCxxArgs(
360
- std::move(jsi::dynamicFromValue(rt, nativeProps)))
358
+ jsi::dynamicFromValue(rt, nativeProps))
361
359
  .get());
362
360
  }
363
361
 
@@ -203,14 +203,13 @@ public class NativeProxy {
203
203
  }
204
204
 
205
205
  @DoNotStrip
206
- private String getUptime() {
206
+ private long getCurrentTime() {
207
207
  if (slowAnimationsEnabled) {
208
208
  final long ANIMATIONS_DRAG_FACTOR = 10;
209
- return Long.toString(
210
- this.firstUptime
211
- + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR);
209
+ return this.firstUptime
210
+ + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR;
212
211
  } else {
213
- return Long.toString(SystemClock.uptimeMillis());
212
+ return SystemClock.uptimeMillis();
214
213
  }
215
214
  }
216
215
 
@@ -57,7 +57,8 @@ public class ReanimatedKeyboardEventListener {
57
57
  rootView,
58
58
  (v, insets) -> {
59
59
  int paddingBottom = 0;
60
- if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED && BuildConfig.REACT_NATIVE_VERSION < 70) {
60
+ if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
61
+ && BuildConfig.REACT_NATIVE_MINOR_VERSION < 70) {
61
62
  paddingBottom = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
62
63
  }
63
64
  int paddingTop = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;
@@ -229,8 +229,8 @@ public class AnimationsManager implements ViewHierarchyObserver {
229
229
  }
230
230
 
231
231
  private void removeLeftovers() {
232
- //mToRemove may be null if onCatalystInstanceDestroy was called first
233
- if(mToRemove != null){
232
+ // mToRemove may be null if onCatalystInstanceDestroy was called first
233
+ if (mToRemove != null) {
234
234
  HashSet<Integer> roots = new HashSet<>();
235
235
  // go through ready to remove from bottom to top
236
236
  for (int tag : mToRemove) {
@@ -20,7 +20,7 @@ class ReaUiImplementationProvider extends UIImplementationProvider {
20
20
  ViewManagerRegistry viewManagerRegistry,
21
21
  EventDispatcher eventDispatcher,
22
22
  int minTimeLeftInFrameForNonBatchedOperationMs) {
23
- return new ReanimatedUIImplementation(
23
+ return new com.facebook.react.uimanager.ReanimatedUIImplementation(
24
24
  reactContext,
25
25
  viewManagerRegistry,
26
26
  eventDispatcher,
@@ -0,0 +1,12 @@
1
+ package com.swmansion.reanimated;
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip;
4
+ import com.swmansion.reanimated.ReanimatedMessageQueueThreadBase;
5
+
6
+ @DoNotStrip
7
+ public class ReanimatedMessageQueueThread extends ReanimatedMessageQueueThreadBase {
8
+ @Override
9
+ public void runOnQueue(Runnable runnable) {
10
+ messageQueueThread.runOnQueue(runnable);
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ package com.swmansion.reanimated;
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip;
4
+ import com.swmansion.reanimated.ReanimatedMessageQueueThreadBase;
5
+
6
+ @DoNotStrip
7
+ public class ReanimatedMessageQueueThread extends ReanimatedMessageQueueThreadBase {
8
+ @Override
9
+ public boolean runOnQueue(Runnable runnable) {
10
+ return messageQueueThread.runOnQueue(runnable);
11
+ }
12
+ }
@@ -2,16 +2,30 @@
2
2
  #import <RNReanimated/REAModule.h>
3
3
  #import <RNReanimated/REANodesManager.h>
4
4
  #import <RNReanimated/REATransitionManager.h>
5
+ #import <RNReanimated/SingleInstanceChecker.h>
6
+
7
+ using namespace reanimated;
5
8
 
6
9
  typedef void (^AnimatedOperation)(REANodesManager *nodesManager);
7
10
 
8
11
  @implementation REAModule {
9
12
  NSMutableArray<AnimatedOperation> *_operations;
10
13
  REATransitionManager *_transitionManager;
14
+ #ifdef DEBUG
15
+ SingleInstanceChecker<REAModule> singleInstanceChecker_;
16
+ #endif
17
+ bool hasListeners;
11
18
  }
12
19
 
13
20
  RCT_EXPORT_MODULE(ReanimatedModule);
14
21
 
22
+ #ifdef RCT_NEW_ARCH_ENABLED
23
+ + (BOOL)requiresMainQueueSetup
24
+ {
25
+ return YES;
26
+ }
27
+ #endif // RCT_NEW_ARCH_ENABLED
28
+
15
29
  - (void)invalidate
16
30
  {
17
31
  _transitionManager = nil;
@@ -181,4 +195,19 @@ RCT_EXPORT_METHOD(triggerRender)
181
195
  [_nodesManager dispatchEvent:event];
182
196
  }
183
197
 
198
+ - (void)startObserving {
199
+ hasListeners = YES;
200
+ }
201
+
202
+ - (void)stopObserving {
203
+ hasListeners = NO;
204
+ }
205
+
206
+ - (void)sendEventWithName:(NSString *)eventName body:(id)body
207
+ {
208
+ if (hasListeners) {
209
+ [super sendEventWithName:eventName body:body];
210
+ }
211
+ }
212
+
184
213
  @end
@@ -1,5 +1,5 @@
1
- #import "REAKeyboardEventObserver.h"
2
1
  #import <Foundation/Foundation.h>
2
+ #import <RNReanimated/REAKeyboardEventObserver.h>
3
3
  #import <React/RCTDefines.h>
4
4
  #import <React/RCTUIManager.h>
5
5
 
@@ -201,8 +201,10 @@ std::shared_ptr<NativeReanimatedModule> createReanimatedModule(
201
201
  }
202
202
  };
203
203
 
204
- auto requestRender = [reanimatedModule, &module](std::function<void(double)> onRender, jsi::Runtime &rt) {
205
- [reanimatedModule.nodesManager postOnAnimation:^(CADisplayLink *displayLink) {
204
+ auto nodesManager = reanimatedModule.nodesManager;
205
+
206
+ auto requestRender = [nodesManager, &module](std::function<void(double)> onRender, jsi::Runtime &rt) {
207
+ [nodesManager postOnAnimation:^(CADisplayLink *displayLink) {
206
208
  double frameTimestamp = calculateTimestampWithSlowAnimations(displayLink.targetTimestamp) * 1000;
207
209
  jsi::Object global = rt.global();
208
210
  jsi::String frameTimestampName = jsi::String::createFromAscii(rt, "_frameTimestamp");
@@ -7,11 +7,11 @@
7
7
  #import <ReactCommon/RCTTurboModuleManager.h>
8
8
  #import <jsireact/JSIExecutor.h>
9
9
 
10
- #if RNVERSION >= 64
10
+ #if REACT_NATIVE_MINOR_VERSION >= 64
11
11
  #import <React/RCTJSIExecutorRuntimeInstaller.h>
12
12
  #endif
13
13
 
14
- #if RNVERSION < 63
14
+ #if REACT_NATIVE_MINOR_VERSION < 63
15
15
  #import <ReactCommon/BridgeJSCallInvoker.h>
16
16
  #endif
17
17
 
@@ -24,7 +24,7 @@ JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
24
24
 
25
25
  [bridge moduleForClass:[RCTEventDispatcher class]];
26
26
  RCTEventDispatcher *eventDispatcher = [REAEventDispatcher new];
27
- #if RNVERSION >= 66
27
+ #if REACT_NATIVE_MINOR_VERSION >= 66
28
28
  RCTCallableJSModules *callableJSModules = [RCTCallableJSModules new];
29
29
  [bridge setValue:callableJSModules forKey:@"_callableJSModules"];
30
30
  [callableJSModules setBridge:bridge];
@@ -39,7 +39,7 @@ JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
39
39
  if (!bridge) {
40
40
  return;
41
41
  }
42
- #if RNVERSION >= 63
42
+ #if REACT_NATIVE_MINOR_VERSION >= 63
43
43
  auto reanimatedModule = reanimated::createReanimatedModule(bridge, bridge.jsCallInvoker);
44
44
  #else
45
45
  auto callInvoker = std::make_shared<react::BridgeJSCallInvoker>(bridge.reactInstance);
@@ -20,7 +20,7 @@ typedef JSCExecutorFactory ExecutorFactory;
20
20
  {
21
21
  const auto installer = reanimated::REAJSIExecutorRuntimeInstaller(bridge, NULL);
22
22
 
23
- #if RNVERSION >= 64
23
+ #if REACT_NATIVE_MINOR_VERSION >= 64
24
24
  // installs globals such as console, nativePerformanceNow, etc.
25
25
  return std::make_unique<ExecutorFactory>(RCTJSIExecutorRuntimeInstaller(installer));
26
26
  #else
@@ -119,11 +119,10 @@ export default function createAnimatedComponent(Component, options) {
119
119
  setLocalRef: (ref) => {
120
120
  // TODO update config
121
121
  const tag = findNodeHandle(ref);
122
- if ((this.props.layout || this.props.entering || this.props.exiting) &&
122
+ if (!shouldBeUseWeb() &&
123
+ (this.props.layout || this.props.entering || this.props.exiting) &&
123
124
  tag != null) {
124
- if (!shouldBeUseWeb()) {
125
- enableLayoutAnimations(true, false);
126
- }
125
+ enableLayoutAnimations(true, false);
127
126
  let layout = this.props.layout ? this.props.layout : DefaultLayout;
128
127
  let entering = this.props.entering
129
128
  ? this.props.entering
package/lib/index.web.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // tree-shaken side effects
2
2
  import './reanimated2/js-reanimated/global';
3
+ // @ts-ignore backward compatibility with treeshaking
4
+ export * from './reanimated1';
3
5
  export * from './reanimated2';
4
6
  export * as default from './Animated'; // If this line fails, you probably forgot some installation steps. Check out the installation guide here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/ 1) Make sure reanimated's babel plugin is installed in your babel.config.js (you should have 'react-native-reanimated/plugin' listed there - also see the above link for details) 2) Make sure you reset build cache after updating the config, run: yarn start --reset-cache
@@ -1,43 +1,92 @@
1
1
  import { findNodeHandle } from 'react-native';
2
- import { shouldBeUseWeb } from './PlatformChecker';
2
+ import { isChromeDebugger, isWeb, shouldBeUseWeb } from './PlatformChecker';
3
3
  export function getTag(view) {
4
4
  return findNodeHandle(view);
5
5
  }
6
- const isNativeIndefined = shouldBeUseWeb();
7
- export function measure(animatedRef) {
8
- 'worklet';
9
- if (!_WORKLET || isNativeIndefined) {
10
- console.warn('[reanimated.measure] method cannot be used for web or Chrome Debugger');
6
+ const isNative = !shouldBeUseWeb();
7
+ export let measure;
8
+ if (isWeb()) {
9
+ measure = (animatedRef) => {
10
+ const element = animatedRef(); // TODO: fix typing of animated refs on web
11
+ const viewportOffset = element.getBoundingClientRect();
11
12
  return {
12
- x: NaN,
13
- y: NaN,
14
- width: NaN,
15
- height: NaN,
16
- pageX: NaN,
17
- pageY: NaN,
13
+ width: element.offsetWidth,
14
+ height: element.offsetHeight,
15
+ x: element.offsetLeft,
16
+ y: element.offsetTop,
17
+ pageX: viewportOffset.left,
18
+ pageY: viewportOffset.top,
18
19
  };
19
- }
20
- const viewTag = animatedRef();
21
- const result = _measure(viewTag);
22
- if (result.x === -1234567) {
23
- throw new Error(`The view with tag ${viewTag} could not be measured`);
24
- }
25
- if (isNaN(result.x)) {
26
- console.warn('Trying to measure a component which gets view-flattened on Android. To disable view-flattening, set `collapsable={false}` on this component.');
27
- }
28
- return result;
20
+ };
29
21
  }
30
- export function scrollTo(animatedRef, x, y, animated) {
31
- 'worklet';
32
- if (!_WORKLET || isNativeIndefined) {
33
- return;
34
- }
35
- const viewTag = animatedRef();
36
- _scrollTo(viewTag, x, y, animated);
22
+ else if (isChromeDebugger()) {
23
+ measure = (_animatedRef) => {
24
+ console.warn('[Reanimated] measure() cannot be used with Chrome Debugger.');
25
+ return null;
26
+ };
27
+ }
28
+ else {
29
+ measure = (animatedRef) => {
30
+ 'worklet';
31
+ if (!_WORKLET) {
32
+ console.warn('[Reanimated] measure() was called from the main JS context. Measure is ' +
33
+ 'only available in the UI runtime. This may also happen if measure() ' +
34
+ 'was called by a worklet in the useAnimatedStyle hook, because useAnimatedStyle ' +
35
+ 'calls the given worklet on the JS runtime during render. If you want to ' +
36
+ 'prevent this warning then wrap the call with `if (_WORKLET)`. Then it will ' +
37
+ 'only be called on the UI runtime after the render has been completed.');
38
+ return null;
39
+ }
40
+ const viewTag = animatedRef();
41
+ if (viewTag === -1) {
42
+ console.warn(`[Reanimated] The view with tag ${viewTag} is not a valid argument for measure(). This may be because the view is not currently rendered, which may not be a bug (e.g. an off-screen FlatList item).`);
43
+ return null;
44
+ }
45
+ const measured = _measure(viewTag);
46
+ if (measured === null) {
47
+ console.warn(`[Reanimated] The view with tag ${viewTag} has some undefined, not-yet-computed or meaningless value of \`LayoutMetrics\` type. This may be because the view is not currently rendered, which may not be a bug (e.g. an off-screen FlatList item).`);
48
+ return null;
49
+ }
50
+ else if (measured.x === -1234567) {
51
+ console.warn(`[Reanimated] The view with tag ${viewTag} returned an invalid measurement response.`);
52
+ return null;
53
+ }
54
+ else if (isNaN(measured.x)) {
55
+ console.warn(`[Reanimated] The view with tag ${viewTag} gets view-flattened on Android. To disable view-flattening, set \`collapsable={false}\` on this component.`);
56
+ return null;
57
+ }
58
+ else {
59
+ return measured;
60
+ }
61
+ };
62
+ }
63
+ export let scrollTo;
64
+ if (isWeb()) {
65
+ scrollTo = (animatedRef, x, y, animated) => {
66
+ 'worklet';
67
+ const element = animatedRef();
68
+ // @ts-ignore same call as in react-native-web
69
+ element.scrollTo({ x, y, animated });
70
+ };
71
+ }
72
+ else if (isNative) {
73
+ scrollTo = (animatedRef, x, y, animated) => {
74
+ 'worklet';
75
+ if (!_WORKLET) {
76
+ return;
77
+ }
78
+ const viewTag = animatedRef();
79
+ _scrollTo(viewTag, x, y, animated);
80
+ };
81
+ }
82
+ else {
83
+ scrollTo = (_animatedRef, _x, _y) => {
84
+ // no-op
85
+ };
37
86
  }
38
87
  export function setGestureState(handlerTag, newState) {
39
88
  'worklet';
40
- if (!_WORKLET || isNativeIndefined) {
89
+ if (!_WORKLET || !isNative) {
41
90
  console.warn('[Reanimated] You can not use setGestureState in non-worklet function.');
42
91
  return;
43
92
  }
@@ -17,16 +17,16 @@ export default class FrameCallbackRegistryJS {
17
17
  })();
18
18
  return callbackId;
19
19
  }
20
- unregisterFrameCallback(frameCallbackId) {
20
+ unregisterFrameCallback(callbackId) {
21
21
  runOnUI(() => {
22
22
  'worklet';
23
- global._frameCallbackRegistry.unregisterFrameCallback(frameCallbackId);
23
+ global._frameCallbackRegistry.unregisterFrameCallback(callbackId);
24
24
  })();
25
25
  }
26
- manageStateFrameCallback(frameCallbackId, state) {
26
+ manageStateFrameCallback(callbackId, state) {
27
27
  runOnUI(() => {
28
28
  'worklet';
29
- global._frameCallbackRegistry.manageStateFrameCallback(frameCallbackId, state);
29
+ global._frameCallbackRegistry.manageStateFrameCallback(callbackId, state);
30
30
  })();
31
31
  }
32
32
  }
@@ -3,43 +3,72 @@ export const prepareUIRegistry = runOnUI(() => {
3
3
  'worklet';
4
4
  const frameCallbackRegistry = {
5
5
  frameCallbackRegistry: new Map(),
6
- frameCallbackActive: new Set(),
7
- isFrameCallbackRunning: false,
6
+ activeFrameCallbacks: new Set(),
7
+ previousFrameTimestamp: null,
8
8
  runCallbacks() {
9
- const loop = () => {
10
- this.frameCallbackActive.forEach((key) => {
11
- const callback = this.frameCallbackRegistry.get(key);
12
- callback();
9
+ const loop = (timestamp) => {
10
+ if (this.previousFrameTimestamp === null) {
11
+ this.previousFrameTimestamp = timestamp;
12
+ }
13
+ const delta = timestamp - this.previousFrameTimestamp;
14
+ this.activeFrameCallbacks.forEach((callbackId) => {
15
+ const callbackDetails = this.frameCallbackRegistry.get(callbackId);
16
+ const { startTime } = callbackDetails;
17
+ if (startTime === null) {
18
+ // First frame
19
+ callbackDetails.startTime = timestamp;
20
+ callbackDetails.callback({
21
+ timestamp,
22
+ timeSincePreviousFrame: null,
23
+ timeSinceFirstFrame: 0,
24
+ });
25
+ }
26
+ else {
27
+ // Next frame
28
+ callbackDetails.callback({
29
+ timestamp,
30
+ timeSincePreviousFrame: delta,
31
+ timeSinceFirstFrame: timestamp - startTime,
32
+ });
33
+ }
13
34
  });
14
- if (this.frameCallbackActive.size > 0) {
35
+ if (this.activeFrameCallbacks.size > 0) {
36
+ this.previousFrameTimestamp = timestamp;
15
37
  requestAnimationFrame(loop);
16
38
  }
17
39
  else {
18
- this.isFrameCallbackRunning = false;
40
+ this.previousFrameTimestamp = null;
19
41
  }
20
42
  };
21
- if (!this.isFrameCallbackRunning) {
43
+ // runCallback() should only be called after registering a callback,
44
+ // so if there is only one active callback, then it means that there were
45
+ // zero previously and the loop isn't running yet.
46
+ if (this.activeFrameCallbacks.size === 1) {
22
47
  requestAnimationFrame(loop);
23
- this.isFrameCallbackRunning = true;
24
48
  }
25
49
  },
26
50
  registerFrameCallback(callback, callbackId) {
27
- this.frameCallbackRegistry.set(callbackId, callback);
51
+ this.frameCallbackRegistry.set(callbackId, {
52
+ callback: callback,
53
+ startTime: null,
54
+ });
28
55
  },
29
- unregisterFrameCallback(frameCallbackId) {
30
- this.manageStateFrameCallback(frameCallbackId, false);
31
- this.frameCallbackRegistry.delete(frameCallbackId);
56
+ unregisterFrameCallback(callbackId) {
57
+ this.manageStateFrameCallback(callbackId, false);
58
+ this.frameCallbackRegistry.delete(callbackId);
32
59
  },
33
- manageStateFrameCallback(frameCallbackId, state) {
34
- if (frameCallbackId === -1) {
60
+ manageStateFrameCallback(callbackId, state) {
61
+ if (callbackId === -1) {
35
62
  return;
36
63
  }
37
64
  if (state) {
38
- this.frameCallbackActive.add(frameCallbackId);
65
+ this.activeFrameCallbacks.add(callbackId);
39
66
  this.runCallbacks();
40
67
  }
41
68
  else {
42
- this.frameCallbackActive.delete(frameCallbackId);
69
+ const callback = this.frameCallbackRegistry.get(callbackId);
70
+ callback.startTime = null;
71
+ this.activeFrameCallbacks.delete(callbackId);
43
72
  }
44
73
  },
45
74
  };