react-native-reanimated 2.6.0 → 2.9.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 (164) hide show
  1. package/Common/cpp/SharedItems/ShareableValue.cpp +2 -2
  2. package/Common/cpp/Tools/RuntimeDecorator.cpp +17 -25
  3. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  4. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  5. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  6. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  7. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  8. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  9. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  10. package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
  11. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  12. package/android/.gradle/checksums/checksums.lock +0 -0
  13. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  14. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  15. package/android/CMakeLists.txt +19 -8
  16. package/android/build.gradle +22 -8
  17. package/android/react-native-reanimated-65-hermes.aar +0 -0
  18. package/android/react-native-reanimated-65-jsc.aar +0 -0
  19. package/android/react-native-reanimated-66-hermes.aar +0 -0
  20. package/android/react-native-reanimated-66-jsc.aar +0 -0
  21. package/android/react-native-reanimated-67-hermes.aar +0 -0
  22. package/android/react-native-reanimated-67-jsc.aar +0 -0
  23. package/android/react-native-reanimated-68-hermes.aar +0 -0
  24. package/android/react-native-reanimated-68-jsc.aar +0 -0
  25. package/android/react-native-reanimated-69-hermes.aar +0 -0
  26. package/android/react-native-reanimated-69-jsc.aar +0 -0
  27. package/android/rnVersionPatch/69/.gitkeep +0 -0
  28. package/android/src/main/cpp/NativeProxy.cpp +35 -14
  29. package/android/src/main/cpp/headers/NativeProxy.h +2 -0
  30. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +11 -8
  31. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +13 -6
  32. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +24 -1
  33. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +7 -5
  34. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  35. package/ios/LayoutReanimation/REAAnimationsManager.m +2 -2
  36. package/ios/LayoutReanimation/REASnapshot.m +1 -1
  37. package/ios/LayoutReanimation/REAUIManager.h +1 -1
  38. package/ios/LayoutReanimation/REAUIManager.mm +4 -5
  39. package/ios/Nodes/REAAlwaysNode.h +1 -1
  40. package/ios/Nodes/REAAlwaysNode.m +5 -5
  41. package/ios/Nodes/REABezierNode.h +1 -1
  42. package/ios/Nodes/REABezierNode.m +4 -5
  43. package/ios/Nodes/REABlockNode.h +1 -1
  44. package/ios/Nodes/REABlockNode.m +2 -2
  45. package/ios/Nodes/REACallFuncNode.h +1 -1
  46. package/ios/Nodes/REACallFuncNode.m +5 -5
  47. package/ios/Nodes/REAClockNodes.h +1 -1
  48. package/ios/Nodes/REAClockNodes.m +4 -4
  49. package/ios/Nodes/REAConcatNode.h +1 -1
  50. package/ios/Nodes/REAConcatNode.m +3 -3
  51. package/ios/Nodes/REACondNode.h +1 -1
  52. package/ios/Nodes/REACondNode.m +3 -3
  53. package/ios/Nodes/READebugNode.h +1 -1
  54. package/ios/Nodes/READebugNode.m +3 -3
  55. package/ios/Nodes/REAEventNode.h +1 -2
  56. package/ios/Nodes/REAEventNode.m +3 -3
  57. package/ios/Nodes/REAFunctionNode.h +1 -1
  58. package/ios/Nodes/REAFunctionNode.m +3 -3
  59. package/ios/Nodes/REAJSCallNode.h +1 -1
  60. package/ios/Nodes/REAJSCallNode.m +3 -3
  61. package/ios/Nodes/REANode.m +2 -2
  62. package/ios/Nodes/REAOperatorNode.h +1 -1
  63. package/ios/Nodes/REAOperatorNode.m +2 -3
  64. package/ios/Nodes/REAParamNode.h +1 -1
  65. package/ios/Nodes/REAParamNode.m +4 -4
  66. package/ios/Nodes/REAPropsNode.h +1 -1
  67. package/ios/Nodes/REAPropsNode.m +4 -6
  68. package/ios/Nodes/REASetNode.h +1 -1
  69. package/ios/Nodes/REASetNode.m +4 -4
  70. package/ios/Nodes/REAStyleNode.h +1 -1
  71. package/ios/Nodes/REAStyleNode.m +2 -3
  72. package/ios/Nodes/REATransformNode.h +1 -1
  73. package/ios/Nodes/REATransformNode.m +2 -2
  74. package/ios/Nodes/REAValueNode.h +1 -3
  75. package/ios/Nodes/REAValueNode.m +1 -1
  76. package/ios/REAEventDispatcher.m +1 -1
  77. package/ios/REAModule.h +1 -1
  78. package/ios/REAModule.m +4 -5
  79. package/ios/REANodesManager.h +1 -2
  80. package/ios/REANodesManager.m +21 -23
  81. package/ios/Transitioning/RCTConvert+REATransition.h +1 -2
  82. package/ios/Transitioning/RCTConvert+REATransition.m +1 -1
  83. package/ios/Transitioning/REAAllTransitions.h +1 -1
  84. package/ios/Transitioning/REAAllTransitions.m +2 -3
  85. package/ios/Transitioning/REATransition.h +2 -3
  86. package/ios/Transitioning/REATransition.m +3 -4
  87. package/ios/Transitioning/REATransitionAnimation.m +1 -2
  88. package/ios/Transitioning/REATransitionManager.m +2 -4
  89. package/ios/Transitioning/REATransitionValues.m +2 -3
  90. package/ios/native/NativeMethods.h +1 -3
  91. package/ios/native/NativeMethods.mm +1 -1
  92. package/ios/native/NativeProxy.h +2 -2
  93. package/ios/native/NativeProxy.mm +20 -17
  94. package/ios/native/REAIOSErrorHandler.h +2 -4
  95. package/ios/native/REAIOSErrorHandler.mm +1 -1
  96. package/ios/native/REAIOSLogger.h +1 -3
  97. package/ios/native/REAIOSLogger.mm +1 -1
  98. package/ios/native/REAIOSScheduler.h +1 -3
  99. package/ios/native/REAIOSScheduler.mm +2 -2
  100. package/ios/native/REAInitializer.h +0 -7
  101. package/ios/native/REAInitializer.mm +13 -3
  102. package/ios/native/UIResponder+Reanimated.mm +3 -3
  103. package/ios/sensor/ReanimatedSensor.h +1 -1
  104. package/ios/sensor/ReanimatedSensor.m +3 -3
  105. package/ios/sensor/ReanimatedSensorContainer.h +1 -1
  106. package/ios/sensor/ReanimatedSensorContainer.m +2 -2
  107. package/lib/Animated.js +8 -30
  108. package/lib/ConfigHelper.js +0 -1
  109. package/lib/index.js +5 -30
  110. package/lib/reanimated2/Easing.js +9 -3
  111. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +1 -1
  112. package/lib/reanimated2/animation/sequence.js +0 -3
  113. package/lib/reanimated2/component/FlatList.js +3 -3
  114. package/lib/reanimated2/component/Image.js +4 -0
  115. package/lib/reanimated2/component/ScrollView.js +4 -0
  116. package/lib/reanimated2/component/Text.js +4 -0
  117. package/lib/reanimated2/component/View.js +4 -0
  118. package/lib/reanimated2/core.js +0 -41
  119. package/lib/reanimated2/globals.d.ts +1 -2
  120. package/lib/reanimated2/hook/utils.js +0 -5
  121. package/lib/reanimated2/js-reanimated/global.js +25 -0
  122. package/lib/reanimated2/js-reanimated/index.js +0 -24
  123. package/lib/reanimated2/mock.js +6 -0
  124. package/lib/types/lib/Animated.d.ts +8 -0
  125. package/lib/types/lib/index.d.ts +4 -0
  126. package/lib/types/lib/reanimated2/commonTypes.d.ts +0 -1
  127. package/lib/types/lib/reanimated2/component/Image.d.ts +3 -0
  128. package/lib/types/lib/reanimated2/component/ScrollView.d.ts +3 -0
  129. package/lib/types/lib/reanimated2/component/Text.d.ts +3 -0
  130. package/lib/types/lib/reanimated2/component/View.d.ts +3 -0
  131. package/lib/types/lib/reanimated2/hook/useAnimatedSensor.d.ts +1 -3
  132. package/lib/types/lib/reanimated2/js-reanimated/global.d.ts +1 -0
  133. package/lib/types/lib/reanimated2/mock.d.ts +6 -0
  134. package/package.json +18 -14
  135. package/plugin.js +36 -33
  136. package/react-native-reanimated.d.ts +16 -7
  137. package/src/Animated.ts +13 -0
  138. package/src/ConfigHelper.ts +0 -1
  139. package/src/index.ts +7 -0
  140. package/src/reanimated2/Easing.ts +9 -3
  141. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +1 -1
  142. package/src/reanimated2/animation/sequence.ts +0 -5
  143. package/src/reanimated2/commonTypes.ts +0 -1
  144. package/src/reanimated2/component/FlatList.tsx +3 -6
  145. package/src/reanimated2/component/Image.ts +6 -0
  146. package/src/reanimated2/component/ScrollView.ts +6 -0
  147. package/src/reanimated2/component/Text.ts +6 -0
  148. package/src/reanimated2/component/View.ts +6 -0
  149. package/src/reanimated2/core.ts +0 -52
  150. package/src/reanimated2/globals.d.ts +1 -2
  151. package/src/reanimated2/hook/useAnimatedSensor.ts +1 -3
  152. package/src/reanimated2/hook/utils.ts +0 -6
  153. package/src/reanimated2/js-reanimated/global.ts +33 -0
  154. package/src/reanimated2/js-reanimated/index.ts +0 -31
  155. package/src/reanimated2/mock.ts +6 -0
  156. package/android/react-native-reanimated-64-hermes.aar +0 -0
  157. package/android/react-native-reanimated-64-jsc.aar +0 -0
  158. package/lib/reanimated2/component/WrappedComponents.js +0 -9
  159. package/lib/reanimated2/component/index.js +0 -4
  160. package/lib/types/lib/reanimated2/component/WrappedComponents.d.ts +0 -8
  161. package/lib/types/lib/reanimated2/component/index.d.ts +0 -9
  162. package/src/Animated.js +0 -31
  163. package/src/reanimated2/component/WrappedComponents.ts +0 -11
  164. package/src/reanimated2/component/index.ts +0 -9
