react-native-reanimated 3.0.0-rc.2 → 3.0.0-rc.3

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 (127) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +3 -0
  2. package/Common/cpp/{headers/AnimatedSensor → AnimatedSensor}/AnimatedSensorModule.h +0 -0
  3. package/Common/cpp/Fabric/FabricUtils.cpp +1 -1
  4. package/Common/cpp/{headers/Fabric → Fabric}/FabricUtils.h +0 -0
  5. package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +2 -0
  6. package/Common/cpp/{headers/Fabric → Fabric}/ReanimatedUIManagerBinding.h +0 -0
  7. package/Common/cpp/{headers/Fabric → Fabric}/ShadowTreeCloner.h +1 -1
  8. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
  9. package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +1 -0
  11. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModule.h +5 -0
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +2 -0
  13. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModuleSpec.h +1 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +93 -0
  15. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +125 -0
  16. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +50 -0
  17. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.h +27 -0
  18. package/Common/cpp/ReanimatedRuntime/RuntimeInitialization.md +194 -0
  19. package/Common/cpp/{headers/Registries → Registries}/EventHandlerRegistry.h +0 -0
  20. package/Common/cpp/Registries/MapperRegistry.cpp +3 -1
  21. package/Common/cpp/{headers/Registries → Registries}/MapperRegistry.h +0 -0
  22. package/Common/cpp/{headers/Registries → Registries}/NewestShadowNodesRegistry.h +0 -0
  23. package/Common/cpp/Registries/WorkletsCache.cpp +8 -1
  24. package/Common/cpp/{headers/Registries → Registries}/WorkletsCache.h +0 -0
  25. package/Common/cpp/{headers/SharedItems → SharedItems}/FrozenObject.h +0 -0
  26. package/Common/cpp/{headers/SharedItems → SharedItems}/HostFunctionHandler.h +0 -0
  27. package/Common/cpp/SharedItems/MutableValue.cpp +2 -0
  28. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValue.h +0 -0
  29. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValueSetterProxy.h +0 -0
  30. package/Common/cpp/{headers/SharedItems → SharedItems}/RemoteObject.h +0 -0
  31. package/Common/cpp/{headers/SharedItems → SharedItems}/RuntimeManager.h +0 -0
  32. package/Common/cpp/SharedItems/ShareableValue.cpp +6 -0
  33. package/Common/cpp/{headers/SharedItems → SharedItems}/ShareableValue.h +0 -0
  34. package/Common/cpp/{headers/SharedItems → SharedItems}/SharedParent.h +0 -0
  35. package/Common/cpp/{headers/SharedItems → SharedItems}/ValueWrapper.h +0 -0
  36. package/Common/cpp/{headers/SpecTools → SpecTools}/ErrorHandler.h +0 -0
  37. package/Common/cpp/{headers/Tools → Tools}/FeaturesConfig.h +0 -0
  38. package/Common/cpp/Tools/JSIStoreValueUser.cpp +2 -2
  39. package/Common/cpp/{headers/Tools → Tools}/JSIStoreValueUser.h +0 -0
  40. package/Common/cpp/{headers/Tools → Tools}/Mapper.h +0 -0
  41. package/Common/cpp/{headers/Tools → Tools}/PlatformDepMethodsHolder.h +0 -0
  42. package/Common/cpp/{headers/Tools → Tools}/ReanimatedHiddenHeaders.h +1 -1
  43. package/Common/cpp/{headers/Tools → Tools}/RuntimeDecorator.h +0 -0
  44. package/Common/cpp/{headers/Tools → Tools}/Scheduler.h +0 -0
  45. package/Common/cpp/Tools/SingleInstanceChecker.h +58 -0
  46. package/Common/cpp/{headers/Tools → Tools}/WorkletEventHandler.h +0 -0
  47. package/RNReanimated.podspec +25 -23
  48. package/android/CMakeLists.txt +41 -38
  49. package/android/build.gradle +91 -72
  50. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +10 -8
  51. package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +0 -0
  52. package/android/src/main/cpp/AndroidLogger.cpp +4 -1
  53. package/android/src/main/cpp/{headers/AndroidLogger.h → AndroidLogger.h} +0 -0
  54. package/android/src/main/cpp/{headers/AndroidScheduler.h → AndroidScheduler.h} +0 -0
  55. package/android/src/main/cpp/{headers/JNIHelper.h → JNIHelper.h} +0 -0
  56. package/android/src/main/cpp/{headers/LayoutAnimations.h → LayoutAnimations.h} +0 -0
  57. package/android/src/main/cpp/NativeProxy.cpp +12 -28
  58. package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +3 -1
  59. package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
  60. package/android/src/main/java/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +77 -0
  61. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
  62. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +7 -7
  63. package/ios/REAModule.mm +10 -0
  64. package/ios/native/NativeProxy.mm +12 -19
  65. package/ios/native/REAInitializer.h +2 -2
  66. package/ios/native/REAInitializer.mm +2 -2
  67. package/ios/native/REAMessageThread.h +22 -0
  68. package/ios/native/REAMessageThread.mm +38 -0
  69. package/ios/native/UIResponder+Reanimated.mm +1 -1
  70. package/lib/commonjs/reanimated2/NativeMethods.js +20 -24
  71. package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
  72. package/lib/commonjs/reanimated2/animation/delay.js +0 -12
  73. package/lib/commonjs/reanimated2/animation/delay.js.map +1 -1
  74. package/lib/commonjs/reanimated2/animation/repeat.js +0 -24
  75. package/lib/commonjs/reanimated2/animation/repeat.js.map +1 -1
  76. package/lib/commonjs/reanimated2/animation/sequence.js +0 -12
  77. package/lib/commonjs/reanimated2/animation/sequence.js.map +1 -1
  78. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  79. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  80. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  81. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +51 -19
  82. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  83. package/lib/commonjs/reanimated2/hook/index.js +8 -0
  84. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  85. package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  86. package/lib/commonjs/reanimated2/hook/useFrameCallback.js.map +1 -1
  87. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +31 -0
  88. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -0
  89. package/lib/commonjs/reanimated2/utils.js +12 -3
  90. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  91. package/lib/module/reanimated2/NativeMethods.js +20 -24
  92. package/lib/module/reanimated2/NativeMethods.js.map +1 -1
  93. package/lib/module/reanimated2/animation/delay.js +0 -10
  94. package/lib/module/reanimated2/animation/delay.js.map +1 -1
  95. package/lib/module/reanimated2/animation/repeat.js +0 -20
  96. package/lib/module/reanimated2/animation/repeat.js.map +1 -1
  97. package/lib/module/reanimated2/animation/sequence.js +0 -10
  98. package/lib/module/reanimated2/animation/sequence.js.map +1 -1
  99. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  100. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  101. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  102. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +51 -19
  103. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  104. package/lib/module/reanimated2/hook/index.js +1 -0
  105. package/lib/module/reanimated2/hook/index.js.map +1 -1
  106. package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  107. package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
  108. package/lib/module/reanimated2/hook/useScrollViewOffset.js +20 -0
  109. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -0
  110. package/lib/module/reanimated2/utils.js +13 -3
  111. package/lib/module/reanimated2/utils.js.map +1 -1
  112. package/package.json +6 -4
  113. package/plugin.js +105 -47
  114. package/react-native-reanimated.d.ts +13 -9
  115. package/src/reanimated2/NativeMethods.ts +28 -33
  116. package/src/reanimated2/animation/delay.ts +0 -12
  117. package/src/reanimated2/animation/repeat.ts +0 -25
  118. package/src/reanimated2/animation/sequence.ts +0 -13
  119. package/src/reanimated2/commonTypes.ts +9 -0
  120. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
  121. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
  122. package/src/reanimated2/hook/index.ts +1 -0
  123. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
  124. package/src/reanimated2/hook/useFrameCallback.ts +2 -1
  125. package/src/reanimated2/hook/useScrollViewOffset.ts +36 -0
  126. package/src/reanimated2/utils.ts +12 -5
  127. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +0 -29
