react-native-reanimated 2.8.0 → 2.10.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 (224) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +4 -4
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +38 -0
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +23 -0
  4. package/Common/cpp/Tools/RuntimeDecorator.cpp +17 -11
  5. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +8 -0
  6. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +8 -0
  7. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +5 -0
  8. package/RNReanimated.podspec +22 -3
  9. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  10. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  11. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  12. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  13. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  14. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
  17. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  18. package/android/.gradle/checksums/checksums.lock +0 -0
  19. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  20. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  21. package/android/CMakeLists.txt +216 -84
  22. package/android/build.gradle +255 -229
  23. package/android/react-native-reanimated-66-hermes.aar +0 -0
  24. package/android/react-native-reanimated-66-jsc.aar +0 -0
  25. package/android/react-native-reanimated-67-hermes.aar +0 -0
  26. package/android/react-native-reanimated-67-jsc.aar +0 -0
  27. package/android/react-native-reanimated-68-hermes.aar +0 -0
  28. package/android/react-native-reanimated-68-jsc.aar +0 -0
  29. package/android/react-native-reanimated-69-hermes.aar +0 -0
  30. package/android/react-native-reanimated-69-jsc.aar +0 -0
  31. package/android/react-native-reanimated-70-hermes.aar +0 -0
  32. package/android/react-native-reanimated-70-jsc.aar +0 -0
  33. package/{lib/types/lib/reanimated2/platform-specific/RNRenderer.web.d.ts → android/rnVersionPatch/69/.gitkeep} +0 -0
  34. package/android/rnVersionPatch/70/.gitkeep +0 -0
  35. package/android/src/main/cpp/NativeProxy.cpp +56 -11
  36. package/android/src/main/cpp/OnLoad.cpp +1 -0
  37. package/android/src/main/cpp/headers/NativeProxy.h +29 -0
  38. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +25 -0
  39. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +3 -1
  40. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +165 -0
  41. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +19 -16
  42. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +5 -1
  43. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +24 -1
  44. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +7 -5
  45. package/ios/REANodesManager.m +31 -8
  46. package/ios/keyboardObserver/REAKeyboardEventObserver.h +17 -0
  47. package/ios/keyboardObserver/REAKeyboardEventObserver.m +198 -0
  48. package/ios/native/NativeProxy.mm +20 -1
  49. package/ios/native/REAInitializer.mm +10 -4
  50. package/ios/sensor/ReanimatedSensor.m +27 -18
  51. package/lib/Animated.js +8 -21
  52. package/lib/index.js +12 -20
  53. package/lib/index.web.js +4 -0
  54. package/lib/reanimated2/Colors.js +1 -1
  55. package/lib/reanimated2/NativeMethods.js +3 -0
  56. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +7 -1
  57. package/lib/reanimated2/animation/sequence.js +0 -3
  58. package/lib/reanimated2/animation/util.js +4 -1
  59. package/lib/reanimated2/commonTypes.js +8 -1
  60. package/lib/reanimated2/component/FlatList.js +8 -8
  61. package/lib/reanimated2/component/Image.js +4 -0
  62. package/lib/reanimated2/component/ScrollView.js +4 -0
  63. package/lib/reanimated2/component/Text.js +4 -0
  64. package/lib/reanimated2/component/View.js +4 -0
  65. package/lib/reanimated2/core.js +5 -9
  66. package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +32 -0
  67. package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +47 -0
  68. package/lib/reanimated2/globals.d.ts +3 -0
  69. package/lib/reanimated2/hook/index.js +2 -0
  70. package/lib/reanimated2/hook/useAnimatedKeyboard.js +31 -0
  71. package/lib/reanimated2/hook/useAnimatedSensor.js +3 -3
  72. package/lib/reanimated2/hook/useFrameCallback.js +23 -0
  73. package/lib/reanimated2/hook/utils.js +0 -5
  74. package/lib/reanimated2/jestUtils.js +11 -3
  75. package/lib/reanimated2/js-reanimated/JSReanimated.js +7 -0
  76. package/lib/reanimated2/js-reanimated/global.js +36 -0
  77. package/lib/reanimated2/js-reanimated/index.js +0 -24
  78. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +1 -1
  79. package/lib/reanimated2/mock.js +6 -0
  80. package/lib/types/Animated.d.ts +8 -0
  81. package/lib/types/{lib/ConfigHelper.d.ts → ConfigHelper.d.ts} +0 -0
  82. package/lib/types/{lib/ReanimatedEventEmitter.d.ts → ReanimatedEventEmitter.d.ts} +0 -0
  83. package/lib/types/{lib/ReanimatedModule.d.ts → ReanimatedModule.d.ts} +0 -0
  84. package/lib/types/{lib/ReanimatedModule.macos.d.ts → ReanimatedModule.macos.d.ts} +0 -0
  85. package/lib/types/{lib/ReanimatedModule.native.d.ts → ReanimatedModule.native.d.ts} +0 -0
  86. package/lib/types/{lib/ReanimatedModule.windows.d.ts → ReanimatedModule.windows.d.ts} +0 -0
  87. package/lib/types/{lib/ReanimatedModuleCompat.d.ts → ReanimatedModuleCompat.d.ts} +0 -0
  88. package/lib/types/{lib/createAnimatedComponent.d.ts → createAnimatedComponent.d.ts} +0 -0
  89. package/lib/types/index.d.ts +4 -0
  90. package/lib/types/index.web.d.ts +3 -0
  91. package/lib/types/{lib/reanimated2 → reanimated2}/Bezier.d.ts +0 -0
  92. package/lib/types/{lib/reanimated2 → reanimated2}/Colors.d.ts +0 -0
  93. package/lib/types/{lib/reanimated2 → reanimated2}/Easing.d.ts +0 -0
  94. package/lib/types/{lib/reanimated2 → reanimated2}/NativeMethods.d.ts +0 -0
  95. package/lib/types/{lib/reanimated2 → reanimated2}/NativeReanimated/NativeReanimated.d.ts +3 -1
  96. package/lib/types/{lib/reanimated2 → reanimated2}/NativeReanimated/index.d.ts +0 -0
  97. package/lib/types/{lib/reanimated2 → reanimated2}/PlatformChecker.d.ts +0 -0
  98. package/lib/types/{lib/reanimated2 → reanimated2}/PropAdapters.d.ts +0 -0
  99. package/lib/types/{lib/reanimated2 → reanimated2}/UpdateProps.d.ts +0 -0
  100. package/lib/types/{lib/reanimated2 → reanimated2}/ViewDescriptorsSet.d.ts +0 -0
  101. package/lib/types/{lib/reanimated2 → reanimated2}/WorkletEventHandler.d.ts +0 -0
  102. package/lib/types/{lib/reanimated2 → reanimated2}/__mocks__/MutableValue.d.ts +0 -0
  103. package/lib/types/{lib/reanimated2 → reanimated2}/__mocks__/NativeReanimated.d.ts +0 -0
  104. package/lib/types/{lib/reanimated2 → reanimated2}/__mocks__/NativeReanimated.native.d.ts +0 -0
  105. package/lib/types/{lib/reanimated2 → reanimated2}/animation/commonTypes.d.ts +0 -0
  106. package/lib/types/{lib/reanimated2 → reanimated2}/animation/decay.d.ts +0 -0
  107. package/lib/types/{lib/reanimated2 → reanimated2}/animation/delay.d.ts +0 -0
  108. package/lib/types/{lib/reanimated2 → reanimated2}/animation/index.d.ts +0 -0
  109. package/lib/types/{lib/reanimated2 → reanimated2}/animation/repeat.d.ts +0 -0
  110. package/lib/types/{lib/reanimated2 → reanimated2}/animation/sequence.d.ts +0 -0
  111. package/lib/types/{lib/reanimated2 → reanimated2}/animation/spring.d.ts +0 -0
  112. package/lib/types/{lib/reanimated2 → reanimated2}/animation/styleAnimation.d.ts +0 -0
  113. package/lib/types/{lib/reanimated2 → reanimated2}/animation/timing.d.ts +0 -0
  114. package/lib/types/{lib/reanimated2 → reanimated2}/animation/util.d.ts +0 -0
  115. package/lib/types/{lib/reanimated2 → reanimated2}/commonTypes.d.ts +12 -0
  116. package/lib/types/{lib/reanimated2 → reanimated2}/component/FlatList.d.ts +2 -2
  117. package/lib/types/reanimated2/component/Image.d.ts +3 -0
  118. package/lib/types/reanimated2/component/ScrollView.d.ts +3 -0
  119. package/lib/types/reanimated2/component/Text.d.ts +3 -0
  120. package/lib/types/reanimated2/component/View.d.ts +3 -0
  121. package/lib/types/{lib/reanimated2 → reanimated2}/core.d.ts +0 -0
  122. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +7 -0
  123. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +10 -0
  124. package/lib/types/{lib/reanimated2 → reanimated2}/hook/Hooks.d.ts +0 -0
  125. package/lib/types/{lib/reanimated2 → reanimated2}/hook/commonTypes.d.ts +0 -0
  126. package/lib/types/{lib/reanimated2 → reanimated2}/hook/index.d.ts +3 -0
  127. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useAnimatedGestureHandler.d.ts +0 -0
  128. package/lib/types/reanimated2/hook/useAnimatedKeyboard.d.ts +2 -0
  129. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useAnimatedReaction.d.ts +0 -0
  130. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useAnimatedRef.d.ts +0 -0
  131. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useAnimatedScrollHandler.d.ts +0 -0
  132. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useAnimatedSensor.d.ts +1 -1
  133. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useAnimatedStyle.d.ts +0 -0
  134. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useDerivedValue.d.ts +0 -0
  135. package/lib/types/reanimated2/hook/useFrameCallback.d.ts +6 -0
  136. package/lib/types/{lib/reanimated2 → reanimated2}/hook/useSharedValue.d.ts +0 -0
  137. package/lib/types/{lib/reanimated2 → reanimated2}/hook/utils.d.ts +0 -0
  138. package/lib/types/{lib/reanimated2 → reanimated2}/index.d.ts +0 -0
  139. package/lib/types/{lib/reanimated2 → reanimated2}/interpolateColor.d.ts +0 -0
  140. package/lib/types/{lib/reanimated2 → reanimated2}/interpolation.d.ts +0 -0
  141. package/lib/types/{lib/reanimated2 → reanimated2}/jestUtils.d.ts +1 -1
  142. package/lib/types/{lib/reanimated2 → reanimated2}/js-reanimated/JSReanimated.d.ts +3 -1
  143. package/lib/types/{lib/reanimated2 → reanimated2}/js-reanimated/Mapper.d.ts +0 -0
  144. package/lib/types/{lib/reanimated2 → reanimated2}/js-reanimated/MapperRegistry.d.ts +0 -0
  145. package/lib/types/{lib/reanimated2 → reanimated2}/js-reanimated/MutableValue.d.ts +0 -0
  146. package/lib/types/{lib/reanimated2 → reanimated2}/js-reanimated/commonTypes.d.ts +0 -0
  147. package/lib/types/reanimated2/js-reanimated/global.d.ts +2 -0
  148. package/lib/types/{lib/reanimated2 → reanimated2}/js-reanimated/index.d.ts +0 -0
  149. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/LayoutAnimationRepository.d.ts +0 -0
  150. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/animationBuilder/BaseAnimationBuilder.d.ts +0 -0
  151. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/animationBuilder/ComplexAnimationBuilder.d.ts +0 -0
  152. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/animationBuilder/Keyframe.d.ts +0 -0
  153. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/animationBuilder/commonTypes.d.ts +0 -0
  154. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/animationBuilder/index.d.ts +0 -0
  155. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Bounce.d.ts +0 -0
  156. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Default.d.ts +0 -0
  157. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Fade.d.ts +0 -0
  158. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Flip.d.ts +0 -0
  159. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Lightspeed.d.ts +0 -0
  160. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Pinwheel.d.ts +0 -0
  161. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Roll.d.ts +0 -0
  162. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Rotate.d.ts +0 -0
  163. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Slide.d.ts +0 -0
  164. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Stretch.d.ts +0 -0
  165. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/Zoom.d.ts +0 -0
  166. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultAnimations/index.d.ts +0 -0
  167. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/CurvedTransition.d.ts +0 -0
  168. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/EntryExitTransition.d.ts +0 -0
  169. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/FadingTransition.d.ts +0 -0
  170. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/JumpingTransition.d.ts +0 -0
  171. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/LinearTransition.d.ts +0 -0
  172. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/SequencedTransition.d.ts +0 -0
  173. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/defaultTransitions/index.d.ts +0 -0
  174. package/lib/types/{lib/reanimated2 → reanimated2}/layoutReanimation/index.d.ts +0 -0
  175. package/lib/types/{lib/reanimated2 → reanimated2}/mock.d.ts +6 -0
  176. package/lib/types/{lib/reanimated2 → reanimated2}/platform-specific/RNRenderer.d.ts +0 -0
  177. package/lib/types/reanimated2/platform-specific/RNRenderer.web.d.ts +0 -0
  178. package/lib/types/{lib/reanimated2 → reanimated2}/utils.d.ts +0 -0
  179. package/lib/types/{lib/setAndForwardRef.d.ts → setAndForwardRef.d.ts} +0 -0
  180. package/mock.js +1 -0
  181. package/package.json +15 -10
  182. package/plugin.js +7 -6
  183. package/react-native-reanimated.d.ts +56 -8
  184. package/src/Animated.ts +13 -0
  185. package/src/index.ts +15 -0
  186. package/src/index.web.ts +5 -0
  187. package/src/reanimated2/Colors.ts +1 -1
  188. package/src/reanimated2/NativeMethods.ts +5 -0
  189. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +10 -1
  190. package/src/reanimated2/animation/sequence.ts +0 -5
  191. package/src/reanimated2/animation/util.ts +8 -1
  192. package/src/reanimated2/commonTypes.ts +15 -0
  193. package/src/reanimated2/component/FlatList.tsx +32 -25
  194. package/src/reanimated2/component/Image.ts +6 -0
  195. package/src/reanimated2/component/ScrollView.ts +6 -0
  196. package/src/reanimated2/component/Text.ts +6 -0
  197. package/src/reanimated2/component/View.ts +6 -0
  198. package/src/reanimated2/core.ts +8 -13
  199. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +43 -0
  200. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +64 -0
  201. package/src/reanimated2/globals.d.ts +3 -0
  202. package/src/reanimated2/hook/index.ts +3 -0
  203. package/src/reanimated2/hook/useAnimatedKeyboard.ts +35 -0
  204. package/src/reanimated2/hook/useAnimatedSensor.ts +5 -5
  205. package/src/reanimated2/hook/useFrameCallback.ts +39 -0
  206. package/src/reanimated2/hook/utils.ts +0 -6
  207. package/src/reanimated2/jestUtils.ts +11 -3
  208. package/src/reanimated2/js-reanimated/JSReanimated.ts +16 -1
  209. package/src/reanimated2/js-reanimated/global.ts +45 -0
  210. package/src/reanimated2/js-reanimated/index.ts +0 -31
  211. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +1 -1
  212. package/src/reanimated2/mock.ts +6 -0
  213. package/android/react-native-reanimated-64-hermes.aar +0 -0
  214. package/android/react-native-reanimated-64-jsc.aar +0 -0
  215. package/android/react-native-reanimated-65-hermes.aar +0 -0
  216. package/android/react-native-reanimated-65-jsc.aar +0 -0
  217. package/lib/reanimated2/component/WrappedComponents.js +0 -9
  218. package/lib/reanimated2/component/index.js +0 -4
  219. package/lib/types/lib/reanimated2/component/WrappedComponents.d.ts +0 -8
  220. package/lib/types/lib/reanimated2/component/index.d.ts +0 -9
  221. package/lib/types/react-native-reanimated-tests.d.ts +0 -1
  222. package/src/Animated.js +0 -22
  223. package/src/reanimated2/component/WrappedComponents.ts +0 -11
  224. package/src/reanimated2/component/index.ts +0 -9