@@ -64,7 +64,7 @@ void ShareableValue::adapt(
64
64
  jsi::Object hiddenProperty = hiddenValue.asObject(rt);
65
65
  if (hiddenProperty.isHostObject<FrozenObject>(rt)) {
66
66
  type = ValueType::FrozenObjectType;
67
- if (object.hasProperty(rt, "__worklet") && object.isFunction(rt)) {
67
+ if (object.hasProperty(rt, "__workletHash") && object.isFunction(rt)) {
68
68
  type = ValueType::WorkletFunctionType;
69
69
  }
70
70
  valueContainer = std::make_unique<FrozenObjectWrapper>(
@@ -99,7 +99,7 @@ void ShareableValue::adapt(
99
99
  } else if (value.isObject()) {
100
100
  auto object = value.asObject(rt);
101
101
  if (object.isFunction(rt)) {
102
- if (object.getProperty(rt, "__worklet").isUndefined()) {
102
+ if (object.getProperty(rt, "__workletHash").isUndefined()) {
103
103
  // not a worklet, we treat this as a host function
104
104
  type = ValueType::HostFunctionType;
105
105
  containsHostFunction = true;
@@ -31,20 +31,6 @@ void RuntimeDecorator::decorateRuntime(
31
31
  rt, "_LABEL", jsi::String::createFromAscii(rt, label));
32
32
 
33
33
  jsi::Object dummyGlobal(rt);
34
- auto dummyFunction = [](jsi::Runtime &rt,
35
- const jsi::Value &thisValue,
36
- const jsi::Value *args,
37
- size_t count) -> jsi::Value {
38
- return jsi::Value::undefined();
39
- };
40
- jsi::Function __reanimatedWorkletInit = jsi::Function::createFromHostFunction(
41
- rt,
42
- jsi::PropNameID::forAscii(rt, "__reanimatedWorkletInit"),
43
- 1,
44
- dummyFunction);
45
-
46
- dummyGlobal.setProperty(
47
- rt, "__reanimatedWorkletInit", __reanimatedWorkletInit);
48
34
  rt.global().setProperty(rt, "global", dummyGlobal);
49
35
 
50
36
  rt.global().setProperty(rt, "jsThis", jsi::Value::undefined());
@@ -85,21 +71,27 @@ void RuntimeDecorator::decorateRuntime(
85
71
  1,
86
72
  setGlobalConsole));
87
73
 
74
+ auto chronoNow = [](jsi::Runtime &rt,
75
+ const jsi::Value &thisValue,
76
+ const jsi::Value *args,
77
+ size_t count) -> jsi::Value {
78
+ double now = std::chrono::system_clock::now().time_since_epoch() /
79
+ std::chrono::milliseconds(1);
80
+ return jsi::Value(now);
81
+ };
82
+
88
83
  rt.global().setProperty(
89
84
  rt,
90
85
  "_chronoNow",
91
86
  jsi::Function::createFromHostFunction(
92
- rt,
93
- jsi::PropNameID::forAscii(rt, "_chronoNow"),
94
- 0,
95
- [](jsi::Runtime &rt,
96
- const jsi::Value &thisValue,
97
- const jsi::Value *args,
98
- size_t count) -> jsi::Value {
99
- double now = std::chrono::system_clock::now().time_since_epoch() /
100
- std::chrono::milliseconds(1);
101
- return jsi::Value(now);
102
- }));
87
+ rt, jsi::PropNameID::forAscii(rt, "_chronoNow"), 0, chronoNow));
88
+ jsi::Object performance(rt);
89
+ performance.setProperty(
90
+ rt,
91
+ "now",
92
+ jsi::Function::createFromHostFunction(
93
+ rt, jsi::PropNameID::forAscii(rt, "now"), 0, chronoNow));
94
+ rt.global().setProperty(rt, "performance", performance);
103
95
  }
104
96
 
105
97
  void RuntimeDecorator::decorateUIRuntime(
@@ -1,2 +1,2 @@
1
- #Mon Apr 04 19:58:22 UTC 2022
1
+ #Thu Jun 30 13:53:38 UTC 2022
2
2
  gradle.version=7.2
@@ -119,12 +119,23 @@ find_library(
119
119
  PATHS ${LIBRN_DIR}
120
120
  NO_CMAKE_FIND_ROOT_PATH
121
121
  )
122
- find_library(
123
- FOLLY_JSON_LIB
124
- folly_json
125
- PATHS ${LIBRN_DIR}
126
- NO_CMAKE_FIND_ROOT_PATH
127
- )
122
+
123
+ if(${REACT_NATIVE_TARGET_VERSION} LESS 69)
124
+ find_library(
125
+ FOLLY_LIB
126
+ folly_json
127
+ PATHS ${LIBRN_DIR}
128
+ NO_CMAKE_FIND_ROOT_PATH
129
+ )
130
+ else()
131
+ find_library(
132
+ FOLLY_LIB
133
+ folly_runtime
134
+ PATHS ${LIBRN_DIR}
135
+ NO_CMAKE_FIND_ROOT_PATH
136
+ )
137
+ endif()
138
+
128
139
  find_library(
129
140
  REACT_NATIVE_JNI_LIB
130
141
  reactnativejni
@@ -169,7 +180,7 @@ if(${FOR_HERMES})
169
180
  ${HERMES_LIB}
170
181
  ${GLOG_LIB}
171
182
  ${FBJNI_LIB}
172
- ${FOLLY_JSON_LIB}
183
+ ${FOLLY_LIB}
173
184
  ${REACT_NATIVE_JNI_LIB}
174
185
  android
175
186
  )
@@ -181,7 +192,7 @@ else()
181
192
  ${JSEXECUTOR_LIB}
182
193
  ${GLOG_LIB}
183
194
  ${FBJNI_LIB}
184
- ${FOLLY_JSON_LIB}
195
+ ${FOLLY_LIB}
185
196
  ${REACT_NATIVE_JNI_LIB}
186
197
  android
187
198
  )
@@ -149,10 +149,10 @@ def detectAAR(minor, engine) {
149
149
  println "\n\n\n"
150
150
  println "****************************************************************************************"
151
151
  println "\n\n\n"
152
- println "WARNING reanimated - no version-specific reanimated AAR for react-native version $rnMinorVersion found."
152
+ println "WARNING reanimated - no version-specific reanimated AAR for react-native version $minor found."
153
153
  println "Falling back to AAR for react-native version $rnMinorVersionCopy."
154
154
  println "The react-native JSI interface is not ABI-safe yet, this may result in crashes."
155
- println "Please post a pull request to implement support for react-native version $rnMinorVersion to the reanimated repo."
155
+ println "Please post a pull request to implement support for react-native version $minor to the reanimated repo."
156
156
  println "Thanks!"
157
157
  println "\n\n\n"
158
158
  println "****************************************************************************************"
@@ -351,8 +351,8 @@ buildscript {
351
351
  }
352
352
  }
353
353
  dependencies {
354
- classpath "com.android.tools.build:gradle:4.2.2"
355
- classpath "de.undercouch:gradle-download-task:4.1.2"
354
+ classpath "com.android.tools.build:gradle:7.1.1"
355
+ classpath "de.undercouch:gradle-download-task:5.0.1"
356
356
  classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
357
357
  }
358
358
  }
@@ -381,8 +381,7 @@ android {
381
381
  "-DBOOST_VERSION=${BOOST_VERSION}",
382
382
  "-DBUILD_DIR=${buildDir}",
383
383
  "-DFOR_HERMES=${FOR_HERMES}",
384
- "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
385
- "--clean-first"
384
+ "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}"
386
385
  abiFilters (*reactNativeArchitectures())
387
386
  _stackProtectorFlag ? (cppFlags("-fstack-protector-all")) : null
388
387
  }
@@ -459,7 +458,12 @@ task createNativeDepsDirectories(dependsOn: applyJavaPatches) {
459
458
  }
460
459
 
461
460
  task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
462
- src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
461
+ def transformedVersion = BOOST_VERSION.replace("_", ".")
462
+ def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
463
+ if (rnMinorVersion < 69) {
464
+ srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
465
+ }
466
+ src(srcUrl)
463
467
  onlyIfNewer(true)
464
468
  overwrite(false)
465
469
  dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
@@ -672,7 +676,17 @@ dependencies {
672
676
  extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers")
673
677
  extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)
674
678
 
675
- def rnAAR = fileTree("$reactNative/android").matching({ it.include "**/**/*.aar" }).singleFile
679
+ def buildType = "debug"
680
+ tasks.all({ task ->
681
+ if (task.name == "buildCMakeRelease") {
682
+ buildType = "release"
683
+ }
684
+ })
685
+ def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
686
+ if (rnMinorVersion < 69) {
687
+ rnAarMatcher = "**/**/*.aar"
688
+ }
689
+ def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
676
690
  def jscAAR = fileTree("$reactNative/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
677
691
  extractSO(files(rnAAR, jscAAR))
678
692
  }
File without changes
@@ -37,6 +37,13 @@ NativeProxy::NativeProxy(
37
37
  scheduler_(scheduler),
38
38
  layoutAnimations(std::move(_layoutAnimations)) {}
39
39
 
40
+ NativeProxy::~NativeProxy() {
41
+ runtime_->global().setProperty(
42
+ *runtime_,
43
+ jsi::PropNameID::forAscii(*runtime_, "__reanimatedModuleProxy"),
44
+ jsi::Value::undefined());
45
+ }
46
+
40
47
  jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybrid(
41
48
  jni::alias_ref<jhybridobject> jThis,
42
49
  jlong jsContext,
@@ -138,11 +145,22 @@ void NativeProxy::installJSIBindings() {
138
145
  std::shared_ptr<jsi::Runtime> animatedRuntime =
139
146
  facebook::jsc::makeJSCRuntime();
140
147
  #endif
148
+ auto workletRuntimeValue = runtime_->global()
149
+ .getProperty(*runtime_, "ArrayBuffer")
150
+ .asObject(*runtime_)
151
+ .asFunction(*runtime_)
152
+ .callAsConstructor(*runtime_, {static_cast<double>(sizeof(void*))});
153
+ uintptr_t* workletRuntimeData = reinterpret_cast<uintptr_t*>(
154
+ workletRuntimeValue
155
+ .getObject(*runtime_)
156
+ .getArrayBuffer(*runtime_)
157
+ .data(*runtime_));
158
+ workletRuntimeData[0] = reinterpret_cast<uintptr_t>(animatedRuntime.get());
159
+
141
160
  runtime_->global().setProperty(
142
161
  *runtime_,
143
162
  "_WORKLET_RUNTIME",
144
- static_cast<double>(
145
- reinterpret_cast<std::uintptr_t>(animatedRuntime.get())));
163
+ workletRuntimeValue);
146
164
 
147
165
  std::shared_ptr<ErrorHandler> errorHandler =
148
166
  std::make_shared<AndroidErrorHandler>(scheduler_);
@@ -192,18 +210,21 @@ void NativeProxy::installJSIBindings() {
192
210
  platformDepMethodsHolder);
193
211
 
194
212
  _nativeReanimatedModule = module;
195
-
196
- this->registerEventHandler([module, getCurrentTime](
197
- std::string eventName,
198
- std::string eventAsString) {
199
- jsi::Object global = module->runtime->global();
200
- jsi::String eventTimestampName =
201
- jsi::String::createFromAscii(*module->runtime, "_eventTimestamp");
202
- global.setProperty(*module->runtime, eventTimestampName, getCurrentTime());
203
- module->onEvent(eventName, eventAsString);
204
- global.setProperty(
205
- *module->runtime, eventTimestampName, jsi::Value::undefined());
206
- });
213
+ std::weak_ptr<NativeReanimatedModule> weakModule = module;
214
+ this->registerEventHandler(
215
+ [weakModule, getCurrentTime](
216
+ std::string eventName, std::string eventAsString) {
217
+ if (auto module = weakModule.lock()) {
218
+ jsi::Object global = module->runtime->global();
219
+ jsi::String eventTimestampName =
220
+ jsi::String::createFromAscii(*module->runtime, "_eventTimestamp");
221
+ global.setProperty(
222
+ *module->runtime, eventTimestampName, getCurrentTime());
223
+ module->onEvent(eventName, eventAsString);
224
+ global.setProperty(
225
+ *module->runtime, eventTimestampName, jsi::Value::undefined());
226
+ }
227
+ });
207
228
 
208
229
  runtime_->global().setProperty(
209
230
  *runtime_,
@@ -131,6 +131,8 @@ class NativeProxy : public jni::HybridClass<NativeProxy> {
131
131
  jni::alias_ref<LayoutAnimations::javaobject> layoutAnimations);
132
132
  static void registerNatives();
133
133
 
134
+ ~NativeProxy();
135
+
134
136
  private:
135
137
  friend HybridBase;
136
138
  jni::global_ref<NativeProxy::javaobject> javaPart_;
@@ -147,14 +147,17 @@ public class NativeProxy {
147
147
  }
148
148
 
149
149
  private void addDevMenuOption() {
150
- final DevSupportManager devSupportManager =
151
- ((ReactApplication) mContext.get().getApplicationContext())
152
- .getReactNativeHost()
153
- .getReactInstanceManager()
154
- .getDevSupportManager();
155
-
156
- devSupportManager.addCustomDevOption(
157
- "Toggle slow animations (Reanimated)", this::toggleSlowAnimations);
150
+ // In Expo, `ApplicationContext` is not an instance of `ReactApplication`
151
+ if (mContext.get().getApplicationContext() instanceof ReactApplication) {
152
+ final DevSupportManager devSupportManager =
153
+ ((ReactApplication) mContext.get().getApplicationContext())
154
+ .getReactNativeHost()
155
+ .getReactInstanceManager()
156
+ .getDevSupportManager();
157
+
158
+ devSupportManager.addCustomDevOption(
159
+ "Toggle slow animations (Reanimated)", this::toggleSlowAnimations);
160
+ }
158
161
  }
159
162
 
160
163
  @DoNotStrip
@@ -1,5 +1,6 @@
1
1
  package com.swmansion.reanimated.layoutReanimation;
2
2
 
3
+ import android.app.Activity;
3
4
  import android.util.DisplayMetrics;
4
5
  import android.util.Log;
5
6
  import android.view.View;
@@ -368,12 +369,18 @@ public class AnimationsManager implements ViewHierarchyObserver {
368
369
  preparedValues.put(key, PixelUtil.toDIPFromPixel((int) values.get(key)));
369
370
  }
370
371
 
371
- DisplayMetrics displaymetrics = new DisplayMetrics();
372
- mContext.getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
373
- int height = displaymetrics.heightPixels;
374
- int width = displaymetrics.widthPixels;
375
- preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(width));
376
- preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(height));
372
+ DisplayMetrics displayMetrics = new DisplayMetrics();
373
+ Activity currentActivity = mContext.getCurrentActivity();
374
+ if (currentActivity != null) {
375
+ currentActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
376
+ int height = displayMetrics.heightPixels;
377
+ int width = displayMetrics.widthPixels;
378
+ preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(width));
379
+ preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(height));
380
+ } else {
381
+ preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(0));
382
+ preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(0));
383
+ }
377
384
  return preparedValues;