@@ -4,7 +4,6 @@ import java.nio.file.Files
4
4
  import java.nio.file.Paths
5
5
  import java.nio.file.Path
6
6
  import org.apache.tools.ant.filters.ReplaceTokens
7
- import groovy.json.JsonSlurper
8
7
  import java.util.stream.Stream
9
8
 
10
9
  /**
@@ -47,13 +46,10 @@ def safeExtGet(prop, fallback) {
47
46
  }
48
47
 
49
48
  def resolveBuildType() {
50
- def buildType = "debug"
51
- tasks.all({ task ->
52
- if (task.name == "buildCMakeRelease") {
53
- buildType = "release"
54
- }
55
- })
56
- return buildType
49
+ Gradle gradle = getGradle()
50
+ String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
51
+
52
+ return tskReqStr.contains('Release') ? 'release' : 'debug'
57
53
  }
58
54
 
59
55
  def resolveClientSideBuild() {
@@ -109,59 +105,55 @@ def getPlaygroundAppName() { // only for the development
109
105
  return playgroundAppName
110
106
  }
111
107
 
112
- boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
113
- if (CLIENT_SIDE_BUILD) {
114
- configurations.maybeCreate("default")
108
+ def shouldAssertNoMultipleInstances() {
109
+ if (rootProject.hasProperty("disableMultipleInstancesCheck")) {
110
+ return rootProject.property("disableMultipleInstancesCheck") != "true"
111
+ } else {
112
+ return true
113
+ }
114
+ }
115
115
 
116
- Stream<Path> pathStream = Files.find(
117
- Paths.get(rootDir.parent),
118
- Integer.MAX_VALUE,
119
- (path, basicFileAttributes) -> { path.toString().endsWith("/react-native-reanimated/package.json") }
120
- )
121
-
122
- String parsedLocation = ""
123
- def libInstancesCount = 0
124
- pathStream.forEach(path -> {
125
- parsedLocation += "- " + path.toString().replace("/package.json", "\n")
126
- libInstancesCount++
127
- })
128
- if (libInstancesCount > 1) {
116
+ def noMultipleInstancesAssertion() {
117
+ // Assert there are no multiple installations of Reanimated
118
+ Set<File> files = fileTree(rootDir.parent) {
119
+ include "**/react-native-reanimated/package.json"
120
+ exclude "**/.yarn/**"
121
+ }.files
122
+
123
+ if (files.size() > 1) {
124
+ String parsedLocation = files.stream().map({ File file -> "- " + file.toString().replace("/package.json", "") }).collect().join("\n")
129
125
  String exceptionMessage = "\nMultiple versions of Reanimated were detected. Only one instance of react-native-reanimated can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/troubleshooting#multiple-versions-of-reanimated-were-detected \n\nConflict between: \n" + parsedLocation + "\n";
130
126
  throw new Exception(exceptionMessage)
131
127
  }
