Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Android): Add backward compatibility for prefabs #2088

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ def reactNativeArchitectures() {
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def safeAppExtGet(prop, fallback) {
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
}

def resolveReactNativeDirectory() {
def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
if (reactNativeLocation != null) {
return file(reactNativeLocation)
}

def reactNativeFromAppNodeModules = file("${projectDir}/../../react-native")
if (reactNativeFromAppNodeModules.exists()) {
return reactNativeFromAppNodeModules
}

def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

throw new GradleException(
"[RNScreens] Unable to resolve react-native location in node_modules. You should project extension property (in `app/build.gradle`) `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
)
}

def reactNativeRootDir = resolveReactNativeDirectory()
def reactProperties = new Properties()
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()

android {
compileSdkVersion safeExtGet('compileSdkVersion', rnsDefaultCompileSdkVersion)
def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION
Expand Down Expand Up @@ -80,12 +112,14 @@ android {
}
}
}
buildFeatures {
prefab true
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
if (REACT_NATIVE_MINOR_VERSION >= 71) {
buildFeatures {
prefab true
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
lintOptions {
Expand Down Expand Up @@ -146,11 +180,11 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.6.1'
Comment on lines +183 to +187
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed, because of the error while building a project: Can't determine type for tag '<macro name="m3_comp_assist_chip_container_shape">?attr/shapeAppearanceCornerSmall</macro>. Since we're not using any features from Material 3, it's more important to patch this (at least for now 😛).

implementation "androidx.core:core-ktx:1.8.0"

constraints {
Expand Down
4 changes: 3 additions & 1 deletion android/src/main/java/com/swmansion/rnscreens/ScreenStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ class ScreenStack(context: Context?) : ScreenContainer(context) {

private fun needsDrawReordering(fragmentWrapper: ScreenFragmentWrapper): Boolean =
// On Android sdk 33 and above the animation is different and requires draw reordering.
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ||
// For React Native 0.70 and lower versions, `Build.VERSION_CODES.TIRAMISU` is not defined yet.
// Hence, we're comparing numerical version here.
Build.VERSION.SDK_INT >= 33 ||
fragmentWrapper.screen.stackAnimation === StackAnimation.SLIDE_FROM_BOTTOM ||
fragmentWrapper.screen.stackAnimation === StackAnimation.FADE_FROM_BOTTOM ||
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS
Expand Down
Loading