Skip to content

Commit

Permalink
fix: add deprecated SvgViewManager to not break 0.72 (#2435)
Browse files Browse the repository at this point in the history
# Summary

Fixes #2428
To not introduce the breaking change in minor version, it restores the
old `SvgViewManager.java` on RN <= 72 using sourceSets

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |    ✅      |
  • Loading branch information
jakex7 authored Sep 2, 2024
1 parent 8d3a03e commit fbc6631
Show file tree
Hide file tree
Showing 3 changed files with 432 additions and 0 deletions.
34 changes: 34 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

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

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

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

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

def getReactNativeMinorVersion() {
def reactNativeRootDir = resolveReactNativeDirectory()
def reactNativeProperties = new Properties()
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactNativeProperties.load(it) }
def reactNativeVersion = reactNativeProperties.getProperty("VERSION_NAME")
return reactNativeVersion.split("\\.")[1].toInteger()
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
Expand Down Expand Up @@ -76,6 +105,11 @@ android {
"src/paper/java",
]
}
if (getReactNativeMinorVersion() >= 73) {
srcDirs += "src/transformRn73/java"
} else {
srcDirs += "src/deprecated/java"
}
}
}
}
Expand Down
Loading

0 comments on commit fbc6631

Please sign in to comment.