378
385
  }
379
386
 
@@ -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_ACCELEROMETER),
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
 
@@ -1,6 +1,6 @@
1
1
  #import <Foundation/Foundation.h>
2
+ #import <RNReanimated/REASnapshot.h>
2
3
  #import <React/RCTUIManager.h>
3
- #import "REASnapshot.h"
4
4
 
5
5
  NS_ASSUME_NONNULL_BEGIN
6
6
 
@@ -1,9 +1,9 @@
1
- #import "REAAnimationsManager.h"
1
+ #import <RNReanimated/REAAnimationsManager.h>
2
+ #import <RNReanimated/REAUIManager.h>
2
3
  #import <React/RCTComponentData.h>
3
4
  #import <React/RCTTextView.h>
4
5
  #import <React/UIView+Private.h>
5
6
  #import <React/UIView+React.h>
6
- #import "REAUIManager.h"
7
7
 
8
8
  @interface REAAnimationsManager ()
9
9
 
@@ -1,5 +1,5 @@
1
- #import "REASnapshot.h"
2
1
  #import <Foundation/Foundation.h>
2
+ #import <RNReanimated/REASnapshot.h>
3
3
 
4
4
  NS_ASSUME_NONNULL_BEGIN
5
5
 
@@ -1,7 +1,7 @@
1
+ #import <RNReanimated/REAAnimationsManager.h>
1
2
  #import <React/RCTBridge+Private.h>
