react-native-reanimated 3.0.0-rc.2 → 3.0.0-rc.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 (154) 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/Fabric/FabricUtils.cpp +1 -1
  4. package/Common/cpp/{headers/Fabric → Fabric}/FabricUtils.h +0 -0
  5. package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +2 -0
  6. package/Common/cpp/{headers/Fabric → Fabric}/ReanimatedUIManagerBinding.h +0 -0
  7. package/Common/cpp/{headers/Fabric → Fabric}/ShadowTreeCloner.h +1 -1
  8. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
  9. package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +6 -1
  11. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModule.h +5 -0
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +2 -0
  13. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModuleSpec.h +1 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +93 -0
  15. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +125 -0
  16. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +50 -0
  17. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.h +27 -0
  18. package/Common/cpp/ReanimatedRuntime/RuntimeInitialization.md +194 -0
  19. package/Common/cpp/{headers/Registries → Registries}/EventHandlerRegistry.h +0 -0
  20. package/Common/cpp/Registries/MapperRegistry.cpp +3 -1
  21. package/Common/cpp/{headers/Registries → Registries}/MapperRegistry.h +0 -0
  22. package/Common/cpp/{headers/Registries → Registries}/NewestShadowNodesRegistry.h +0 -0
  23. package/Common/cpp/Registries/WorkletsCache.cpp +8 -1
  24. package/Common/cpp/{headers/Registries → Registries}/WorkletsCache.h +0 -0
  25. package/Common/cpp/{headers/SharedItems → SharedItems}/FrozenObject.h +0 -0
  26. package/Common/cpp/{headers/SharedItems → SharedItems}/HostFunctionHandler.h +0 -0
  27. package/Common/cpp/SharedItems/MutableValue.cpp +2 -0
  28. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValue.h +0 -0
  29. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValueSetterProxy.h +0 -0
  30. package/Common/cpp/{headers/SharedItems → SharedItems}/RemoteObject.h +0 -0
  31. package/Common/cpp/{headers/SharedItems → SharedItems}/RuntimeManager.h +0 -0
  32. package/Common/cpp/SharedItems/ShareableValue.cpp +6 -2
  33. package/Common/cpp/{headers/SharedItems → SharedItems}/ShareableValue.h +0 -0
  34. package/Common/cpp/{headers/SharedItems → SharedItems}/SharedParent.h +0 -0
  35. package/Common/cpp/{headers/SharedItems → SharedItems}/ValueWrapper.h +0 -0
  36. package/Common/cpp/{headers/SpecTools → SpecTools}/ErrorHandler.h +0 -0
  37. package/Common/cpp/{headers/Tools → Tools}/FeaturesConfig.h +0 -0
  38. package/Common/cpp/Tools/JSIStoreValueUser.cpp +2 -2
  39. package/Common/cpp/{headers/Tools → Tools}/JSIStoreValueUser.h +0 -0
  40. package/Common/cpp/{headers/Tools → Tools}/Mapper.h +0 -0
  41. package/Common/cpp/{headers/Tools → Tools}/PlatformDepMethodsHolder.h +0 -0
  42. package/Common/cpp/{headers/Tools → Tools}/ReanimatedHiddenHeaders.h +1 -1
  43. package/Common/cpp/{headers/Tools → Tools}/RuntimeDecorator.h +0 -0
  44. package/Common/cpp/{headers/Tools → Tools}/Scheduler.h +0 -0
  45. package/Common/cpp/Tools/SingleInstanceChecker.h +58 -0
  46. package/Common/cpp/{headers/Tools → Tools}/WorkletEventHandler.h +0 -0
  47. package/RNReanimated.podspec +21 -85
  48. package/android/CMakeLists.txt +62 -58
  49. package/android/build.gradle +421 -114
  50. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  51. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +10 -8
  52. package/android/src/main/cpp/AndroidErrorHandler.cpp +3 -4
  53. package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +1 -4
  54. package/android/src/main/cpp/AndroidLogger.cpp +4 -1
  55. package/android/src/main/cpp/{headers/AndroidLogger.h → AndroidLogger.h} +0 -0
  56. package/android/src/main/cpp/{headers/AndroidScheduler.h → AndroidScheduler.h} +0 -0
  57. package/android/src/main/cpp/{headers/JNIHelper.h → JNIHelper.h} +0 -0
  58. package/android/src/main/cpp/{headers/LayoutAnimations.h → LayoutAnimations.h} +0 -0
  59. package/android/src/main/cpp/NativeProxy.cpp +12 -28
  60. package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +3 -1
  61. package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
  62. package/android/src/main/java/com/swmansion/reanimated/ReanimatedMessageQueueThreadBase.java +72 -0
  63. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
  64. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +1 -1
  65. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +7 -7
  66. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/UIImplementation/64/com/swmansion/reanimated}/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  67. package/android/src/{main/java → reactNativeVersionPatch/UIImplementation/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  68. package/android/src/reactNativeVersionPatch/messageQueueThread/67/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  69. package/android/src/reactNativeVersionPatch/messageQueueThread/latest/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  70. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated}/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  71. package/android/src/{main/java → reactNativeVersionPatch/nativeHierarchyManager/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  72. package/ios/REAModule.mm +29 -0
  73. package/ios/keyboardObserver/REAKeyboardEventObserver.m +1 -1
  74. package/ios/native/NativeProxy.mm +12 -19
  75. package/ios/native/REAInitializer.h +2 -2
  76. package/ios/native/REAInitializer.mm +2 -2
  77. package/ios/native/REAMessageThread.h +22 -0
  78. package/ios/native/REAMessageThread.mm +38 -0
  79. package/ios/native/UIResponder+Reanimated.mm +1 -1
  80. package/lib/commonjs/createAnimatedComponent.js +2 -5
  81. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  82. package/lib/commonjs/reanimated2/NativeMethods.js +67 -31
  83. package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
  84. package/lib/commonjs/reanimated2/animation/delay.js +0 -12
  85. package/lib/commonjs/reanimated2/animation/delay.js.map +1 -1
  86. package/lib/commonjs/reanimated2/animation/repeat.js +0 -24
  87. package/lib/commonjs/reanimated2/animation/repeat.js.map +1 -1
  88. package/lib/commonjs/reanimated2/animation/sequence.js +0 -12
  89. package/lib/commonjs/reanimated2/animation/sequence.js.map +1 -1
  90. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  91. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  92. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  93. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +51 -19
  94. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  95. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  96. package/lib/commonjs/reanimated2/hook/index.js +8 -0
  97. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  98. package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  99. package/lib/commonjs/reanimated2/hook/useFrameCallback.js.map +1 -1
  100. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +33 -0
  101. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -0
  102. package/lib/commonjs/reanimated2/utils.js +12 -3
  103. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  104. package/lib/module/createAnimatedComponent.js +2 -5
  105. package/lib/module/createAnimatedComponent.js.map +1 -1
  106. package/lib/module/reanimated2/NativeMethods.js +68 -30
  107. package/lib/module/reanimated2/NativeMethods.js.map +1 -1
  108. package/lib/module/reanimated2/animation/delay.js +0 -10
  109. package/lib/module/reanimated2/animation/delay.js.map +1 -1
  110. package/lib/module/reanimated2/animation/repeat.js +0 -20
  111. package/lib/module/reanimated2/animation/repeat.js.map +1 -1
  112. package/lib/module/reanimated2/animation/sequence.js +0 -10
  113. package/lib/module/reanimated2/animation/sequence.js.map +1 -1
  114. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  115. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  116. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  117. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +51 -19
  118. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  119. package/lib/module/reanimated2/globals.d.js.map +1 -1
  120. package/lib/module/reanimated2/hook/index.js +1 -0
  121. package/lib/module/reanimated2/hook/index.js.map +1 -1
  122. package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  123. package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
  124. package/lib/module/reanimated2/hook/useScrollViewOffset.js +21 -0
  125. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -0
  126. package/lib/module/reanimated2/utils.js +13 -3
  127. package/lib/module/reanimated2/utils.js.map +1 -1
  128. package/package.json +10 -6
  129. package/plugin.js +105 -47
  130. package/react-native-reanimated.d.ts +13 -9
  131. package/scripts/reanimated_utils.rb +77 -0
  132. package/src/createAnimatedComponent.tsx +2 -3
  133. package/src/reanimated2/NativeMethods.ts +91 -44
  134. package/src/reanimated2/animation/delay.ts +0 -12
  135. package/src/reanimated2/animation/repeat.ts +0 -25
  136. package/src/reanimated2/animation/sequence.ts +0 -13
  137. package/src/reanimated2/commonTypes.ts +9 -0
  138. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
  139. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
  140. package/src/reanimated2/globals.d.ts +56 -14
  141. package/src/reanimated2/hook/index.ts +1 -0
  142. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
  143. package/src/reanimated2/hook/useFrameCallback.ts +2 -1
  144. package/src/reanimated2/hook/useScrollViewOffset.ts +37 -0
  145. package/src/reanimated2/utils.ts +12 -5
  146. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  147. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  148. package/android/rnVersionPatch/65/.gitkeep +0 -0
  149. package/android/rnVersionPatch/66/.gitkeep +0 -0
  150. package/android/rnVersionPatch/67/.gitkeep +0 -0
  151. package/android/rnVersionPatch/68/.gitkeep +0 -0
  152. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  153. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
  154. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +0 -29
@@ -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
@@ -7,6 +7,7 @@ import com.facebook.jni.HybridData;
7
7
  import com.facebook.proguard.annotations.DoNotStrip;
8
8
  import com.facebook.react.ReactApplication;
9
9
  import com.facebook.react.bridge.NativeModule;
10
+ import com.facebook.react.bridge.queue.MessageQueueThread;
10
11
  import com.facebook.react.bridge.ReactApplicationContext;
11
12
  import com.facebook.react.bridge.ReadableMap;
12
13
  import com.facebook.react.bridge.ReadableNativeArray;
@@ -159,7 +160,9 @@ public class NativeProxy {
159
160
  LayoutAnimations LayoutAnimations,
160
161
  FabricUIManager fabricUIManager);
161
162
 
162
- private native void installJSIBindings(FabricUIManager fabricUIManager);
163
+ private native void installJSIBindings(
164
+ MessageQueueThread messageQueueThread,
165
+ FabricUIManager fabricUIManager);
163
166
 
164
167
  public native boolean isAnyHandlerWaitingForEvent(String eventName);
165
168
 
@@ -223,14 +226,12 @@ public class NativeProxy {
223
226
  }
224
227
 
225
228
  @DoNotStrip
226
- private String getUptime() {
229
+ private long getCurrentTime() {
227
230
  if (slowAnimationsEnabled) {
228
231
  final long ANIMATIONS_DRAG_FACTOR = 10;
229
- return Long.toString(
230
- this.firstUptime
231
- + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR);
232
+ return this.firstUptime + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR;
232
233
  } else {
233
- return Long.toString(SystemClock.uptimeMillis());
234
+ return SystemClock.uptimeMillis();
234
235
  }
235
236
  }
236
237
 
@@ -294,8 +295,9 @@ public class NativeProxy {
294
295
  }
295
296
  mNodesManager = mContext.get().getNativeModule(ReanimatedModule.class).getNodesManager();
296
297
  FabricUIManager fabricUIManager =
297
- (FabricUIManager) UIManagerHelper.getUIManager(mContext.get(), UIManagerType.FABRIC);
298
- installJSIBindings(fabricUIManager);
298
+ (FabricUIManager) UIManagerHelper.getUIManager(mContext.get(), UIManagerType.FABRIC);
299
+ ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread();
300
+ installJSIBindings(messageQueueThread, fabricUIManager);
299
301
  AnimationsManager animationsManager =
300
302
  mContext
301
303
  .get()
@@ -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 {
@@ -1,26 +1,20 @@
1
+ #include <android/log.h>
1
2
  #include <fbjni/fbjni.h>
2
3
  #include <jsi/JSIDynamic.h>
3
4
  #include <jsi/jsi.h>
5
+ #include <react/jni/JMessageQueueThread.h>
4
6
  #include <react/jni/ReadableNativeArray.h>
5
7
  #include <react/jni/ReadableNativeMap.h>
6
8
 
7
9
  #include <memory>
8
10
  #include <string>
9
11
 
10
- #if JS_RUNTIME_HERMES
11
- #include <hermes/hermes.h>
12
- #elif JS_RUNTIME_V8
13
- #include <v8runtime/V8RuntimeFactory.h>
14
- #else
15
- #include <jsi/JSCRuntime.h>
16
- #endif
17
-
18
- #include <android/log.h>
19
12
  #include "AndroidErrorHandler.h"
20
13
  #include "AndroidScheduler.h"
21
14
  #include "LayoutAnimationsProxy.h"
22
15
  #include "NativeProxy.h"
23
16
  #include "PlatformDepMethodsHolder.h"
17
+ #include "ReanimatedRuntime.h"
24
18
 
25
19
  #ifdef RCT_NEW_ARCH_ENABLED
26
20
  #include <JFabricUIManager.h>
@@ -101,7 +95,9 @@ jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybrid(
101
95
  }
102
96
 
103
97
  void NativeProxy::installJSIBindings(
98
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread
104
99
  #ifdef RCT_NEW_ARCH_ENABLED
100
+ ,
105
101
  jni::alias_ref<facebook::react::JFabricUIManager::javaobject>
106
102
  fabricUIManager
107
103
  #endif
@@ -130,11 +126,10 @@ void NativeProxy::installJSIBindings(
130
126
  #endif
131
127
 
132
128
  auto getCurrentTime = [this]() {
133
- auto method =
134
- javaPart_->getClass()->getMethod<local_ref<JString>()>("getUptime");
135
- local_ref<JString> output = method(javaPart_.get());
136
- return static_cast<double>(
137
- std::strtoll(output->toStdString().c_str(), NULL, 10));
129
+ static const auto method =
130
+ javaPart_->getClass()->getMethod<jlong()>("getCurrentTime");
131
+ jlong output = method(javaPart_.get());
132
+ return static_cast<double>(output);
138
133
  };
139
134
 
140
135
  auto requestRender = [this, getCurrentTime](
@@ -206,21 +201,10 @@ void NativeProxy::installJSIBindings(
206
201
  unsubscribeFromKeyboardEvents(listenerId);
207
202
  };
208
203
 
209
- #if JS_RUNTIME_HERMES
210
- auto config =
211
- ::hermes::vm::RuntimeConfig::Builder().withEnableSampleProfiling(false);
212
- std::shared_ptr<jsi::Runtime> animatedRuntime =
213
- facebook::hermes::makeHermesRuntime(config.build());
214
- #elif JS_RUNTIME_V8
215
- auto config = std::make_unique<rnv8::V8RuntimeConfig>();
216
- config->enableInspector = false;
217
- config->appName = "reanimated";
218
- std::shared_ptr<jsi::Runtime> animatedRuntime =
219
- rnv8::createSharedV8Runtime(runtime_, std::move(config));
220
- #else
204
+ auto jsQueue = std::make_shared<JMessageQueueThread>(messageQueueThread);
221
205
  std::shared_ptr<jsi::Runtime> animatedRuntime =
222
- facebook::jsc::makeJSCRuntime();
223
- #endif
206
+ ReanimatedRuntime::make(jsQueue);
207
+
224
208
  auto workletRuntimeValue =
225
209
  runtime_->global()
226
210
  .getProperty(*runtime_, "ArrayBuffer")
@@ -186,13 +186,15 @@ class NativeProxy : public jni::HybridClass<NativeProxy> {
186
186
  #endif
187
187
  #ifdef RCT_NEW_ARCH_ENABLED
188
188
  void installJSIBindings(
189
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
189
190
  jni::alias_ref<JFabricUIManager::javaobject> fabricUIManager);
190
191
  void synchronouslyUpdateUIProps(
191
192
  jsi::Runtime &rt,
192
193
  Tag viewTag,
193
194
  const jsi::Value &uiProps);
194
195
  #else
195
- void installJSIBindings();
196
+ void installJSIBindings(
197
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread);
196
198
  #endif
197
199
  bool isAnyHandlerWaitingForEvent(std::string);
198
200
  void performOperations();
@@ -0,0 +1,72 @@
1
+ package com.swmansion.reanimated;
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip;
4
+ import com.facebook.react.bridge.queue.MessageQueueThread;
5
+ import com.facebook.react.bridge.queue.MessageQueueThreadImpl;
6
+ import com.facebook.react.bridge.queue.MessageQueueThreadPerfStats;
7
+ import com.facebook.react.bridge.queue.MessageQueueThreadSpec;
8
+ import java.lang.reflect.Field;
9
+ import java.util.concurrent.Callable;
10
+ import java.util.concurrent.Future;
11
+
12
+ // This class is an almost exact copy of MessageQueueThreadImpl taken from here:
13
+ // https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.java
14
+ // The only method that has changed is `quitSynchronous()` (see comment above
15
+ // function implementation for details).
16
+ @DoNotStrip
17
+ public abstract class ReanimatedMessageQueueThreadBase implements MessageQueueThread {
18
+ protected final MessageQueueThreadImpl messageQueueThread;
19
+
20
+ public ReanimatedMessageQueueThreadBase() {
21
+ messageQueueThread =
22
+ MessageQueueThreadImpl.create(
23
+ MessageQueueThreadSpec.mainThreadSpec(),
24
+ exception -> {
25
+ throw new RuntimeException(exception);
26
+ });
27
+ }
28
+
29
+ @Override
30
+ public <T> Future<T> callOnQueue(Callable<T> callable) {
31
+ return messageQueueThread.callOnQueue(callable);
32
+ }
33
+
34
+ @Override
35
+ public boolean isOnThread() {
36
+ return messageQueueThread.isOnThread();
37
+ }
38
+
39
+ @Override
40
+ public void assertIsOnThread() {
41
+ messageQueueThread.assertIsOnThread();
42
+ }
43
+
44
+ @Override
45
+ public void assertIsOnThread(String s) {
46
+ messageQueueThread.assertIsOnThread(s);
47
+ }
48
+
49
+ // We don't want to quit the main looper (which is what MessageQueueThreadImpl would have done),
50
+ // but we still want to prevent anything else from executing.
51
+ @Override
52
+ public void quitSynchronous() {
53
+ try {
54
+ Field mIsFinished = messageQueueThread.getClass().getDeclaredField("mIsFinished");
55
+ mIsFinished.setAccessible(true);
56
+ mIsFinished.set(messageQueueThread, true);
57
+ mIsFinished.setAccessible(false);
58
+ } catch (NoSuchFieldException | IllegalAccessException e) {
59
+ e.printStackTrace();
60
+ }
61
+ }
62
+
63
+ @Override
64
+ public MessageQueueThreadPerfStats getPerfStats() {
65
+ return messageQueueThread.getPerfStats();
66
+ }
67
+
68
+ @Override
69
+ public void resetPerfStats() {
70
+ messageQueueThread.resetPerfStats();
71
+ }
72
+ }
@@ -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;
@@ -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,
@@ -7,6 +7,7 @@ import com.facebook.jni.HybridData;
7
7
  import com.facebook.proguard.annotations.DoNotStrip;
8
8
  import com.facebook.react.ReactApplication;
9
9
  import com.facebook.react.bridge.NativeModule;
10
+ import com.facebook.react.bridge.queue.MessageQueueThread;
10
11
  import com.facebook.react.bridge.ReactApplicationContext;
11
12
  import com.facebook.react.bridge.ReadableMap;
12
13
  import com.facebook.react.bridge.ReadableNativeArray;
@@ -152,7 +153,7 @@ public class NativeProxy {
152
153
  Scheduler scheduler,
153
154
  LayoutAnimations LayoutAnimations);
154
155
 
155
- private native void installJSIBindings();
156
+ private native void installJSIBindings(MessageQueueThread messageQueueThread);
156
157
 
157
158
  public native boolean isAnyHandlerWaitingForEvent(String eventName);
158
159
 
@@ -216,14 +217,12 @@ public class NativeProxy {
216
217
  }
217
218
 
218
219
  @DoNotStrip
219
- private String getUptime() {
220
+ private long getCurrentTime() {
220
221
  if (slowAnimationsEnabled) {
221
222
  final long ANIMATIONS_DRAG_FACTOR = 10;
222
- return Long.toString(
223
- this.firstUptime
224
- + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR);
223
+ return this.firstUptime + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR;
225
224
  } else {
226
- return Long.toString(SystemClock.uptimeMillis());
225
+ return SystemClock.uptimeMillis();
227
226
  }
228
227
  }
229
228
 
@@ -286,7 +285,8 @@ public class NativeProxy {
286
285
  return;
287
286
  }
288
287
  mNodesManager = mContext.get().getNativeModule(ReanimatedModule.class).getNodesManager();
289
- installJSIBindings();
288
+ ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread();
289
+ installJSIBindings(messageQueueThread);
290
290
  AnimationsManager animationsManager =
291
291
  mContext
292
292
  .get()
@@ -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
+ }
package/ios/REAModule.mm CHANGED
@@ -19,6 +19,7 @@
19
19
 
20
20
  #import <RNReanimated/REAModule.h>
21
21
  #import <RNReanimated/REANodesManager.h>
22
+ #import <RNReanimated/SingleInstanceChecker.h>
22
23
 
23
24
  using namespace facebook::react;
24
25
  using namespace reanimated;
@@ -47,10 +48,21 @@ typedef void (^AnimatedOperation)(REANodesManager *nodesManager);
47
48
  #else
48
49
  NSMutableArray<AnimatedOperation> *_operations;
49
50
  #endif
51
+ #ifdef DEBUG
52
+ SingleInstanceChecker<REAModule> singleInstanceChecker_;
53
+ #endif
54
+ bool hasListeners;
50
55
  }
51
56
 
52
57
  RCT_EXPORT_MODULE(ReanimatedModule);
53
58
 
59
+ #ifdef RCT_NEW_ARCH_ENABLED
60
+ + (BOOL)requiresMainQueueSetup
61
+ {
62
+ return YES;
63
+ }
64
+ #endif // RCT_NEW_ARCH_ENABLED
65
+
54
66
  - (void)invalidate
55
67
  {
56
68
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -281,4 +293,21 @@ RCT_EXPORT_METHOD(installTurboModule)
281
293
  [_nodesManager dispatchEvent:event];
282
294
  }
283
295
 
296
+ - (void)startObserving
297
+ {
298
+ hasListeners = YES;
299
+ }
300
+
301
+ - (void)stopObserving
302
+ {
303
+ hasListeners = NO;
304
+ }
305
+
306
+ - (void)sendEventWithName:(NSString *)eventName body:(id)body
307
+ {
308
+ if (hasListeners) {
309
+ [super sendEventWithName:eventName body:body];
310
+ }
311
+ }
312
+
284
313
  @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
 
@@ -6,10 +6,12 @@
6
6
  #import <RNReanimated/REAIOSScheduler.h>
7
7
  #import <RNReanimated/REAJSIUtils.h>
8
8
  #import <RNReanimated/REAKeyboardEventObserver.h>
9
+ #import <RNReanimated/REAMessageThread.h>
9
10
  #import <RNReanimated/REAModule.h>
10
11
  #import <RNReanimated/REANodesManager.h>
11
12
  #import <RNReanimated/REAUIManager.h>
12
13
  #import <RNReanimated/RNGestureHandlerStateManager.h>
14
+ #import <RNReanimated/ReanimatedRuntime.h>
13
15
  #import <RNReanimated/ReanimatedSensorContainer.h>
14
16
 
15
17
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -30,14 +32,6 @@
30
32
  #import <dlfcn.h>
31
33
  #endif
32
34
 
33
- #if __has_include(<reacthermes/HermesExecutorFactory.h>)
34
- #import <reacthermes/HermesExecutorFactory.h>
35
- #elif __has_include(<hermes/hermes.h>)
36
- #import <hermes/hermes.h>
37
- #else
38
- #import <jsi/JSCRuntime.h>
39
- #endif
40
-
41
35
  namespace reanimated {
42
36
 
43
37
  using namespace facebook;
@@ -201,20 +195,19 @@ std::shared_ptr<NativeReanimatedModule> createReanimatedModule(
201
195
  };
202
196
  #endif
203
197
 
204
- #if __has_include(<reacthermes/HermesExecutorFactory.h>)
205
- std::shared_ptr<jsi::Runtime> animatedRuntime = facebook::hermes::makeHermesRuntime();
206
- #elif __has_include(<hermes/hermes.h>)
207
- std::shared_ptr<jsi::Runtime> animatedRuntime = facebook::hermes::makeHermesRuntime();
208
- #else
209
- std::shared_ptr<jsi::Runtime> animatedRuntime = facebook::jsc::makeJSCRuntime();
210
- #endif
198
+ auto jsQueue = std::make_shared<REAMessageThread>([NSRunLoop currentRunLoop], ^(NSError *error) {
199
+ throw error;
200
+ });
201
+ std::shared_ptr<jsi::Runtime> animatedRuntime = ReanimatedRuntime::make(jsQueue);
211
202
 
212
203
  std::shared_ptr<Scheduler> scheduler = std::make_shared<REAIOSScheduler>(jsInvoker);
213
204
  std::shared_ptr<ErrorHandler> errorHandler = std::make_shared<REAIOSErrorHandler>(scheduler);
214
205
  std::shared_ptr<NativeReanimatedModule> module;
215
206
 
216
- auto requestRender = [reanimatedModule, &module](std::function<void(double)> onRender, jsi::Runtime &rt) {
217
- [reanimatedModule.nodesManager postOnAnimation:^(CADisplayLink *displayLink) {
207
+ auto nodesManager = reanimatedModule.nodesManager;
208
+
209
+ auto requestRender = [nodesManager, &module](std::function<void(double)> onRender, jsi::Runtime &rt) {
210
+ [nodesManager postOnAnimation:^(CADisplayLink *displayLink) {
218
211
  double frameTimestamp = calculateTimestampWithSlowAnimations(displayLink.targetTimestamp) * 1000;
219
212
  jsi::Object global = rt.global();
220
213
  jsi::String frameTimestampName = jsi::String::createFromAscii(rt, "_frameTimestamp");
@@ -225,10 +218,10 @@ std::shared_ptr<NativeReanimatedModule> createReanimatedModule(
225
218
  };
226
219
 
227
220
  #ifdef RCT_NEW_ARCH_ENABLED
228
- auto synchronouslyUpdateUIPropsFunction = [reanimatedModule](jsi::Runtime &rt, Tag tag, const jsi::Value &props) {
221
+ auto synchronouslyUpdateUIPropsFunction = [nodesManager](jsi::Runtime &rt, Tag tag, const jsi::Value &props) {
229
222
  NSNumber *viewTag = @(tag);
230
223
  NSDictionary *uiProps = convertJSIObjectToNSDictionary(rt, props.asObject(rt));
231
- [reanimatedModule.nodesManager synchronouslyUpdateViewOnUIThread:viewTag props:uiProps];
224
+ [nodesManager synchronouslyUpdateViewOnUIThread:viewTag props:uiProps];
232
225
  };
233
226
 
234
227
  std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy =
@@ -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);
@@ -0,0 +1,22 @@
1
+ #pragma once
2
+
3
+ #import <memory>
4
+ #import <string>
5
+
6
+ #import <Foundation/Foundation.h>
7
+
8
+ #import <React/RCTJavaScriptExecutor.h>
9
+ #import <React/RCTMessageThread.h>
10
+ #import <cxxreact/MessageQueueThread.h>
11
+
12
+ namespace facebook {
13
+ namespace react {
14
+
15
+ class REAMessageThread : public RCTMessageThread {
16
+ public:
17
+ using RCTMessageThread::RCTMessageThread;
18
+ virtual void quitSynchronous() override;
19
+ };
20
+
21
+ } // namespace react
22
+ } // namespace facebook
@@ -0,0 +1,38 @@
1
+ #import <RNReanimated/REAMessageThread.h>
2
+
3
+ #include <condition_variable>
4
+ #include <mutex>
5
+
6
+ #import <React/RCTCxxUtils.h>
7
+ #import <React/RCTMessageThread.h>
8
+ #import <React/RCTUtils.h>
9
+
10
+ namespace facebook {
11
+ namespace react {
12
+
13
+ // Essentially the same as RCTMessageThread, but with public fields.
14
+ struct REAMessageThreadPublic {
15
+ // I don't know why we need three vtables (if you know then feel free to
16
+ // explain it instead of this message), but this is what makes the casts in
17
+ // quitSynchronous() work correctly.
18
+ void *vtable1;
19
+ void *vtable2;
20
+ void *vtable3;
21
+ CFRunLoopRef m_cfRunLoop;
22
+ RCTJavaScriptCompleteBlock m_errorBlock;
23
+ std::atomic_bool m_shutdown;
24
+ };
25
+
26
+ // We need to prevent any new code from being executed on the thread as there
27
+ // is an assertion for that in the destructor of RCTMessageThread, but we have
28
+ // to override quitSynchronous() as it would quit the main looper and freeze
29
+ // the app.
30
+ void REAMessageThread::quitSynchronous()
31
+ {
32
+ RCTMessageThread *rctThread = static_cast<RCTMessageThread *>(this);
33
+ REAMessageThreadPublic *rctThreadPublic = reinterpret_cast<REAMessageThreadPublic *>(rctThread);
34
+ rctThreadPublic->m_shutdown = true;
35
+ }
36
+
37
+ }
38
+ }
@@ -21,7 +21,7 @@ typedef JSCExecutorFactory ExecutorFactory;
21
21
  {
22
22
  const auto installer = reanimated::REAJSIExecutorRuntimeInstaller(bridge, NULL);
23
23
 
24
- #if RNVERSION >= 64
24
+ #if REACT_NATIVE_MINOR_VERSION >= 64
25
25
  // installs globals such as console, nativePerformanceNow, etc.
26
26
  return std::make_unique<ExecutorFactory>(RCTJSIExecutorRuntimeInstaller(installer));
27
27
  #else
@@ -118,11 +118,8 @@ function createAnimatedComponent(Component, options) {
118
118
  // TODO update config
119
119
  const tag = (0, _reactNative.findNodeHandle)(ref);
120
120
 
121
- if ((this.props.layout || this.props.entering || this.props.exiting) && tag != null) {
122
- if (!(0, _PlatformChecker.shouldBeUseWeb)()) {
123
- (0, _core.enableLayoutAnimations)(true, false);
124
- }
125
-
121
+ if (!(0, _PlatformChecker.shouldBeUseWeb)() && (this.props.layout || this.props.entering || this.props.exiting) && tag != null) {
122
+ (0, _core.enableLayoutAnimations)(true, false);
126
123
  let layout = this.props.layout ? this.props.layout : _Default.DefaultLayout;
127
124
  let entering = this.props.entering ? this.props.entering : _Default.DefaultEntering;
128
125
  let exiting = this.props.exiting ? this.props.exiting : _Default.DefaultExiting;