react-native-reanimated 2.3.3 → 2.5.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 (249) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +72 -0
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +30 -1
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +64 -39
  4. package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -0
  5. package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
  6. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
  7. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
  8. package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
  9. package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
  10. package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
  11. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
  12. package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
  13. package/LICENSE +1 -1
  14. package/README.md +2 -2
  15. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  16. package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
  17. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  18. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  19. package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
  20. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  21. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  22. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  23. package/android/.gradle/7.2/gc.properties +0 -0
  24. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  25. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  26. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  27. package/android/.gradle/checksums/checksums.lock +0 -0
  28. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  29. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  30. package/android/.gradle/vcs-1/gc.properties +0 -0
  31. package/android/CMakeLists.txt +198 -0
  32. package/android/README.md +15 -0
  33. package/android/build.gradle +686 -73
  34. package/android/empty.cpp +1 -0
  35. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  36. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  37. package/android/gradle.properties +25 -0
  38. package/android/gradlew +234 -0
  39. package/android/gradlew.bat +89 -0
  40. package/android/react-native-reanimated-64-hermes.aar +0 -0
  41. package/android/react-native-reanimated-64-jsc.aar +0 -0
  42. package/android/react-native-reanimated-65-hermes.aar +0 -0
  43. package/android/react-native-reanimated-65-jsc.aar +0 -0
  44. package/android/react-native-reanimated-66-hermes.aar +0 -0
  45. package/android/react-native-reanimated-66-jsc.aar +0 -0
  46. package/android/react-native-reanimated-67-hermes.aar +0 -0
  47. package/android/react-native-reanimated-67-jsc.aar +0 -0
  48. package/android/react-native-reanimated-68-hermes.aar +0 -0
  49. package/android/react-native-reanimated-68-jsc.aar +0 -0
  50. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
  51. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  52. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  53. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  54. package/android/rnVersionPatch/65/.gitkeep +0 -0
  55. package/android/rnVersionPatch/66/.gitkeep +0 -0
  56. package/android/rnVersionPatch/67/.gitkeep +0 -0
  57. package/android/rnVersionPatch/68/.gitkeep +0 -0
  58. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  59. package/android/settings.gradle +1 -0
  60. package/android/spotless.gradle +9 -0
  61. package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
  62. package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
  63. package/android/src/main/cpp/AndroidLogger.cpp +27 -0
  64. package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
  65. package/android/src/main/cpp/JNIHelper.cpp +59 -0
  66. package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
  67. package/android/src/main/cpp/NativeProxy.cpp +327 -0
  68. package/android/src/main/cpp/OnLoad.cpp +17 -0
  69. package/android/src/main/cpp/TurboModule.cpp +44 -0
  70. package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
  71. package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
  72. package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
  73. package/android/src/main/cpp/headers/JNIHelper.h +30 -0
  74. package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
  75. package/android/src/main/cpp/headers/NativeProxy.h +170 -0
  76. package/android/src/main/cpp/headers/TurboModule.h +70 -0
  77. package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
  78. package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
  79. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
  80. package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
  81. package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
  82. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
  83. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
  84. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
  85. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
  86. package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
  87. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
  88. package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
  89. package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
  90. package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
  91. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
  92. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
  93. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
  94. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
  95. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  96. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
  97. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
  98. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
  99. package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
  100. package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
  101. package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
  102. package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
  103. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
  104. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
  105. package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
  106. package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
  107. package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
  108. package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
  109. package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
  110. package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
  111. package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
  112. package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
  113. package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
  114. package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
  115. package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
  116. package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
  117. package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
  118. package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
  119. package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
  120. package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
  121. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
  122. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
  123. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
  124. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
  125. package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
  126. package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
  127. package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
  128. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
  129. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
  130. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  131. package/ios/LayoutReanimation/REAAnimationsManager.m +18 -4
  132. package/ios/REAModule.m +8 -9
  133. package/ios/REANodesManager.h +4 -1
  134. package/ios/REANodesManager.m +75 -3
  135. package/ios/native/NativeMethods.h +1 -1
  136. package/ios/native/NativeProxy.mm +85 -5
  137. package/ios/sensor/ReanimatedSensor.h +21 -0
  138. package/ios/sensor/ReanimatedSensor.m +169 -0
  139. package/ios/sensor/ReanimatedSensorContainer.h +13 -0
  140. package/ios/sensor/ReanimatedSensorContainer.m +41 -0
  141. package/ios/sensor/ReanimatedSensorType.h +7 -0
  142. package/lib/ConfigHelper.js +2 -2
  143. package/lib/createAnimatedComponent.js +3 -4
  144. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  145. package/lib/reanimated1/derived/interpolate.js +2 -4
  146. package/lib/reanimated2/Colors.js +3 -98
  147. package/lib/reanimated2/Easing.js +5 -0
  148. package/lib/reanimated2/NativeMethods.js +15 -5
  149. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
  150. package/lib/reanimated2/NativeReanimated/index.js +2 -6
  151. package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
  152. package/lib/reanimated2/animation/styleAnimation.js +2 -1
  153. package/lib/reanimated2/core.js +30 -24
  154. package/lib/reanimated2/globals.d.ts +6 -0
  155. package/lib/reanimated2/hook/index.js +1 -0
  156. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
  157. package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
  158. package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
  159. package/lib/reanimated2/hook/utils.js +14 -11
  160. package/lib/reanimated2/index.js +2 -0
  161. package/lib/reanimated2/interpolateColor.js +98 -0
  162. package/lib/reanimated2/interpolation.js +1 -1
  163. package/lib/reanimated2/jestUtils.js +9 -4
  164. package/lib/reanimated2/js-reanimated/JSReanimated.js +24 -3
  165. package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
  166. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
  167. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
  168. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
  169. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
  170. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
  171. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
  172. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
  173. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  174. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
  175. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
  176. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
  177. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
  178. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
  179. package/lib/reanimated2/mock.js +3 -2
  180. package/mock.js +6 -4
  181. package/package.json +44 -36
  182. package/plugin.js +3 -0
  183. package/react-native-reanimated.d.ts +102 -15
  184. package/src/ConfigHelper.ts +4 -4
  185. package/src/createAnimatedComponent.tsx +3 -3
  186. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  187. package/src/reanimated1/derived/interpolate.js +2 -4
  188. package/src/reanimated2/Colors.ts +8 -151
  189. package/src/reanimated2/Easing.ts +11 -0
  190. package/src/reanimated2/NativeMethods.ts +19 -6
  191. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -14
  192. package/src/reanimated2/NativeReanimated/index.ts +2 -8
  193. package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
  194. package/src/reanimated2/animation/commonTypes.ts +44 -40
  195. package/src/reanimated2/animation/decay.ts +1 -1
  196. package/src/reanimated2/animation/delay.ts +2 -16
  197. package/src/reanimated2/animation/index.ts +8 -8
  198. package/src/reanimated2/animation/repeat.ts +2 -12
  199. package/src/reanimated2/animation/sequence.ts +3 -10
  200. package/src/reanimated2/animation/spring.ts +1 -1
  201. package/src/reanimated2/animation/styleAnimation.ts +11 -25
  202. package/src/reanimated2/animation/timing.ts +4 -2
  203. package/src/reanimated2/animation/util.ts +22 -20
  204. package/src/reanimated2/commonTypes.ts +68 -1
  205. package/src/reanimated2/component/FlatList.tsx +2 -1
  206. package/src/reanimated2/core.ts +35 -29
  207. package/src/reanimated2/globals.d.ts +6 -0
  208. package/src/reanimated2/hook/commonTypes.ts +5 -0
  209. package/src/reanimated2/hook/index.ts +1 -0
  210. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
  211. package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
  212. package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
  213. package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
  214. package/src/reanimated2/hook/utils.ts +20 -18
  215. package/src/reanimated2/index.ts +2 -0
  216. package/src/reanimated2/interpolateColor.ts +178 -0
  217. package/src/reanimated2/interpolation.ts +2 -6
  218. package/src/reanimated2/jestUtils.ts +9 -4
  219. package/src/reanimated2/js-reanimated/JSReanimated.ts +28 -6
  220. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  221. package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
  222. package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
  223. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
  224. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
  225. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
  226. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
  227. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
  228. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
  229. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
  230. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
  231. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
  232. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
  233. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
  234. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
  235. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
  236. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +32 -21
  237. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
  238. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
  239. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
  240. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
  241. package/src/reanimated2/mock.ts +3 -2
  242. package/src/reanimated2/utils.ts +1 -1
  243. package/android/react-native-reanimated-63-hermes.aar +0 -0
  244. package/android/react-native-reanimated-63-jsc.aar +0 -0
  245. package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
  246. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  247. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  248. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  249. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