2
3
  #import <React/RCTDefines.h>
3
4
  #import <React/RCTUIManager.h>
4
- #import "REAAnimationsManager.h"
5
5
 
6
6
  NS_ASSUME_NONNULL_BEGIN
7
7
 
@@ -1,9 +1,8 @@
1
- #import "REAUIManager.h"
2
1
  #import <Foundation/Foundation.h>
3
- #include "FeaturesConfig.h"
4
- #import "REAIOSScheduler.h"
5
- #include "Scheduler.h"
6
-
2
+ #import <RNReanimated/FeaturesConfig.h>
3
+ #import <RNReanimated/REAIOSScheduler.h>
4
+ #import <RNReanimated/REAUIManager.h>
5
+ #import <RNReanimated/Scheduler.h>
7
6
  #import <React/RCTComponentData.h>
8
7
  #import <React/RCTLayoutAnimation.h>
9
8
  #import <React/RCTLayoutAnimationGroup.h>
@@ -1,4 +1,4 @@
1
- #import "REANode.h"
1
+ #import <RNReanimated/REANode.h>
2
2
 
3
3
  @interface REAAlwaysNode : REANode <REAFinalNode>
4
4
  @end
@@ -1,11 +1,11 @@
1
- #import "REAAlwaysNode.h"
1
+ #import <RNReanimated/REAAlwaysNode.h>
2
+ #import <RNReanimated/REAModule.h>
3
+ #import <RNReanimated/REANodesManager.h>
4
+ #import <RNReanimated/REAStyleNode.h>
5
+ #import <RNReanimated/REAUtils.h>
2
6
  #import <React/RCTConvert.h>