132
128
  }
133
- def reactNative = resolveReactNativeDirectory()
134
- def reactNativeManifest = file("$reactNative/package.json")
135
- def reactNativeManifestAsJson = new JsonSlurper().parseText(reactNativeManifest.text)
136
- def reactNativeVersion = reactNativeManifestAsJson.version as String
137
- def (major, minor, patch) = reactNativeVersion.tokenize('.')
138
- def rnMinorVersion = Integer.parseInt(minor)
139
129
 
140
- def localProps = new Properties()
141
- def localPropertiesFile = file("local.properties")
142
- if (localPropertiesFile.exists()) {
143
- localProps.load(new InputStreamReader(new FileInputStream(localPropertiesFile), "UTF-8"))
130
+ boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
131
+ if (CLIENT_SIDE_BUILD) {
132
+ configurations.maybeCreate("default")
144
133
  }
145
134
 
146
- def debugNativeLibraries = localProps.getProperty('NATIVE_DEBUG_ON', 'FALSE').toBoolean()
135
+ def reactNativeRootDir = resolveReactNativeDirectory()
136
+
147
137
  def reactProperties = new Properties()
148
- file("$reactNative/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
138
+ file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
149
139
 
150
140
  def BOOST_VERSION = reactProperties.getProperty("BOOST_VERSION")
151
141
  def DOUBLE_CONVERSION_VERSION = reactProperties.getProperty("DOUBLE_CONVERSION_VERSION")
152
142
  def FOLLY_VERSION = reactProperties.getProperty("FOLLY_VERSION")
153
143
  def GLOG_VERSION = reactProperties.getProperty("GLOG_VERSION")
154
- def REACT_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
144
+ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
145
+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
155
146
  def FBJNI_VERSION = "0.3.0"
156
147
 
157
148
  // We download various C++ open-source dependencies into downloads.
158
149
  // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
159
150
  // After that we build native code from src/main/jni with module path pointing at third-party-ndk.
160
151
 
161
- def downloadsDir = new File("$buildDir/downloads")
152
+ def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
153
+ def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
162
154
  def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
163
155
 
164
- def reactNativeThirdParty = new File("$reactNative/ReactAndroid/src/main/jni/third-party")
156
+ def reactNativeThirdParty = new File("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party")
165
157
 
166
158
  def _stackProtectorFlag = true
167
159
 
@@ -187,7 +179,7 @@ def JS_RUNTIME = {
187
179
 
188
180
  def jsRuntimeDir = {
189
181
  if (JS_RUNTIME == "hermes") {
190
- if (rnMinorVersion >= 69) {
182
+ if (REACT_NATIVE_MINOR_VERSION >= 69) {
191
183
  return Paths.get(CMAKE_NODE_MODULES_DIR, "react-native", "sdks", "hermes")
192
184
  } else {
193
185
  return Paths.get(CMAKE_NODE_MODULES_DIR, "hermes-engine")
@@ -258,8 +250,7 @@ android {
258
250
  externalNativeBuild {
259
251
  cmake {
260
252
  arguments "-DANDROID_STL=c++_shared",
261
- "-DNATIVE_DEBUG=${debugNativeLibraries}",
262
- "-DREACT_NATIVE_TARGET_VERSION=${REACT_VERSION}",
253
+ "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
263
254
  "-DANDROID_TOOLCHAIN=clang",
264
255
  "-DBOOST_VERSION=${BOOST_VERSION}",
265
256
  "-DNODE_MODULES_DIR=${CMAKE_NODE_MODULES_DIR}",
@@ -267,8 +258,7 @@ android {
267
258
  "-DJS_RUNTIME_DIR=${jsRuntimeDir}",
268
259
  "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
269
260
  "-DIS_NEW_ARCHITECTURE_ENABLED=${isNewArchitectureEnabled()}",
270
- "-DPLAYGROUND_APP_NAME=${getPlaygroundAppName()}",
271
- "-DRNVERSION=${rnMinorVersion}"
261
+ "-DPLAYGROUND_APP_NAME=${getPlaygroundAppName()}"
272
262
  abiFilters (*reactNativeArchitectures())
273
263
  _stackProtectorFlag ? (cppFlags("-fstack-protector-all")) : null
274
264
  }
@@ -276,20 +266,38 @@ android {
276
266
 
277
267
  buildConfigField("boolean", "IS_INTERNAL_BUILD", "false")
278
268
  buildConfigField("int", "EXOPACKAGE_FLAGS", "0")
279
- buildConfigField("int", "REACT_NATIVE_VERSION", rnMinorVersion.toString())
269
+ buildConfigField("int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString())
280
270
  }
281
271
  externalNativeBuild {
282
272
  cmake {
283
273
  path "CMakeLists.txt"
284
- version "3.18.1"
274
+ }
275
+ }
276
+ buildTypes {
277
+ debug {
278
+ externalNativeBuild {
279
+ cmake {
280
+ if (JS_RUNTIME == "hermes") {
281
+ arguments "-DHERMES_ENABLE_DEBUGGER=1"
282
+ } else {
283
+ arguments "-DHERMES_ENABLE_DEBUGGER=0"
284
+ }
285
+ }
286
+ }
287
+ }
288
+ release {
289
+ externalNativeBuild {
290
+ cmake {
291
+ arguments "-DHERMES_ENABLE_DEBUGGER=0"
292
+ }
293
+ }
285
294
  }
286
295
  }
287
296
  lintOptions {
288
297
  abortOnError false
289
298
  }
290
299
  packagingOptions {
291
- println "Native libs debug enabled: ${debugNativeLibraries}"
292
- doNotStrip debugNativeLibraries ? "**/**/*.so" : ''
300
+ doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
293
301
  excludes = [
294
302
  "**/libc++_shared.so",
295
303
  "**/libfbjni.so",
@@ -298,6 +306,7 @@ android {
298
306
  "**/libfolly_runtime.so",
299
307
  "**/libglog.so",
300
308
  "**/libhermes.so",
309
+ "**/libhermes-executor-debug.so",
301
310
  "**/libreactnativejni.so",
302
311
  "**/libjscexecutor.so",
303
312
  "**/libv8executor.so",
@@ -338,6 +347,17 @@ android {
338
347
  }
339
348
  }
340
349
 
350
+ def assertionTask = task assertNoMultipleInstances {
351
+ onlyIf { shouldAssertNoMultipleInstances() && CLIENT_SIDE_BUILD }
352
+ doFirst {
353
+ noMultipleInstancesAssertion()
354
+ }
355
+ }
356
+
357
+ tasks.preBuild {
358
+ dependsOn assertionTask
359
+ }
360
+
341
361
  task cleanCmakeCache() {
342
362
  tasks.getByName("clean").dependsOn(cleanCmakeCache)
343
363
  doFirst {
@@ -355,7 +375,7 @@ task Log {
355
375
  }
356
376
 
357
377
  task applyJavaPatches(type: Copy) {
358
- def patchDirectory = file("${projectDir}/rnVersionPatch/${rnMinorVersion}")
378
+ def patchDirectory = file("${projectDir}/rnVersionPatch/${REACT_NATIVE_MINOR_VERSION}")
359
379
  if (patchDirectory.exists()) {
360
380
  from ("${patchDirectory}") {
361
381
  include "**/*.java"
@@ -372,7 +392,7 @@ task createNativeDepsDirectories(dependsOn: applyJavaPatches) {
372
392
  task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
373
393
  def transformedVersion = BOOST_VERSION.replace("_", ".")
374
394
  def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
375
- if (rnMinorVersion < 69) {
395
+ if (REACT_NATIVE_MINOR_VERSION < 69) {
376
396
  srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
377
397
  }
378
398
  src(srcUrl)
@@ -483,12 +503,10 @@ as well as unzip Hermes AAR in order to obtain `libhermes.so` shared library.
483
503
  For more details, see https://reactnative.dev/architecture/bundled-hermes
484
504
  or https://github.com/reactwg/react-native-new-architecture/discussions/4
485
505
  */
486
- if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
506
+ if (REACT_NATIVE_MINOR_VERSION >= 69 && !isNewArchitectureEnabled()) {
487
507
  // copied from `react-native/ReactAndroid/hermes-engine/build.gradle`
488
508
 
489
- def reactNativeRootDir = resolveReactNativeDirectory()
490
- def customDownloadDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
491
- def downloadDir = customDownloadDir ? new File(customDownloadDir) : new File(reactNativeRootDir, "sdks/download")
509
+ def downloadDir = customDownloadsDir ? new File(customDownloadsDir) : new File(reactNativeRootDir, "sdks/download")
492
510
 
493
511
  // By default we are going to download and unzip hermes inside the /sdks/hermes folder
494
512
  // but you can provide an override for where the hermes source code is located.
@@ -522,13 +540,13 @@ if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
522
540
  }
523
541
 
524
542
  task prepareHermes() {
525
- if (rnMinorVersion >= 69) {
543
+ if (REACT_NATIVE_MINOR_VERSION >= 69) {
526
544
  if (!isNewArchitectureEnabled()) {
527
545
  dependsOn(unzipHermes)
528
546
  }
529
547
 
530
548
  doLast {
531
- def hermesAAR = file("$reactNative/android/com/facebook/react/hermes-engine/$reactNativeVersion/hermes-engine-$reactNativeVersion-${resolveBuildType()}.aar") // e.g. hermes-engine-0.70.0-rc.1-debug.aar
549
+ def hermesAAR = file("$reactNativeRootDir/android/com/facebook/react/hermes-engine/${REACT_NATIVE_VERSION}/hermes-engine-${REACT_NATIVE_VERSION}-${resolveBuildType()}.aar") // e.g. hermes-engine-0.70.0-rc.1-debug.aar
532
550
  if (!hermesAAR.exists()) {
533
551
  throw new GradleScriptException("Could not find hermes-engine AAR", null)
534
552
  }
@@ -537,7 +555,7 @@ task prepareHermes() {
537
555
 
538
556
  copy {
539
557
  from soFiles
540
- from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
558
+ from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
541
559
  into "$thirdPartyNdkDir/hermes"
542
560
  }
543
561
  }
@@ -548,16 +566,16 @@ task prepareHermes() {
548
566
  throw new GradleScriptException("Could not find the hermes-engine npm package", null)
549
567
  }
550
568
 
551
- def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar")
569
+ def hermesAAR = file("$hermesPackagePath/android/hermes-${resolveBuildType()}.aar") // e.g. hermes-debug.aar
552
570
  if (!hermesAAR.exists()) {
553
- throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
571
+ throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-${resolveBuildType()}.aar\"", null)
554
572
  }
555
573
 
556
574
  def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" })
557
575
 
558
576
  copy {
559
577
  from soFiles
560
- from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
578
+ from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
561
579
  into "$thirdPartyNdkDir/hermes"
562
580
  }
563
581
  }
@@ -584,7 +602,7 @@ task prepareJSC {
584
602
  copy {
585
603
  from(soFiles)
586
604
  from(headerFiles)
587
- from("$reactNative/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
605
+ from("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
588
606
 
589
607
  filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" })
590
608
 
@@ -601,7 +619,7 @@ task extractAARHeaders {
601
619
  def packageName = file.name.tokenize('-')[0]
602
620
  copy {
603
621
  from zipTree(file)
604
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/headers"
622
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/headers"
605
623
  include "**/*.h"
606
624
  }
607
625
  }
@@ -615,7 +633,7 @@ task extractSOFiles {
615
633
  def packageName = file.name.tokenize('-')[0]
616
634
  copy {
617
635
  from zipTree(file)
618
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
636
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/"
619
637
  include "jni/**/*.so"
620
638
  }
621
639
  }
@@ -625,7 +643,7 @@ task extractSOFiles {
625
643
  task packageNdkLibs(type: Copy) {
626
644
  from("$buildDir/reanimated-ndk/all")
627
645
  include("**/libreanimated.so")
628
- if(REACT_VERSION < 64) {
646
+ if(REACT_NATIVE_MINOR_VERSION < 64) {
629
647
  include("**/libturbomodulejsijni.so")
630
648
  }
631
649
  into("$projectDir/src/main/jniLibs")
@@ -636,11 +654,11 @@ repositories {
636
654
  mavenLocal()
637
655
  maven {
638
656
  // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
639
- url "$reactNative/android"
657
+ url "$reactNativeRootDir/android"
640
658
  }
641
659
  maven {
642
660
  // Android JSC is installed from npm
643
- url "$reactNative/../jsc-android/dist"
661
+ url "$reactNativeRootDir/../jsc-android/dist"
644
662
  }
645
663
  google()
646
664
  }
@@ -656,26 +674,27 @@ dependencies {
656
674
  }
657
675
  implementation "com.facebook.react:react-native:+" // From node_modules
658
676
  implementation "androidx.transition:transition:1.1.0"
659
- implementation "androidx.core:core:1.7.0"
677
+ implementation "androidx.core:core:1.6.0"
678
+
660
679
  extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers")
661
680
  extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)
662
681
 
663
- def jscAAR = fileTree("$reactNative/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
682
+ def jscAAR = fileTree("$reactNativeRootDir/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
664
683
  extractSO(files(jscAAR))
665
684
  }
666
685
 
667
686
  task unpackReactNativeAAR {
668
687
  def buildType = resolveBuildType()
669
688
  def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
670
- if (rnMinorVersion < 69) {
689
+ if (REACT_NATIVE_MINOR_VERSION < 69) {
671
690
  rnAarMatcher = "**/**/*.aar"
672
691
  }
673
- def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
692
+ def rnAAR = fileTree("$reactNativeRootDir/android").matching({ it.include rnAarMatcher }).singleFile
674
693
  def file = rnAAR.absoluteFile
675
694
  def packageName = file.name.tokenize('-')[0]
676
695
  copy {
677
696
  from zipTree(file)
678
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
697
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/"
679
698
  include "jni/**/*.so"
680
699
  }
681
700
  }
@@ -727,7 +746,7 @@ afterEvaluate {
727
746
 
728
747
  if (CLIENT_SIDE_BUILD) {
729
748
  def aarDir = "${buildDir}/outputs"
730
- def aar = file("${aarDir}/android-debug.aar")
749
+ def aar = file("${aarDir}/android-${resolveBuildType()}.aar") // e.g. android-debug.aar
731
750
  if (aar == null) {
732
751
  throw GradleScriptException("AAR build failed. No AAR found in ${aarDir}.")
733
752
  }
@@ -7,6 +7,7 @@ import com.facebook.jni.HybridData;
7
7
  import com.facebook.proguard.annotations.DoNotStrip;
8
8
  import com.facebook.react.ReactApplication;
9
9
  import com.facebook.react.bridge.NativeModule;
10
+ import com.facebook.react.bridge.queue.MessageQueueThread;
10
11
  import com.facebook.react.bridge.ReactApplicationContext;
11
12
  import com.facebook.react.bridge.ReadableMap;
12
13
  import com.facebook.react.bridge.ReadableNativeArray;
@@ -159,7 +160,9 @@ public class NativeProxy {
159
160
  LayoutAnimations LayoutAnimations,
160
161
  FabricUIManager fabricUIManager);
161
162
 
162
- private native void installJSIBindings(FabricUIManager fabricUIManager);
163
+ private native void installJSIBindings(
164
+ MessageQueueThread messageQueueThread,
165
+ FabricUIManager fabricUIManager);
163
166
 
164
167
  public native boolean isAnyHandlerWaitingForEvent(String eventName);
165
168
 
@@ -223,14 +226,12 @@ public class NativeProxy {
223
226
  }
224
227
 
225
228
  @DoNotStrip
226
- private String getUptime() {
229
+ private long getCurrentTime() {
227
230
  if (slowAnimationsEnabled) {
228
231
  final long ANIMATIONS_DRAG_FACTOR = 10;
229
- return Long.toString(
230
- this.firstUptime
231
- + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR);
232
+ return this.firstUptime + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR;
232
233
  } else {
233
- return Long.toString(SystemClock.uptimeMillis());
234
+ return SystemClock.uptimeMillis();
234
235
  }
235
236
  }
236
237
 
@@ -294,8 +295,9 @@ public class NativeProxy {
294
295
  }
295
296
  mNodesManager = mContext.get().getNativeModule(ReanimatedModule.class).getNodesManager();
296
297
  FabricUIManager fabricUIManager =
297
- (FabricUIManager) UIManagerHelper.getUIManager(mContext.get(), UIManagerType.FABRIC);
298
- installJSIBindings(fabricUIManager);
298
+ (FabricUIManager) UIManagerHelper.getUIManager(mContext.get(), UIManagerType.FABRIC);
299
+ ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread();
300
+ installJSIBindings(messageQueueThread, fabricUIManager);
299
301
  AnimationsManager animationsManager =
300
302
  mContext
301
303
  .get()
@@ -1,6 +1,9 @@
1
- #include "AndroidLogger.h"
2
1
  #include <android/log.h>
2
+ #include <memory>
3
+
4
+ #include "AndroidLogger.h"
3
5
  #include "Logger.h"
6
+
4
7
  #define APPNAME "NATIVE_REANIMATED"
5
8
 
6
9
  namespace reanimated {
@@ -1,26 +1,20 @@
1
+ #include <android/log.h>
1
2
  #include <fbjni/fbjni.h>
2
3
  #include <jsi/JSIDynamic.h>
3
4
  #include <jsi/jsi.h>
5
+ #include <react/jni/JMessageQueueThread.h>
4
6
  #include <react/jni/ReadableNativeArray.h>
5
7
  #include <react/jni/ReadableNativeMap.h>
6
8
 
7
9
  #include <memory>
8
10
  #include <string>
9
11
 
10
- #if JS_RUNTIME_HERMES
11
- #include <hermes/hermes.h>
12
- #elif JS_RUNTIME_V8
13
- #include <v8runtime/V8RuntimeFactory.h>
14
- #else
15
- #include <jsi/JSCRuntime.h>
16
- #endif
17
-
18
- #include <android/log.h>
19
12
  #include "AndroidErrorHandler.h"
20
13
  #include "AndroidScheduler.h"
21
14
  #include "LayoutAnimationsProxy.h"
22
15
  #include "NativeProxy.h"
23
16
  #include "PlatformDepMethodsHolder.h"
17
+ #include "ReanimatedRuntime.h"
24
18
 
25
19
  #ifdef RCT_NEW_ARCH_ENABLED
26
20
  #include <JFabricUIManager.h>
@@ -101,7 +95,9 @@ jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybrid(
101
95
  }
102
96
 
103
97
  void NativeProxy::installJSIBindings(
98
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread
104
99
  #ifdef RCT_NEW_ARCH_ENABLED
100
+ ,
105
101
  jni::alias_ref<facebook::react::JFabricUIManager::javaobject>
106
102
  fabricUIManager
107
103
  #endif
@@ -130,11 +126,10 @@ void NativeProxy::installJSIBindings(
130
126
  #endif
131
127
 
132
128
  auto getCurrentTime = [this]() {
133
- auto method =
134
- javaPart_->getClass()->getMethod<local_ref<JString>()>("getUptime");
135
- local_ref<JString> output = method(javaPart_.get());
136
- return static_cast<double>(
137
- std::strtoll(output->toStdString().c_str(), NULL, 10));
129
+ static const auto method =
130
+ javaPart_->getClass()->getMethod<jlong()>("getCurrentTime");
131
+ jlong output = method(javaPart_.get());
132
+ return static_cast<double>(output);
138
133
  };
139
134
 
140
135
  auto requestRender = [this, getCurrentTime](
@@ -206,21 +201,10 @@ void NativeProxy::installJSIBindings(
206
201
  unsubscribeFromKeyboardEvents(listenerId);
207
202
  };
208
203
 
209
- #if JS_RUNTIME_HERMES
210
- auto config =
211
- ::hermes::vm::RuntimeConfig::Builder().withEnableSampleProfiling(false);
212
- std::shared_ptr<jsi::Runtime> animatedRuntime =
213
- facebook::hermes::makeHermesRuntime(config.build());
214
- #elif JS_RUNTIME_V8
215
- auto config = std::make_unique<rnv8::V8RuntimeConfig>();
216
- config->enableInspector = false;
217
- config->appName = "reanimated";
218
- std::shared_ptr<jsi::Runtime> animatedRuntime =
219
- rnv8::createSharedV8Runtime(runtime_, std::move(config));
220
- #else
204
+ auto jsQueue = std::make_shared<JMessageQueueThread>(messageQueueThread);
221
205
  std::shared_ptr<jsi::Runtime> animatedRuntime =
222
- facebook::jsc::makeJSCRuntime();
223
- #endif
206
+ ReanimatedRuntime::make(jsQueue);
207
+
224
208
  auto workletRuntimeValue =
225
209
  runtime_->global()
226
210
  .getProperty(*runtime_, "ArrayBuffer")
@@ -186,13 +186,15 @@ class NativeProxy : public jni::HybridClass<NativeProxy> {
186
186
  #endif
187
187
  #ifdef RCT_NEW_ARCH_ENABLED
188
188
  void installJSIBindings(
189
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
189
190
  jni::alias_ref<JFabricUIManager::javaobject> fabricUIManager);
190
191
  void synchronouslyUpdateUIProps(
191
192
  jsi::Runtime &rt,
192
193
  Tag viewTag,
193
194
  const jsi::Value &uiProps);
194
195
  #else
195
- void installJSIBindings();
196
+ void installJSIBindings(
197
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread);
196
198
  #endif
197
199
  bool isAnyHandlerWaitingForEvent(std::string);
198
200
  void performOperations();
@@ -0,0 +1,77 @@
1
+ package com.swmansion.reanimated;
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip;
4
+ import com.facebook.react.bridge.queue.MessageQueueThread;
5
+ import com.facebook.react.bridge.queue.MessageQueueThreadImpl;
6
+ import com.facebook.react.bridge.queue.MessageQueueThreadPerfStats;
7
+ import com.facebook.react.bridge.queue.MessageQueueThreadSpec;
8
+ import java.lang.reflect.Field;
9
+ import java.util.concurrent.Callable;
10
+ import java.util.concurrent.Future;
11
+
12
+ // This class is an almost exact copy of MessageQueueThreadImpl taken from here:
13
+ // https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/MessageQueueThreadImpl.java
14
+ // The only method that has changed is `quitSynchronous()` (see comment above
15
+ // function implementation for details).
16
+ @DoNotStrip
17
+ public class ReanimatedMessageQueueThread implements MessageQueueThread {
18
+ private final MessageQueueThreadImpl messageQueueThread;
19
+
20
+ public ReanimatedMessageQueueThread() {
21
+ messageQueueThread =
22
+ MessageQueueThreadImpl.create(
23
+ MessageQueueThreadSpec.mainThreadSpec(),
24
+ exception -> {
25
+ throw new RuntimeException(exception);
26
+ });
27
+ }
28
+
29
+ @Override
30
+ public boolean runOnQueue(Runnable runnable) {
31
+ return messageQueueThread.runOnQueue(runnable);
32
+ }
33
+
34
+ @Override
35
+ public <T> Future<T> callOnQueue(Callable<T> callable) {
36
+ return messageQueueThread.callOnQueue(callable);
37
+ }
38
+
39
+ @Override
40
+ public boolean isOnThread() {
41
+ return messageQueueThread.isOnThread();
42
+ }
43
+
44
+ @Override
45
+ public void assertIsOnThread() {
46
+ messageQueueThread.assertIsOnThread();
47
+ }
48
+
49
+ @Override
50
+ public void assertIsOnThread(String s) {
51
+ messageQueueThread.assertIsOnThread(s);
52
+ }
53
+
54
+ // We don't want to quit the main looper (which is what MessageQueueThreadImpl would have done),
55
+ // but we still want to prevent anything else from executing.
56
+ @Override
57
+ public void quitSynchronous() {
58
+ try {
59
+ Field mIsFinished = messageQueueThread.getClass().getDeclaredField("mIsFinished");
60
+ mIsFinished.setAccessible(true);
61
+ mIsFinished.set(messageQueueThread, true);
62
+ mIsFinished.setAccessible(false);
63
+ } catch (NoSuchFieldException | IllegalAccessException e) {
64
+ e.printStackTrace();
65
+ }
66
+ }
67
+
68
+ @Override
69
+ public MessageQueueThreadPerfStats getPerfStats() {
70
+ return messageQueueThread.getPerfStats();
71
+ }
72
+
73
+ @Override
74
+ public void resetPerfStats() {
75
+ messageQueueThread.resetPerfStats();
76
+ }
77
+ }
@@ -57,7 +57,8 @@ public class ReanimatedKeyboardEventListener {
57
57
  rootView,
58
58
  (v, insets) -> {
59
59
  int paddingBottom = 0;
60
- if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED && BuildConfig.REACT_NATIVE_VERSION < 70) {
60
+ if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
61
+ && BuildConfig.REACT_NATIVE_MINOR_VERSION < 70) {
61
62
  paddingBottom = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
62
63
  }
63
64
  int paddingTop = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;