@@ -7,8 +7,10 @@
7
7
  #include <memory>
8
8
  #include <string>
9
9
 
10
- #if FOR_HERMES
10
+ #if JS_RUNTIME_HERMES
11
11
  #include <hermes/hermes.h>
12
+ #elif JS_RUNTIME_V8
13
+ #include <v8runtime/V8RuntimeFactory.h>
12
14
  #else
13
15
  #include <jsi/JSCRuntime.h>
14
16
  #endif
@@ -38,10 +40,8 @@ NativeProxy::NativeProxy(
38
40
  layoutAnimations(std::move(_layoutAnimations)) {}
39
41
 
40
42
  NativeProxy::~NativeProxy() {
41
- runtime_->global().setProperty(
42
- *runtime_,
43
- jsi::PropNameID::forAscii(*runtime_, "__reanimatedModuleProxy"),
44
- jsi::Value::undefined());
43
+ // removed temporary, new event listener mechanism need fix on the RN side
44
+ // reactScheduler_->removeEventListener(eventListener_);
45
45
  }
46
46
 
47
47
  jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybrid(
@@ -136,20 +136,44 @@ void NativeProxy::installJSIBindings() {
136
136
  auto setGestureStateFunction = [this](int handlerTag, int newState) -> void {
137
137
  setGestureState(handlerTag, newState);
138
138
  };
139
- #if FOR_HERMES
139
+
140
+ auto subscribeForKeyboardEventsFunction =
141
+ [this](std::function<void(int, int)> keyboardEventDataUpdater) -> int {
142
+ return subscribeForKeyboardEvents(std::move(keyboardEventDataUpdater));
143
+ };
144
+
145
+ auto unsubscribeFromKeyboardEventsFunction = [this](int listenerId) -> void {
146
+ unsubscribeFromKeyboardEvents(listenerId);
147
+ };
148
+
149
+ #if JS_RUNTIME_HERMES
140
150
  auto config =
141
151
  ::hermes::vm::RuntimeConfig::Builder().withEnableSampleProfiling(false);
142
152
  std::shared_ptr<jsi::Runtime> animatedRuntime =
143
153
  facebook::hermes::makeHermesRuntime(config.build());
154
+ #elif JS_RUNTIME_V8
155
+ auto config = std::make_unique<rnv8::V8RuntimeConfig>();
156
+ config->enableInspector = false;
157
+ config->appName = "reanimated";
158
+ std::shared_ptr<jsi::Runtime> animatedRuntime =
159
+ rnv8::createSharedV8Runtime(runtime_, std::move(config));
144
160
  #else
145
161
  std::shared_ptr<jsi::Runtime> animatedRuntime =
146
162
  facebook::jsc::makeJSCRuntime();
147
163
  #endif
164
+ auto workletRuntimeValue =
165
+ runtime_->global()
166
+ .getProperty(*runtime_, "ArrayBuffer")
167
+ .asObject(*runtime_)
168
+ .asFunction(*runtime_)
169
+ .callAsConstructor(*runtime_, {static_cast<double>(sizeof(void *))});
170
+ uintptr_t *workletRuntimeData = reinterpret_cast<uintptr_t *>(
171
+ workletRuntimeValue.getObject(*runtime_).getArrayBuffer(*runtime_).data(
172
+ *runtime_));
173
+ workletRuntimeData[0] = reinterpret_cast<uintptr_t>(animatedRuntime.get());
174
+
148
175
  runtime_->global().setProperty(
149
- *runtime_,
150
- "_WORKLET_RUNTIME",
151
- static_cast<double>(
152
- reinterpret_cast<std::uintptr_t>(animatedRuntime.get())));
176
+ *runtime_, "_WORKLET_RUNTIME", workletRuntimeValue);
153
177
 
154
178
  std::shared_ptr<ErrorHandler> errorHandler =
155
179
  std::make_shared<AndroidErrorHandler>(scheduler_);
@@ -187,7 +211,10 @@ void NativeProxy::installJSIBindings() {
187
211
  registerSensorFunction,
188
212
  unregisterSensorFunction,
189
213
  setGestureStateFunction,
190
- configurePropsFunction};
214
+ configurePropsFunction,
215
+ subscribeForKeyboardEventsFunction,
216
+ unsubscribeFromKeyboardEventsFunction,
217
+ };
191
218
 
192
219
  auto module = std::make_shared<NativeReanimatedModule>(
193
220
  jsCallInvoker_,
@@ -334,4 +361,22 @@ void NativeProxy::configureProps(
334
361
  .get());
335
362
  }
336
363
 
364
+ int NativeProxy::subscribeForKeyboardEvents(
365
+ std::function<void(int, int)> keyboardEventDataUpdater) {
366
+ auto method = javaPart_->getClass()
367
+ ->getMethod<int(KeyboardEventDataUpdater::javaobject)>(
368
+ "subscribeForKeyboardEvents");
369
+ return method(
370
+ javaPart_.get(),
371
+ KeyboardEventDataUpdater::newObjectCxxArgs(
372
+ std::move(keyboardEventDataUpdater))
373
+ .get());
374
+ }
375
+
376
+ void NativeProxy::unsubscribeFromKeyboardEvents(int listenerId) {
377
+ auto method = javaPart_->getClass()->getMethod<void(int)>(
378
+ "unsubscribeFromKeyboardEvents");
379
+ method(javaPart_.get(), listenerId);
380
+ }
381
+
337
382
  } // namespace reanimated