3
7
  #import <React/RCTLog.h>
4
8
  #import <React/RCTUIManager.h>
5
- #import "REAModule.h"
6
- #import "REANodesManager.h"
7
- #import "REAStyleNode.h"
8
- #import "REAUtils.h"
9
9
 
10
10
  @implementation REAAlwaysNode {
11
11
  NSNumber *_nodeToBeEvaluated;
@@ -1,4 +1,4 @@
1
- #import "REANode.h"
1
+ #import <RNReanimated/REANode.h>
2
2
 
3
3
  @interface REABezierNode : REANode
4
4
 
@@ -1,10 +1,9 @@
1
- #include <tgmath.h>
2
-
1
+ #import <RNReanimated/REABezierNode.h>
2
+ #import <RNReanimated/REANodesManager.h>
3
+ #import <RNReanimated/REAUtils.h>
3
4
  #import <React/RCTConvert.h>
4
5
  #import <React/RCTLog.h>
5
- #import "REABezierNode.h"
6
- #import "REANodesManager.h"
7
- #import "REAUtils.h"
6
+ #include <tgmath.h>
8
7
 
9
8
  #define EPS 1e-5
10
9
 
@@ -1,4 +1,4 @@
1
- #import "REANode.h"
1
+ #import <RNReanimated/REANode.h>
2
2
 
3
3
  @interface REABlockNode : REANode
4
4
 
@@ -1,5 +1,5 @@
1
- #import "REABlockNode.h"
2
- #import "REANodesManager.h"
1
+ #import <RNReanimated/REABlockNode.h>
2
+ #import <RNReanimated/REANodesManager.h>
3
3
 
4
4
  @implementation REABlockNode {
5
5
  NSArray<NSNumber *> *_block;
@@ -1,5 +1,5 @@
1
1
 
2
- #import "REANode.h"
2
+ #import <RNReanimated/REANode.h>
3
3
 
4
4
  @interface REACallFuncNode : REANode
5
5
 
@@ -1,10 +1,10 @@
1
1
 
2
2
 
3
- #import "REACallFuncNode.h"
4
- #import "REAFunctionNode.h"
5
- #import "REANodesManager.h"
6
- #import "REAParamNode.h"
7
- #import "REAUtils.h"
3
+ #import <RNReanimated/REACallFuncNode.h>
4
+ #import <RNReanimated/REAFunctionNode.h>
5
+ #import <RNReanimated/REANodesManager.h>
6
+ #import <RNReanimated/REAParamNode.h>
7
+ #import <RNReanimated/REAUtils.h>
8
8
 
9
9
  @implementation REACallFuncNode {
10
10
  NSNumber *_whatNodeID;
@@ -1,4 +1,4 @@
1
- #import "REANode.h"
1
+ #import <RNReanimated/REANode.h>
2
2
 
3
3
  @interface REAClockNode : REANode
4
4
  @property (nonatomic, readonly) BOOL isRunning;
@@ -1,9 +1,9 @@
1
- #import "REAClockNodes.h"
1
+ #import <RNReanimated/REAClockNodes.h>
2
+ #import <RNReanimated/REANodesManager.h>
3
+ #import <RNReanimated/REAParamNode.h>
4
+ #import <RNReanimated/REAUtils.h>
2
5
  #import <React/RCTConvert.h>
3
6
  #import <React/RCTLog.h>
4
- #import "REANodesManager.h"
5
- #import "REAParamNode.h"
6
- #import "REAUtils.h"
7
7
 
8
8
  @interface REAClockNode ()
9
9
 
@@ -1,4 +1,4 @@
1
- #import "REANode.h"
1
+ #import <RNReanimated/REANode.h>
2
2
 
3
3
  @interface REAConcatNode : REANode
4
4