Skip to content

Commit 3a04189

Browse files
authored
fix: reanimated on old architecture (software-mansion#1869)
PR adding option for `Double` for all props that were of type `NumberProp` on `Android` so `reanimated` works the same as before on old architecture. It also introduces the change of how `fill` and `stroke` should be constructed for options not going through `render` method, e.g. `react-native-reanimated`. An example of how to handle it can be seen in the provided example: https://github.com/react-native-svg/react-native-svg/pull/1869/files#diff-76a76277daf14518270e8aea8a5e9358a8215d7e4276d2e5f1c4fe95107cdc20
1 parent ee6e5da commit 3a04189

File tree

111 files changed

+3582
-2159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3582
-2159
lines changed

TestsExample/.flowconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ node_modules/react-native/Libraries/polyfills/.*
1111
; Flow doesn't support platforms
1212
.*/Libraries/Utilities/LoadingView.js
1313

14+
.*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$
15+
1416
[untyped]
1517
.*/node_modules/@react-native-community/cli/.*/.*
1618

@@ -50,7 +52,6 @@ nonstrict-import=warn
5052
deprecated-type=warn
5153
unsafe-getters-setters=warn
5254
unnecessary-invariant=warn
53-
signature-verification-failure=warn
5455

5556
[strict]
5657
deprecated-type
@@ -62,4 +63,4 @@ untyped-import
6263
untyped-type-import
6364

6465
[version]
65-
^0.170.0
66+
^0.182.0

TestsExample/.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23+
ios/.xcode.env.local
2324

2425
# Android/IntelliJ
2526
#
@@ -29,6 +30,7 @@ build/
2930
local.properties
3031
*.iml
3132
*.hprof
33+
.cxx/
3234

3335
# node.js
3436
#
@@ -49,9 +51,10 @@ buck-out/
4951
# For more information about the recommended setup visit:
5052
# https://docs.fastlane.tools/best-practices/source-control/
5153

52-
*/fastlane/report.xml
53-
*/fastlane/Preview.html
54-
*/fastlane/screenshots
54+
**/fastlane/report.xml
55+
**/fastlane/Preview.html
56+
**/fastlane/screenshots
57+
**/fastlane/test_output
5558

5659
# Bundle artifact
5760
*.jsbundle

TestsExample/.prettierrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module.exports = {
22
arrowParens: 'avoid',
3-
jsxBracketSameLine: true,
43
bracketSameLine: true,
54
bracketSpacing: false,
65
singleQuote: true,

TestsExample/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable no-unused-vars */
22
import React from 'react';
3+
34
import ColorTest from './src/ColorTest';
45
import Test1718 from './src/Test1718';
56
import Test1813 from './src/Test1813';
7+
import Test1845 from './src/Test1845';
68

79
export default function App() {
810
return <ColorTest />;

TestsExample/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

33
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4-
ruby '2.7.4'
4+
ruby '2.7.5'
55

66
gem 'cocoapods', '~> 1.11', '>= 1.11.2'

TestsExample/Gemfile.lock

Lines changed: 0 additions & 100 deletions
This file was deleted.

TestsExample/_node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

TestsExample/_ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.4
1+
2.7.5

TestsExample/android/app/build.gradle

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import org.apache.tools.ant.taskdefs.condition.Os
45

56
/**
67
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -78,7 +79,7 @@ import com.android.build.OutputFile
7879
*/
7980

8081
project.ext.react = [
81-
enableHermes: false, // clean and rebuild if changing
82+
enableHermes: true, // clean and rebuild if changing
8283
]
8384

8485
apply from: "../../node_modules/react-native/react.gradle"
@@ -142,21 +143,19 @@ android {
142143
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
143144

144145
if (isNewArchitectureEnabled()) {
145-
// We configure the NDK build only if you decide to opt-in for the New Architecture.
146+
// We configure the CMake build only if you decide to opt-in for the New Architecture.
146147
externalNativeBuild {
147-
ndkBuild {
148-
arguments "APP_PLATFORM=android-21",
149-
"APP_STL=c++_shared",
150-
"NDK_TOOLCHAIN_VERSION=clang",
151-
"GENERATED_SRC_DIR=$buildDir/generated/source",
152-
"PROJECT_BUILD_DIR=$buildDir",
153-
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
154-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
155-
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
156-
cppFlags "-std=c++17"
157-
// Make sure this target name is the same you specify inside the
158-
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
159-
targets "testsexample_appmodules"
148+
cmake {
149+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
150+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
151+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
152+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
153+
"-DANDROID_STL=c++_shared"
154+
}
155+
}
156+
if (!enableSeparateBuildPerCPUArchitecture) {
157+
ndk {
158+
abiFilters (*reactNativeArchitectures())
160159
}
161160
}
162161
}
@@ -165,8 +164,8 @@ android {
165164
if (isNewArchitectureEnabled()) {
166165
// We configure the NDK build only if you decide to opt-in for the New Architecture.
167166
externalNativeBuild {
168-
ndkBuild {
169-
path "$projectDir/src/main/jni/Android.mk"
167+
cmake {
168+
path "$projectDir/src/main/jni/CMakeLists.txt"
170169
}
171170
}
172171
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
@@ -186,6 +185,20 @@ android {
186185
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
187186
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
188187
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
188+
189+
// Due to a bug inside AGP, we have to explicitly set a dependency
190+
// between configureCMakeDebug* tasks and the preBuild tasks.
191+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
192+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
193+
configureCMakeDebug.dependsOn(preDebugBuild)
194+
reactNativeArchitectures().each { architecture ->
195+
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
196+
dependsOn("preDebugBuild")
197+
}
198+
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
199+
dependsOn("preReleaseBuild")
200+
}
201+
}
189202
}
190203
}
191204

@@ -238,14 +251,8 @@ android {
238251
dependencies {
239252
implementation fileTree(dir: "libs", include: ["*.jar"])
240253

241-
// If new architecture is enabled, we let you build RN from source
242-
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
243-
if (isNewArchitectureEnabled()) {
244-
implementation project(":ReactAndroid")
245-
} else {
246-
//noinspection GradleDynamicVersion
247-
implementation "com.facebook.react:react-native:+" // From node_modules
248-
}
254+
//noinspection GradleDynamicVersion
255+
implementation "com.facebook.react:react-native:+" // From node_modules
249256

250257
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
251258

@@ -263,14 +270,31 @@ dependencies {
263270
}
264271

265272
if (enableHermes) {
266-
def hermesPath = "../../node_modules/hermes-engine/android/";
267-
debugImplementation files(hermesPath + "hermes-debug.aar")
268-
releaseImplementation files(hermesPath + "hermes-release.aar")
273+
//noinspection GradleDynamicVersion
274+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
275+
exclude group:'com.facebook.fbjni'
276+
}
269277
} else {
270278
implementation jscFlavor
271279
}
272280
}
273281

282+
if (isNewArchitectureEnabled()) {
283+
// If new architecture is enabled, we let you build RN from source
284+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
285+
// This will be applied to all the imported transtitive dependency.
286+
configurations.all {
287+
resolutionStrategy.dependencySubstitution {
288+
substitute(module("com.facebook.react:react-native"))
289+
.using(project(":ReactAndroid"))
290+
.because("On New Architecture we're building React Native from source")
291+
substitute(module("com.facebook.react:hermes-engine"))
292+
.using(project(":ReactAndroid:hermes-engine"))
293+
.because("On New Architecture we're building Hermes from source")
294+
}
295+
}
296+
}
297+
274298
// Run this once to be able to run the application with BUCK
275299
// puts all compile dependencies into folder libs for BUCK to use
276300
task copyDownloadableDepsToLibs(type: Copy) {

TestsExample/android/app/src/main/java/com/testsexample/MainActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ protected String getMainComponentName() {
1717

1818
/**
1919
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
20-
* you can specify the rendered you wish to use (Fabric or the older renderer).
20+
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
21+
* (Paper).
2122
*/
2223
@Override
2324
protected ReactActivityDelegate createReactActivityDelegate() {
@@ -36,5 +37,12 @@ protected ReactRootView createRootView() {
3637
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
3738
return reactRootView;
3839
}
40+
41+
@Override
42+
protected boolean isConcurrentRootEnabled() {
43+
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
44+
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
45+
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
46+
}
3947
}
4048
}

TestsExample/android/app/src/main/java/com/testsexample/newarchitecture/MainApplicationReactNativeHost.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import com.facebook.react.bridge.UIManager;
1717
import com.facebook.react.fabric.ComponentFactory;
1818
import com.facebook.react.fabric.CoreComponentsRegistry;
19-
import com.facebook.react.fabric.EmptyReactNativeConfig;
2019
import com.facebook.react.fabric.FabricJSIModuleProvider;
20+
import com.facebook.react.fabric.ReactNativeConfig;
2121
import com.facebook.react.uimanager.ViewManagerRegistry;
2222
import com.testsexample.BuildConfig;
2323
import com.testsexample.newarchitecture.components.MainComponentsRegistry;
@@ -105,7 +105,7 @@ public JSIModuleProvider<UIManager> getJSIModuleProvider() {
105105
return new FabricJSIModuleProvider(
106106
reactApplicationContext,
107107
componentFactory,
108-
new EmptyReactNativeConfig(),
108+
ReactNativeConfig.DEFAULT_CONFIG,
109109
viewManagerRegistry);
110110
}
111111
});

0 commit comments

Comments
 (0)