@@ -13,5 +13,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
13
13
  reanimated::AndroidScheduler::registerNatives();
14
14
  reanimated::LayoutAnimations::registerNatives();
15
15
  reanimated::SensorSetter::registerNatives();
16
+ reanimated::KeyboardEventDataUpdater::registerNatives();
16
17
  });
17
18
  }
@@ -118,6 +118,32 @@ class SensorSetter : public HybridClass<SensorSetter> {
118
118
  std::function<void(double[])> callback_;
119
119
  };
120
120
 
121
+ class KeyboardEventDataUpdater : public HybridClass<KeyboardEventDataUpdater> {
122
+ public:
123
+ static auto constexpr kJavaDescriptor =
124
+ "Lcom/swmansion/reanimated/NativeProxy$KeyboardEventDataUpdater;";
125
+
126
+ void keyboardEventDataUpdater(int keyboardState, int height) {
127
+ callback_(keyboardState, height);
128
+ }
129
+
130
+ static void registerNatives() {
131
+ javaClassStatic()->registerNatives({
132
+ makeNativeMethod(
133
+ "keyboardEventDataUpdater",
134
+ KeyboardEventDataUpdater::keyboardEventDataUpdater),
135
+ });
136
+ }
137
+
138
+ private:
139
+ friend HybridBase;
140
+
141
+ explicit KeyboardEventDataUpdater(std::function<void(int, int)> callback)
142
+ : callback_(std::move(callback)) {}
143
+
144
+ std::function<void(int, int)> callback_;
145
+ };
146
+
121
147
  class NativeProxy : public jni::HybridClass<NativeProxy> {
122
148
  public:
123
149
  static auto constexpr kJavaDescriptor =
@@ -160,6 +186,9 @@ class NativeProxy : public jni::HybridClass<NativeProxy> {
160
186
  jsi::Runtime &rt,
161
187
  const jsi::Value &uiProps,
162
188
  const jsi::Value &nativeProps);
189
+ int subscribeForKeyboardEvents(
190
+ std::function<void(int, int)> keyboardEventDataUpdater);
191
+ void unsubscribeFromKeyboardEvents(int listenerId);
163
192
 
164
193
  explicit NativeProxy(
165
194
  jni::alias_ref<NativeProxy::jhybridobject> jThis,
@@ -16,6 +16,7 @@ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
16
16
  import com.facebook.react.uimanager.UIManagerModule;
17
17
  import com.facebook.react.uimanager.events.RCTEventEmitter;
18
18
  import com.swmansion.common.GestureHandlerStateManager;
19
+ import com.swmansion.reanimated.keyboardObserver.ReanimatedKeyboardEventListener;
19
20
  import com.swmansion.reanimated.layoutReanimation.AnimationsManager;
20
21
  import com.swmansion.reanimated.layoutReanimation.LayoutAnimations;
21
22
  import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder;
@@ -87,6 +88,18 @@ public class NativeProxy {
87
88
  public native void sensorSetter(float[] value);
88
89
  }
89
90
 
91
+ @DoNotStrip
92
+ public static class KeyboardEventDataUpdater {
93
+ @DoNotStrip private final HybridData mHybridData;
94
+
95
+ @DoNotStrip
96
+ private KeyboardEventDataUpdater(HybridData hybridData) {
97
+ mHybridData = hybridData;
98
+ }
99
+
100
+ public native void keyboardEventDataUpdater(int keyboardState, int height);
101
+ }
102
+
90
103
  @DoNotStrip
91
104
  @SuppressWarnings("unused")
92
105
  private final HybridData mHybridData;
@@ -96,6 +109,7 @@ public class NativeProxy {
96
109
  private Scheduler mScheduler = null;
97
110
  private ReanimatedSensorContainer reanimatedSensorContainer;
98
111
  private final GestureHandlerStateManager gestureHandlerStateManager;
112
+ private ReanimatedKeyboardEventListener reanimatedKeyboardEventListener;
99
113
  private Long firstUptime = SystemClock.uptimeMillis();
100
114
  private boolean slowAnimationsEnabled = false;
101
115
 
@@ -110,6 +124,7 @@ public class NativeProxy {
110
124
  mContext = new WeakReference<>(context);
111
125
  prepare(LayoutAnimations);
112
126
  reanimatedSensorContainer = new ReanimatedSensorContainer(mContext);
127
+ reanimatedKeyboardEventListener = new ReanimatedKeyboardEventListener(mContext);
113
128
  addDevMenuOption();
114
129
 
115
130
  GestureHandlerStateManager tempHandlerStateManager;
@@ -237,6 +252,16 @@ public class NativeProxy {
237
252
  reanimatedSensorContainer.unregisterSensor(sensorId);
238
253
  }
239
254
 
255
+ @DoNotStrip
256
+ private int subscribeForKeyboardEvents(KeyboardEventDataUpdater keyboardEventDataUpdater) {
257
+ return reanimatedKeyboardEventListener.subscribeForKeyboardEvents(keyboardEventDataUpdater);
258
+ }
259
+
260
+ @DoNotStrip
261
+ private void unsubscribeFromKeyboardEvents(int listenerId) {
262
+ reanimatedKeyboardEventListener.unsubscribeFromKeyboardEvents(listenerId);
263
+ }
264
+
240
265
  public void onCatalystInstanceDestroy() {
241
266
  mScheduler.deactivate();
242
267
  mHybridData.resetNative();
@@ -1,5 +1,7 @@
1
1
  package com.swmansion.reanimated;
2
2
 
3
+ import static java.lang.Float.NaN;
4
+
3
5
  import android.util.SparseArray;
4
6
  import android.view.View;
5
7
  import com.facebook.react.bridge.Arguments;
@@ -83,7 +85,7 @@ public class NodesManager implements EventDispatcherListener {
83
85
  view = mUIManager.resolveView(viewTag);
84
86
  } catch (IllegalViewOperationException e) {
85
87
  e.printStackTrace();
86
- return (new float[] {});
88
+ return (new float[] {NaN, NaN, NaN, NaN, NaN, NaN});
87
89
  }
88
90
  return NativeMethodsHelper.measure(view);
89
91
  }
@@ -0,0 +1,165 @@
1
+ package com.swmansion.reanimated.keyboardObserver;
2
+
3
+ import android.os.Handler;
4
+ import android.os.Looper;
5
+ import android.view.View;
6
+ import android.widget.FrameLayout;
7
+ import androidx.annotation.NonNull;
8
+ import androidx.core.view.ViewCompat;
9
+ import androidx.core.view.WindowCompat;
10
+ import androidx.core.view.WindowInsetsAnimationCompat;
11
+ import androidx.core.view.WindowInsetsCompat;
12
+ import com.facebook.react.bridge.ReactApplicationContext;
13
+ import com.facebook.react.uimanager.PixelUtil;
14
+ import com.swmansion.reanimated.BuildConfig;
15
+ import com.swmansion.reanimated.NativeProxy.KeyboardEventDataUpdater;
16
+ import java.lang.ref.WeakReference;
17
+ import java.util.HashMap;
18
+ import java.util.List;
19
+
20
+ public class ReanimatedKeyboardEventListener {
21
+ enum KeyboardState {
22
+ UNKNOWN(0),
23
+ OPENING(1),
24
+ OPEN(2),
25
+ CLOSING(3),
26
+ CLOSED(4);
27
+
28
+ private final int value;
29
+
30
+ KeyboardState(int value) {
31
+ this.value = value;
32
+ }
33
+
34
+ public int asInt() {
35
+ return value;
36
+ }
37
+ }
38
+
39
+ private final WeakReference<ReactApplicationContext> reactContext;
40
+ private int nextListenerId = 0;
41
+ private KeyboardState state;
42
+ private final HashMap<Integer, KeyboardEventDataUpdater> listeners = new HashMap<>();
43
+
44
+ public ReanimatedKeyboardEventListener(WeakReference<ReactApplicationContext> reactContext) {
45
+ this.reactContext = reactContext;
46
+ }
47
+
48
+ private View getRootView() {
49
+ return reactContext.get().getCurrentActivity().getWindow().getDecorView();
50
+ }
51
+
52
+ private void setupWindowInsets() {
53
+ View rootView = getRootView();
54
+ WindowCompat.setDecorFitsSystemWindows(
55
+ reactContext.get().getCurrentActivity().getWindow(), false);
56
+ ViewCompat.setOnApplyWindowInsetsListener(
57
+ rootView,
58
+ (v, insets) -> {
59
+ int paddingBottom = 0;
60
+ if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED && BuildConfig.REACT_NATIVE_VERSION < 70) {
61
+ paddingBottom = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
62
+ }
63
+ int paddingTop = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;
64
+ View content =
65
+ rootView.getRootView().findViewById(com.swmansion.reanimated.R.id.action_bar_root);
66
+
67
+ FrameLayout.LayoutParams params =
68
+ new FrameLayout.LayoutParams(
69
+ FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
70
+ params.setMargins(0, paddingTop, 0, paddingBottom);
71
+ content.setLayoutParams(params);
72
+ return insets;
73
+ });
74
+ }
75
+
76
+ private void updateKeyboard(int keyboardHeight) {
77
+ for (KeyboardEventDataUpdater listener : listeners.values()) {
78
+ listener.keyboardEventDataUpdater(state.asInt(), keyboardHeight);
79
+ }
80
+ }
81
+
82
+ private class WindowInsetsCallback extends WindowInsetsAnimationCompat.Callback {
83
+ private int keyboardHeight = 0;
84
+
85
+ public WindowInsetsCallback() {
86
+ super(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE);
87
+ }
88
+
89
+ @NonNull
90
+ @Override
91
+ public WindowInsetsAnimationCompat.BoundsCompat onStart(
92
+ @NonNull WindowInsetsAnimationCompat animation,
93
+ @NonNull WindowInsetsAnimationCompat.BoundsCompat bounds) {
94
+ state = keyboardHeight == 0 ? KeyboardState.OPENING : KeyboardState.CLOSING;
95
+ updateKeyboard(keyboardHeight);
96
+ return super.onStart(animation, bounds);
97
+ }
98
+
99
+ @NonNull
100
+ @Override
101
+ public WindowInsetsCompat onProgress(
102
+ @NonNull WindowInsetsCompat insets,
103
+ @NonNull List<WindowInsetsAnimationCompat> runningAnimations) {
104
+
105
+ keyboardHeight =
106
+ (int)
107
+ PixelUtil.toDIPFromPixel(
108
+ Math.max(
109
+ 0,
110
+ insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
111
+ - insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom));
112
+ updateKeyboard(keyboardHeight);
113
+ return insets;
114
+ }
115
+
116
+ @Override
117
+ public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
118
+ state = keyboardHeight == 0 ? KeyboardState.CLOSED : KeyboardState.OPEN;
119
+ updateKeyboard(keyboardHeight);
120
+ }
121
+ }
122
+
123
+ private void setUpCallbacks() {
124
+ View rootView = getRootView();
125
+ new Handler(Looper.getMainLooper()).post(this::setupWindowInsets);
126
+ ViewCompat.setWindowInsetsAnimationCallback(rootView, new WindowInsetsCallback());
127
+ }
128
+
129
+ public int subscribeForKeyboardEvents(KeyboardEventDataUpdater updater) {
130
+ int listenerId = nextListenerId++;
131
+ if (listeners.isEmpty()) {
132
+ setUpCallbacks();
133
+ }
134
+ listeners.put(listenerId, updater);
135
+ return listenerId;
136
+ }
137
+
138
+ private void bringBackWindowInsets() {
139
+ WindowCompat.setDecorFitsSystemWindows(
140
+ reactContext.get().getCurrentActivity().getWindow(), true);
141
+ ViewCompat.setOnApplyWindowInsetsListener(getRootView(), null);
142
+ ViewCompat.setWindowInsetsAnimationCallback(getRootView(), null);
143
+ View content =
144
+ getRootView().getRootView().findViewById(com.swmansion.reanimated.R.id.action_bar_root);
145
+
146
+ FrameLayout.LayoutParams params =
147
+ new FrameLayout.LayoutParams(
148
+ FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
149
+ params.setMargins(0, 0, 0, 0);
150
+ content.setLayoutParams(params);
151
+ }
152
+
153
+ private void removeCallbacks() {
154
+ View rootView = getRootView();
155
+ new Handler(Looper.getMainLooper()).post(this::bringBackWindowInsets);
156
+ ViewCompat.setWindowInsetsAnimationCallback(rootView, null);
157
+ }
158
+
159
+ public void unsubscribeFromKeyboardEvents(int listenerId) {
160
+ listeners.remove(listenerId);
161
+ if (listeners.isEmpty()) {
162
+ removeCallbacks();
163
+ }
164
+ }
165
+ }
@@ -229,24 +229,27 @@ public class AnimationsManager implements ViewHierarchyObserver {
229
229
  }
230
230
 
231
231
  private void removeLeftovers() {
232
- HashSet<Integer> roots = new HashSet<>();
233
- // go through ready to remove from bottom to top
234
- for (int tag : mToRemove) {
235
- View view = mViewForTag.get(tag);
236
- if (view == null) {
237
- try {
238
- view = mUIManager.resolveView(tag);
239
- mViewForTag.put(tag, view);
240
- } catch (IllegalViewOperationException ignored) {
241
- continue;
232
+ //mToRemove may be null if onCatalystInstanceDestroy was called first
233
+ if(mToRemove != null){
234
+ HashSet<Integer> roots = new HashSet<>();
235
+ // go through ready to remove from bottom to top
236
+ for (int tag : mToRemove) {
237
+ View view = mViewForTag.get(tag);
238
+ if (view == null) {
239
+ try {
240
+ view = mUIManager.resolveView(tag);
241
+ mViewForTag.put(tag, view);
242
+ } catch (IllegalViewOperationException ignored) {
243
+ continue;
244
+ }
242
245
  }
246
+ findRoot(view, roots);
243
247
  }
244
- findRoot(view, roots);
245
- }
246
- for (int tag : roots) {
247
- View view = mViewForTag.get(tag);
248
- if (view != null) {
249
- dfs(view, view, mToRemove);
248
+ for (int tag : roots) {
249
+ View view = mViewForTag.get(tag);
250
+ if (view != null) {
251
+ dfs(view, view, mToRemove);
252
+ }
250
253
  }
251
254
  }
252
255
  }
@@ -23,7 +23,11 @@ public class ReanimatedSensor {
23
23
  sensorManager =
24
24
  (SensorManager) reactContext.get().getSystemService(reactContext.get().SENSOR_SERVICE);
25
25
  this.sensorType = sensorType;
26
- this.interval = interval;
26
+ if (interval == -1) {
27
+ this.interval = SensorManager.SENSOR_DELAY_UI;
28
+ } else {
29
+ this.interval = interval;
30
+ }
27
31
  }
28
32
 
29
33
  boolean initialize() {
@@ -3,6 +3,7 @@ package com.swmansion.reanimated.sensor;
3
3
  import android.hardware.Sensor;
4
4
  import android.hardware.SensorEvent;
5
5
  import android.hardware.SensorEventListener;
6
+ import android.hardware.SensorManager;
6
7
  import com.swmansion.reanimated.NativeProxy;
7
8
 
8
9
  public class ReanimatedSensorListener implements SensorEventListener {
@@ -11,6 +12,10 @@ public class ReanimatedSensorListener implements SensorEventListener {
11
12
  private double lastRead = (double) System.currentTimeMillis();
12
13
  private final double interval;
13
14
 
15
+ private float[] rotation = new float[9];
16
+ private float[] orientation = new float[3];
17
+ private float[] quaternion = new float[4];
18
+
14
19
  ReanimatedSensorListener(NativeProxy.SensorSetter setter, double interval) {
15
20
  this.setter = setter;
16
21
  this.interval = interval;
@@ -22,8 +27,26 @@ public class ReanimatedSensorListener implements SensorEventListener {
22
27
  if (current - lastRead < interval) {
23
28
  return;
24
29
  }
30
+ int sensorType = event.sensor.getType();
25
31
  lastRead = current;
26
- setter.sensorSetter(event.values);
32
+ if (sensorType == Sensor.TYPE_ROTATION_VECTOR) {
33
+ SensorManager.getQuaternionFromVector(quaternion, event.values);
34
+ SensorManager.getRotationMatrixFromVector(rotation, event.values);
35
+ SensorManager.getOrientation(rotation, orientation);
36
+ float[] data =
37
+ new float[] {
38
+ quaternion[1], // qx
39
+ quaternion[2], // qy
40
+ quaternion[3], // qz
41
+ quaternion[0], // qw
42
+ orientation[0], // yaw
43
+ orientation[1], // pitch
44
+ orientation[2] // roll
45
+ };
46
+ setter.sensorSetter(data);
47
+ } else {
48
+ setter.sensorSetter(event.values);
49
+ }
27
50
  }
28
51
 
29
52
  @Override
@@ -1,11 +1,13 @@
1
1
  package com.swmansion.reanimated.sensor;
2
2
 
3
+ import android.hardware.Sensor;
4
+
3
5
  public enum ReanimatedSensorType {
4
- ACCELEROMETER(1),
5
- GYROSCOPE(2),
6
- GRAVITY(3),
7
- MAGNETIC_FIELD(4),
8
- ROTATION_VECTOR(5);
6
+ ACCELEROMETER(Sensor.TYPE_LINEAR_ACCELERATION),
7
+ GYROSCOPE(Sensor.TYPE_GYROSCOPE),
8
+ GRAVITY(Sensor.TYPE_GRAVITY),
9
+ MAGNETIC_FIELD(Sensor.TYPE_MAGNETIC_FIELD),
10
+ ROTATION_VECTOR(Sensor.TYPE_ROTATION_VECTOR);
9
11
 
10
12
  private final int type;
11
13
 
@@ -509,9 +509,9 @@
509
509
  _nativeProps = nativePropsSet;
510
510
  }
511
511
 
512
- - (BOOL)isNotNativeViewFullyMounted:(NSNumber *)viewTag
512
+ - (BOOL)isNativeViewMounted:(NSNumber *)viewTag
513
513
  {
514
- return _viewRegistry[viewTag].superview == nil;
514
+ return _viewRegistry[viewTag].superview != nil;
515
515
  }
516
516
 
517
517
  - (void)setValueForNodeID:(nonnull NSNumber *)nodeID value:(nonnull NSNumber *)newValue
@@ -529,7 +529,17 @@
529
529
  withName:(nonnull NSString *)viewName
530
530
  {
531
531
  ComponentUpdate *lastSnapshot = _componentUpdateBuffer[viewTag];
532
- if ([self isNotNativeViewFullyMounted:viewTag] || lastSnapshot != nil) {
532
+ BOOL isNativeViewMounted = [self isNativeViewMounted:viewTag];
533
+
534
+ if (lastSnapshot != nil) {
535
+ NSMutableDictionary *lastProps = lastSnapshot.props;
536
+ for (NSString *key in props) {
537
+ [lastProps setValue:props[key] forKey:key];
538
+ }
539
+ }
540
+
541
+ // If the component isn't mounted, we will bail early with a scheduled update
542
+ if (!isNativeViewMounted) {
533
543
  if (lastSnapshot == nil) {
534
544
  ComponentUpdate *propsSnapshot = [ComponentUpdate new];
535
545
  propsSnapshot.props = [props mutableCopy];
@@ -537,15 +547,28 @@
537
547
  propsSnapshot.viewName = viewName;
538
548
  _componentUpdateBuffer[viewTag] = propsSnapshot;
539
549
  atomic_store(&_shouldFlushUpdateBuffer, true);
540
- } else {
541
- NSMutableDictionary *lastProps = lastSnapshot.props;
542
- for (NSString *key in props) {
543
- [lastProps setValue:props[key] forKey:key];
544
- }
545
550
  }
551
+
546
552
  return;
547
553
  }
548
554
 
555
+ // The component may have been mounted with a pending snapshot (due to a race condition),
556
+ // so we should attempt run the update. Otherwise, the next call to -maybeFlushUpdateBuffer
557
+ // will only arrive when a new component is mounted (which might be never!)
558
+ //
559
+ // If there are 0 remaining items in the buffer, we can skip the run in -maybeFlushUpdateBuffer.
560
+ if (lastSnapshot != nil && isNativeViewMounted) {
561
+ props = lastSnapshot.props;
562
+ viewTag = lastSnapshot.viewTag;
563
+ viewName = lastSnapshot.viewName;
564
+
565
+ [_componentUpdateBuffer removeObjectForKey:viewTag];
566
+
567
+ if (_componentUpdateBuffer.count == 0) {
568
+ atomic_store(&_shouldFlushUpdateBuffer, false);
569
+ }
570
+ }
571
+
549
572
  // TODO: refactor PropsNode to also use this function
550
573
  NSMutableDictionary *uiProps = [NSMutableDictionary new];
551
574
  NSMutableDictionary *nativeProps = [NSMutableDictionary new];
@@ -0,0 +1,17 @@
1
+ #ifndef REAKeyboardEventManager_h
2
+ #define REAKeyboardEventManager_h
3
+
4
+ #import <RNReanimated/REAEventDispatcher.h>
5
+ #import <React/RCTEventDispatcher.h>
6
+
7
+ typedef void (^KeyboardEventListenerBlock)(int keyboardState, int height);
8
+
9
+ @interface REAKeyboardEventObserver : NSObject
10
+
11
+ - (instancetype)init;
12
+ - (int)subscribeForKeyboardEvents:(KeyboardEventListenerBlock)listener;
13
+ - (void)unsubscribeFromKeyboardEvents:(int)listenerId;
14
+
15
+ @end
16
+
17
+ #endif /* REAKeyboardEventManager_h */