@@ -0,0 +1,72 @@
1
+ #include "AnimatedSensorModule.h"
2
+ #include "MutableValue.h"
3
+ #include "ValueWrapper.h"
4
+
5
+ namespace reanimated {
6
+
7
+ AnimatedSensorModule::AnimatedSensorModule(
8
+ const PlatformDepMethodsHolder &platformDepMethodsHolder,
9
+ RuntimeManager *runtimeManager)
10
+ : platformRegisterSensorFunction_(platformDepMethodsHolder.registerSensor),
11
+ platformUnregisterSensorFunction_(
12
+ platformDepMethodsHolder.unregisterSensor),
13
+ runtimeManager_(runtimeManager) {}
14
+
15
+ AnimatedSensorModule::~AnimatedSensorModule() {
16
+ // It is called during app reload because app reload doesn't call hooks
17
+ // unmounting
18
+ for (auto sensorId : sensorsIds_) {
19
+ platformUnregisterSensorFunction_(sensorId);
20
+ }
21
+ }
22
+
23
+ jsi::Value AnimatedSensorModule::registerSensor(
24
+ jsi::Runtime &rt,
25
+ const jsi::Value &sensorType,
26
+ const jsi::Value &interval,
27
+ const jsi::Value &sensorDataContainer) {
28
+ std::shared_ptr<ShareableValue> sensorsData = ShareableValue::adapt(
29
+ rt, sensorDataContainer.getObject(rt), runtimeManager_);
30
+ auto &mutableObject =
31
+ ValueWrapper::asMutableValue(sensorsData->valueContainer);
32
+
33
+ std::function<void(double[])> setter;
34
+ if (sensorType.asNumber() == SensorType::ROTATION_VECTOR) {
35
+ setter = [&, mutableObject](double newValues[]) {
36
+ jsi::Runtime &runtime = *runtimeManager_->runtime.get();
37
+ jsi::Object value(runtime);
38
+ value.setProperty(runtime, "qw", newValues[0]);
39
+ value.setProperty(runtime, "qx", newValues[1]);
40
+ value.setProperty(runtime, "qy", newValues[2]);
41
+ value.setProperty(runtime, "qz", newValues[3]);
42
+ value.setProperty(runtime, "yaw", newValues[4]);
43
+ value.setProperty(runtime, "pitch", newValues[5]);
44
+ value.setProperty(runtime, "roll", newValues[6]);
45
+ mutableObject->setValue(runtime, std::move(value));
46
+ };
47
+ } else {
48
+ setter = [&, mutableObject](double newValues[]) {
49
+ jsi::Runtime &runtime = *runtimeManager_->runtime.get();
50
+ jsi::Object value(runtime);
51
+ value.setProperty(runtime, "x", newValues[0]);
52
+ value.setProperty(runtime, "y", newValues[1]);
53
+ value.setProperty(runtime, "z", newValues[2]);
54
+ mutableObject->setValue(runtime, std::move(value));
55
+ };
56
+ }
57
+
58
+ int sensorId = platformRegisterSensorFunction_(
59
+ sensorType.asNumber(), interval.asNumber(), setter);
60
+ if (sensorId != -1) {
61
+ sensorsIds_.insert(sensorId);
62
+ }
63
+ return jsi::Value(sensorId);
64
+ }
65
+
66
+ void AnimatedSensorModule::unregisterSensor(const jsi::Value &sensorId) {
67
+ // It is called during sensor hook unmounting
68
+ sensorsIds_.erase(sensorId.getNumber());
69
+ platformUnregisterSensorFunction_(sensorId.asNumber());
70
+ }
71
+
72
+ } // namespace reanimated
@@ -8,6 +8,7 @@
8
8
  #include "JSIStoreValueUser.h"
9
9
  #include "Mapper.h"
10
10
  #include "MapperRegistry.h"
11
+ #include "MutableValue.h"
11
12
  #include "ReanimatedHiddenHeaders.h"
12
13
  #include "RuntimeDecorator.h"
13
14
  #include "ShareableValue.h"
@@ -70,7 +71,10 @@ NativeReanimatedModule::NativeReanimatedModule(
70
71
  mapperRegistry(std::make_shared<MapperRegistry>()),
71
72
  eventHandlerRegistry(std::make_shared<EventHandlerRegistry>()),
72
73
  requestRender(platformDepMethodsHolder.requestRender),
73
- propObtainer(propObtainer) {
74
+ propObtainer(propObtainer),
75
+ animatedSensorModule(platformDepMethodsHolder, this),
76
+ configurePropsPlatformFunction(
77
+ platformDepMethodsHolder.configurePropsFunction) {
74
78
  auto requestAnimationFrame = [=](FrameCallback callback) {
75
79
  frameCallbacks.push_back(callback);
76
80
  maybeRequestRender();
@@ -85,6 +89,8 @@ NativeReanimatedModule::NativeReanimatedModule(
85
89
  platformDepMethodsHolder.scrollToFunction,
86
90
  platformDepMethodsHolder.measuringFunction,
87
91
  platformDepMethodsHolder.getCurrentTime,
92
+ platformDepMethodsHolder.registerSensor,
93
+ platformDepMethodsHolder.unregisterSensor,
88
94
  platformDepMethodsHolder.setGestureStateFunction,
89
95
  layoutAnimationsProxy);
90
96
  onRenderCallback = [this](double timestampMs) {
@@ -243,6 +249,14 @@ jsi::Value NativeReanimatedModule::enableLayoutAnimations(
243
249
  return jsi::Value::undefined();
244
250
  }
245
251
 
252
+ jsi::Value NativeReanimatedModule::configureProps(
253
+ jsi::Runtime &rt,
254
+ const jsi::Value &uiProps,
255
+ const jsi::Value &nativeProps) {
256
+ configurePropsPlatformFunction(rt, uiProps, nativeProps);
257
+ return jsi::Value::undefined();
258
+ }
259
+
246
260
  void NativeReanimatedModule::onEvent(
247
261
  std::string eventName,
248
262
  std::string eventAsString) {
@@ -298,4 +312,19 @@ void NativeReanimatedModule::onRender(double timestampMs) {
298
312
  }
299
313
  }
300
314
 
315
+ jsi::Value NativeReanimatedModule::registerSensor(
316
+ jsi::Runtime &rt,
317
+ const jsi::Value &sensorType,
318
+ const jsi::Value &interval,
319
+ const jsi::Value &sensorDataContainer) {
320
+ return animatedSensorModule.registerSensor(
321
+ rt, sensorType, interval, sensorDataContainer);
322
+ }
323
+
324
+ void NativeReanimatedModule::unregisterSensor(
325
+ jsi::Runtime &rt,
326
+ const jsi::Value &sensorId) {
327
+ animatedSensorModule.unregisterSensor(sensorId);
328
+ }
329
+
301
330
  } // namespace reanimated
@@ -1,9 +1,10 @@
1
1
  #include "NativeReanimatedModuleSpec.h"
2
2
 
3
+ #define SPEC_PREFIX(FN_NAME) __hostFunction_NativeReanimatedModuleSpec_##FN_NAME
4
+
3
5
  namespace reanimated {
4
6
 
5
- static jsi::Value
6
- __hostFunction_NativeReanimatedModuleSpec_installCoreFunctions(
7
+ static jsi::Value SPEC_PREFIX(installCoreFunctions)(
7
8
  jsi::Runtime &rt,
8
9
  TurboModule &turboModule,
9
10
  const jsi::Value *args,
@@ -15,7 +16,7 @@ __hostFunction_NativeReanimatedModuleSpec_installCoreFunctions(
15
16
 
16
17
  // SharedValue
17
18
 
18
- static jsi::Value __hostFunction_NativeReanimatedModuleSpec_makeShareable(
19
+ static jsi::Value SPEC_PREFIX(makeShareable)(
19
20
  jsi::Runtime &rt,
20
21
  TurboModule &turboModule,
21
22
  const jsi::Value *args,
@@ -24,7 +25,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_makeShareable(
24
25
  ->makeShareable(rt, std::move(args[0]));
25
26
  }
26
27
 
27
- static jsi::Value __hostFunction_NativeReanimatedModuleSpec_makeMutable(
28
+ static jsi::Value SPEC_PREFIX(makeMutable)(
28
29
  jsi::Runtime &rt,
29
30
  TurboModule &turboModule,
30
31
  const jsi::Value *args,
@@ -33,7 +34,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_makeMutable(
33
34
  ->makeMutable(rt, std::move(args[0]));
34
35
  }
35
36
 
36
- static jsi::Value __hostFunction_NativeReanimatedModuleSpec_makeRemote(
37
+ static jsi::Value SPEC_PREFIX(makeRemote)(
37
38
  jsi::Runtime &rt,
38
39
  TurboModule &turboModule,
39
40
  const jsi::Value *args,
@@ -42,7 +43,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_makeRemote(
42
43
  ->makeRemote(rt, std::move(args[0]));
43
44
  }
44
45
 
45
- static jsi::Value __hostFunction_NativeReanimatedModuleSpec_startMapper(
46
+ static jsi::Value SPEC_PREFIX(startMapper)(
46
47
  jsi::Runtime &rt,
47
48
  TurboModule &turboModule,
48
49
  const jsi::Value *args,
@@ -57,7 +58,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_startMapper(
57
58
  std::move(args[4]));
58
59
  }
59
60
 
60
- static jsi::Value __hostFunction_NativeReanimatedModuleSpec_stopMapper(
61
+ static jsi::Value SPEC_PREFIX(stopMapper)(
61
62
  jsi::Runtime &rt,
62
63
  TurboModule &turboModule,
63
64
  const jsi::Value *args,
@@ -67,8 +68,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_stopMapper(
67
68
  return jsi::Value::undefined();
68
69
  }
69
70
 
70
- static jsi::Value
71
- __hostFunction_NativeReanimatedModuleSpec_registerEventHandler(
71
+ static jsi::Value SPEC_PREFIX(registerEventHandler)(
72
72
  jsi::Runtime &rt,
73
73
  TurboModule &turboModule,
74
74
  const jsi::Value *args,
@@ -77,8 +77,7 @@ __hostFunction_NativeReanimatedModuleSpec_registerEventHandler(
77
77
  ->registerEventHandler(rt, std::move(args[0]), std::move(args[1]));
78
78
  }
79
79
 
80
- static jsi::Value
81
- __hostFunction_NativeReanimatedModuleSpec_unregisterEventHandler(
80
+ static jsi::Value SPEC_PREFIX(unregisterEventHandler)(
82
81
  jsi::Runtime &rt,
83
82
  TurboModule &turboModule,
84
83
  const jsi::Value *args,
@@ -88,7 +87,7 @@ __hostFunction_NativeReanimatedModuleSpec_unregisterEventHandler(
88
87
  return jsi::Value::undefined();
89
88
  }
90
89
 
91
- static jsi::Value __hostFunction_NativeReanimatedModuleSpec_getViewProp(
90
+ static jsi::Value SPEC_PREFIX(getViewProp)(
92
91
  jsi::Runtime &rt,
93
92
  TurboModule &turboModule,
94
93
  const jsi::Value *args,
@@ -99,8 +98,7 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_getViewProp(
99
98
  return jsi::Value::undefined();
100
99
  }
101
100
 
102
- static jsi::Value
103
- __hostFunction_NativeReanimatedModuleSpec_enableLayoutAnimations(
101
+ static jsi::Value SPEC_PREFIX(enableLayoutAnimations)(
104
102
  jsi::Runtime &rt,
105
103
  TurboModule &turboModule,
106
104
  const jsi::Value *args,
@@ -110,33 +108,60 @@ __hostFunction_NativeReanimatedModuleSpec_enableLayoutAnimations(
110
108
  return jsi::Value::undefined();
111
109
  }
112
110
 
111
+ static jsi::Value SPEC_PREFIX(registerSensor)(
112
+ jsi::Runtime &rt,
113
+ TurboModule &turboModule,
114
+ const jsi::Value *args,
115
+ size_t count) {
116
+ return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
117
+ ->registerSensor(
118
+ rt, std::move(args[0]), std::move(args[1]), std::move(args[2]));
119
+ }
120
+
121
+ static jsi::Value SPEC_PREFIX(unregisterSensor)(
122
+ jsi::Runtime &rt,
123
+ TurboModule &turboModule,
124
+ const jsi::Value *args,
125
+ size_t count) {
126
+ static_cast<NativeReanimatedModuleSpec *>(&turboModule)
127
+ ->unregisterSensor(rt, std::move(args[0]));
128
+ return jsi::Value::undefined();
129
+ }
130
+
131
+ static jsi::Value SPEC_PREFIX(configureProps)(
132
+ jsi::Runtime &rt,
133
+ TurboModule &turboModule,
134
+ const jsi::Value *args,
135
+ size_t count) {
136
+ static_cast<NativeReanimatedModuleSpec *>(&turboModule)
137
+ ->configureProps(rt, std::move(args[0]), std::move(args[1]));
138
+ return jsi::Value::undefined();
139
+ }
140
+
113
141
  NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
114
142
  std::shared_ptr<CallInvoker> jsInvoker)
115
143
  : TurboModule("NativeReanimated", jsInvoker) {
116
- methodMap_["installCoreFunctions"] = MethodMetadata{
117
- 1, __hostFunction_NativeReanimatedModuleSpec_installCoreFunctions};
118
-
119
- methodMap_["makeShareable"] = MethodMetadata{
120
- 1, __hostFunction_NativeReanimatedModuleSpec_makeShareable};
121
- methodMap_["makeMutable"] =
122
- MethodMetadata{1, __hostFunction_NativeReanimatedModuleSpec_makeMutable};
123
- methodMap_["makeRemote"] =
124
- MethodMetadata{1, __hostFunction_NativeReanimatedModuleSpec_makeRemote};
125
-
126
- methodMap_["startMapper"] =
127
- MethodMetadata{5, __hostFunction_NativeReanimatedModuleSpec_startMapper};
128
- methodMap_["stopMapper"] =
129
- MethodMetadata{1, __hostFunction_NativeReanimatedModuleSpec_stopMapper};
130
-
131
- methodMap_["registerEventHandler"] = MethodMetadata{
132
- 2, __hostFunction_NativeReanimatedModuleSpec_registerEventHandler};
133
- methodMap_["unregisterEventHandler"] = MethodMetadata{
134
- 1, __hostFunction_NativeReanimatedModuleSpec_unregisterEventHandler};
135
-
136
- methodMap_["getViewProp"] =
137
- MethodMetadata{3, __hostFunction_NativeReanimatedModuleSpec_getViewProp};
138
- methodMap_["enableLayoutAnimations"] = MethodMetadata{
139
- 2, __hostFunction_NativeReanimatedModuleSpec_enableLayoutAnimations};
144
+ methodMap_["installCoreFunctions"] =
145
+ MethodMetadata{1, SPEC_PREFIX(installCoreFunctions)};
146
+
147
+ methodMap_["makeShareable"] = MethodMetadata{1, SPEC_PREFIX(makeShareable)};
148
+ methodMap_["makeMutable"] = MethodMetadata{1, SPEC_PREFIX(makeMutable)};
149
+ methodMap_["makeRemote"] = MethodMetadata{1, SPEC_PREFIX(makeRemote)};
150
+
151
+ methodMap_["startMapper"] = MethodMetadata{5, SPEC_PREFIX(startMapper)};
152
+ methodMap_["stopMapper"] = MethodMetadata{1, SPEC_PREFIX(stopMapper)};
153
+
154
+ methodMap_["registerEventHandler"] =
155
+ MethodMetadata{2, SPEC_PREFIX(registerEventHandler)};
156
+ methodMap_["unregisterEventHandler"] =
157
+ MethodMetadata{1, SPEC_PREFIX(unregisterEventHandler)};
158
+
159
+ methodMap_["getViewProp"] = MethodMetadata{3, SPEC_PREFIX(getViewProp)};
160
+ methodMap_["enableLayoutAnimations"] =
161
+ MethodMetadata{2, SPEC_PREFIX(enableLayoutAnimations)};
162
+ methodMap_["registerSensor"] = MethodMetadata{3, SPEC_PREFIX(registerSensor)};
163
+ methodMap_["unregisterSensor"] =
164
+ MethodMetadata{1, SPEC_PREFIX(unregisterSensor)};
165
+ methodMap_["configureProps"] = MethodMetadata{2, SPEC_PREFIX(configureProps)};
140
166
  }
141
-
142
167
  } // namespace reanimated
@@ -109,6 +109,8 @@ void RuntimeDecorator::decorateUIRuntime(
109
109
  const ScrollToFunction scrollTo,
110
110
  const MeasuringFunction measure,
111
111
  const TimeProviderFunction getCurrentTime,
112
+ const RegisterSensorFunction registerSensor,
113
+ const UnregisterSensorFunction unregisterSensor,
112
114
  const SetGestureStateFunction setGestureState,
113
115
  std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy) {
114
116
  RuntimeDecorator::decorateRuntime(rt, "UI");
@@ -0,0 +1,41 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <unordered_set>
5
+
6
+ #include "PlatformDepMethodsHolder.h"
7
+ #include "RuntimeManager.h"
8
+
9
+ namespace reanimated {
10
+
11
+ using namespace facebook;
12
+
13
+ enum SensorType {
14
+ ACCELEROMETER = 1,
15
+ GYROSCOPE = 2,
16
+ GRAVITY = 3,
17
+ MAGNETIC_FIELD = 4,
18
+ ROTATION_VECTOR = 5,
19
+ };
20
+
21
+ class AnimatedSensorModule {
22
+ std::unordered_set<int> sensorsIds_;
23
+ RegisterSensorFunction platformRegisterSensorFunction_;
24
+ UnregisterSensorFunction platformUnregisterSensorFunction_;
25
+ RuntimeManager *runtimeManager_;
26
+
27
+ public:
28
+ AnimatedSensorModule(
29
+ const PlatformDepMethodsHolder &platformDepMethodsHolder,
30
+ RuntimeManager *runtimeManager);
31
+ ~AnimatedSensorModule();
32
+
33
+ jsi::Value registerSensor(
34
+ jsi::Runtime &rt,
35
+ const jsi::Value &sensorType,
36
+ const jsi::Value &interval,
37
+ const jsi::Value &sensorDataContainer);
38
+ void unregisterSensor(const jsi::Value &sensorId);
39
+ };
40
+
41
+ } // namespace reanimated
@@ -5,6 +5,7 @@
5
5
  #include <string>
6
6
  #include <vector>
7
7
 
8
+ #include "AnimatedSensorModule.h"
8
9
  #include "ErrorHandler.h"
9
10
  #include "LayoutAnimationsProxy.h"
10
11
  #include "NativeReanimatedModuleSpec.h"
@@ -70,6 +71,10 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
70
71
 
71
72
  jsi::Value enableLayoutAnimations(jsi::Runtime &rt, const jsi::Value &config)
72
73
  override;
74
+ jsi::Value configureProps(
75
+ jsi::Runtime &rt,
76
+ const jsi::Value &uiProps,
77
+ const jsi::Value &nativeProps) override;
73
78
 
74
79
  void onRender(double timestampMs);
75
80
  void onEvent(std::string eventName, std::string eventAsString);
@@ -78,6 +83,13 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
78
83
  void maybeRequestRender();
79
84
  UpdaterFunction updaterFunction;
80
85
 
86
+ jsi::Value registerSensor(
87
+ jsi::Runtime &rt,
88
+ const jsi::Value &sensorType,
89
+ const jsi::Value &interval,
90
+ const jsi::Value &sensorDataContainer) override;
91
+ void unregisterSensor(jsi::Runtime &rt, const jsi::Value &sensorId) override;
92
+
81
93
  private:
82
94
  std::shared_ptr<MapperRegistry> mapperRegistry;
83
95
  std::shared_ptr<EventHandlerRegistry> eventHandlerRegistry;
@@ -89,6 +101,8 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
89
101
  propObtainer;
90
102
  std::function<void(double)> onRenderCallback;
91
103
  std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy;
104
+ AnimatedSensorModule animatedSensorModule;
105
+ ConfigurePropsFunction configurePropsPlatformFunction;
92
106
  };
93
107
 
94
108
  } // namespace reanimated
@@ -59,10 +59,24 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
59
59
  const jsi::Value &propName,
60
60
  const jsi::Value &callback) = 0;
61
61
 
62
+ // sensors
63
+ virtual jsi::Value registerSensor(
64
+ jsi::Runtime &rt,
65
+ const jsi::Value &sensorType,
66
+ const jsi::Value &interval,
67
+ const jsi::Value &sensorDataContainer) = 0;
68
+ virtual void unregisterSensor(
69
+ jsi::Runtime &rt,
70
+ const jsi::Value &sensorId) = 0;
71
+
62
72
  // other
63
73
  virtual jsi::Value enableLayoutAnimations(
64
74
  jsi::Runtime &rt,
65
75
  const jsi::Value &config) = 0;
76
+ virtual jsi::Value configureProps(
77
+ jsi::Runtime &rt,
78
+ const jsi::Value &uiProps,
79
+ const jsi::Value &nativeProps) = 0;
66
80
  };
67
81
 
68
82
  } // namespace reanimated
@@ -20,13 +20,16 @@ class MutableValue : public jsi::HostObject,
20
20
  public StoreUser {
21
21
  private:
22
22
  friend MutableValueSetterProxy;
23
- RuntimeManager *runtimeManager;
24
23
  friend LayoutAnimationsProxy;
24
+
25
+ private:
26
+ RuntimeManager *runtimeManager;
25
27
  std::mutex readWriteMutex;
26
28
  std::shared_ptr<ShareableValue> value;
27
29
  std::weak_ptr<jsi::Value> animation;
28
30
  std::map<unsigned long, std::function<void()>> listeners;
29
31
 
32
+ public:
30
33
  void setValue(jsi::Runtime &rt, const jsi::Value &newValue);
31
34
  jsi::Value getValue(jsi::Runtime &rt);
32
35
 
@@ -6,6 +6,7 @@
6
6
  #include <string>
7
7
  #include <unordered_map>
8
8
  #include <vector>
9
+ #include "AnimatedSensorModule.h"
9
10
  #include "HostFunctionHandler.h"
10
11
  #include "JSIStoreValueUser.h"
11
12
  #include "LayoutAnimationsProxy.h"
@@ -24,6 +25,8 @@ class ShareableValue : public std::enable_shared_from_this<ShareableValue>,
24
25
  friend WorkletsCache;
25
26
  friend FrozenObject;
26
27
  friend LayoutAnimationsProxy;
28
+ friend NativeReanimatedModule;
29
+ friend AnimatedSensorModule;
27
30
  friend void extractMutables(
28
31
  jsi::Runtime &rt,
29
32
  std::shared_ptr<ShareableValue> sv,
@@ -12,8 +12,11 @@
12
12
  namespace reanimated {
13
13
 
14
14
  class HostFunctionWrapper;
15
+ class AnimatedSensorModule;
15
16
 
16
17
  class ValueWrapper {
18
+ friend AnimatedSensorModule;
19
+
17
20
  public:
18
21
  ValueWrapper() {}
19
22
  explicit ValueWrapper(ValueType _type) : type(_type) {}
@@ -21,7 +21,15 @@ using ScrollToFunction = std::function<void(int, double, double, bool)>;
21
21
  using MeasuringFunction =
22
22
  std::function<std::vector<std::pair<std::string, double>>(int)>;
23
23
  using TimeProviderFunction = std::function<double(void)>;
24
+
25
+ using RegisterSensorFunction =
26
+ std::function<int(int, int, std::function<void(double[])>)>;
27
+ using UnregisterSensorFunction = std::function<void(int)>;
24
28
  using SetGestureStateFunction = std::function<void(int, int)>;
29
+ using ConfigurePropsFunction = std::function<void(
30
+ jsi::Runtime &rt,
31
+ const jsi::Value &uiProps,
32
+ const jsi::Value &nativeProps)>;
25
33
 
26
34
  struct PlatformDepMethodsHolder {
27
35
  RequestRender requestRender;
@@ -29,7 +37,10 @@ struct PlatformDepMethodsHolder {
29
37
  ScrollToFunction scrollToFunction;
30
38
  MeasuringFunction measuringFunction;
31
39
  TimeProviderFunction getCurrentTime;
40
+ RegisterSensorFunction registerSensor;
41
+ UnregisterSensorFunction unregisterSensor;
32
42
  SetGestureStateFunction setGestureStateFunction;
43
+ ConfigurePropsFunction configurePropsFunction;
33
44
  };
34
45
 
35
46
  } // namespace reanimated
@@ -36,6 +36,8 @@ class RuntimeDecorator {
36
36
  const ScrollToFunction scrollTo,
37
37
  const MeasuringFunction measure,
38
38
  const TimeProviderFunction getCurrentTime,
39
+ const RegisterSensorFunction registerSensor,
40
+ const UnregisterSensorFunction unregisterSensor,
39
41
  const SetGestureStateFunction setGestureState,
40
42
  std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy);
41
43
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Krzysztof Magiera
3
+ Copyright (c) 2016 Software Mansion <swmansion.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -11,7 +11,7 @@ comes to gesture based interactions.
11
11
 
12
12
  ## Installation
13
13
 
14
- Check out [installation](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation) section of our docs for the detailed installation instructions.
14
+ Check out the [installation](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation) section of our docs for the detailed installation instructions.
15
15
 
16
16
  ## Documentation
17
17
 
@@ -28,7 +28,7 @@ Reanimated library is licensed under [The MIT License](LICENSE).
28
28
 
29
29
  ## Credits
30
30
 
31
- This project has been build and is maintained thanks to the support from [Shopify](https://shopify.com), [Expo.io](https://expo.io) and [Software Mansion](https://swmansion.com)
31
+ This project has been built and is maintained thanks to the support from [Shopify](https://shopify.com), [Expo.io](https://expo.io) and [Software Mansion](https://swmansion.com)
32
32
 
33
33
  [![shopify](https://avatars1.githubusercontent.com/u/8085?v=3&s=100 'Shopify.com')](https://shopify.com)
34
34
  [![expo](https://avatars2.githubusercontent.com/u/12504344?v=3&s=100 'Expo.io')](https://expo.io)
File without changes
@@ -0,0 +1,2 @@
1
+ #Mon Mar 21 07:47:31 UTC 2022
2
+ gradle.version=7.2
File without changes