Skip to content

Commit

Permalink
🐞 rebox/ios, rebox/android: fix compatibility with lottie-react-native
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviervia authored and deepsweet committed Apr 10, 2020
1 parent 41a7174 commit 0054ea1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/rebox/android/src/link-android-dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ export type TLinkAndroidDependencyOptions = {
dependencyName: string,
}

const getDependencyAndroidSourcePath = async (dependencyPath: string): Promise<string> => {
try {
const reactNativeConfig = await import(path.resolve(dependencyPath, 'react-native.config.js'))

return path.join(dependencyPath, reactNativeConfig.dependency.platforms.android.sourceDir)
} catch {
return path.join(dependencyPath, 'android')
}
}

export const linkAndroidDependency = async (options: TLinkAndroidDependencyOptions): Promise<void> => {
const dependencyPath = path.join('node_modules', options.dependencyName)
const dependencyAndroidSourcePath = await getDependencyAndroidSourcePath(dependencyPath)

// settings.gradle
const settingsGradlePath = path.join(options.projectPath, 'settings.gradle')
const dependencySettingsGradlePath = path.relative(options.projectPath, dependencyPath)
const dependencySettingsGradlePath = path.relative(options.projectPath, dependencyAndroidSourcePath)
let settingGradleData = await readFile(settingsGradlePath, { encoding: 'utf8' })

settingGradleData = settingGradleData.replace('// REBOX', `include ':${options.dependencyName}'\nproject(':${options.dependencyName}').projectDir = new File(rootProject.projectDir, '${dependencySettingsGradlePath}/android')\n// REBOX`)
settingGradleData = settingGradleData.replace('// REBOX', `include ':${options.dependencyName}'\nproject(':${options.dependencyName}').projectDir = new File(rootProject.projectDir, '${dependencySettingsGradlePath}')\n// REBOX`)

await writeFile(settingsGradlePath, settingGradleData)

Expand All @@ -27,10 +38,10 @@ export const linkAndroidDependency = async (options: TLinkAndroidDependencyOptio
await writeFile(buildGradlePath, buildGradleData)

// app/src/main/java/com/rebox/MainApplication.java
const dependencyManifestPath = path.join(dependencyPath, 'android', 'src', 'main', 'AndroidManifest.xml')
const dependencyManifestPath = path.join(dependencyAndroidSourcePath, 'src', 'main', 'AndroidManifest.xml')
const dependencyManifestData = await readFile(dependencyManifestPath, { encoding: 'utf8' })
const packageId = /package="(.+)"/.exec(dependencyManifestData)![1]
const packageDirFiles = await readdir(path.join(dependencyPath, 'android', 'src', 'main', 'java', ...packageId.split('.')))
const packageDirFiles = await readdir(path.join(dependencyAndroidSourcePath, 'src', 'main', 'java', ...packageId.split('.')))
const packageName = packageDirFiles.find((filename) => filename.endsWith('Package.java'))!.replace('.java', '')
const mainApplicationJavaPath = path.join(options.projectPath, 'app', 'src', 'main', 'java', 'com', 'rebox', 'MainApplication.java')
let mainApplicationJavaData = await readFile(mainApplicationJavaPath, { encoding: 'utf8' })
Expand Down
1 change: 1 addition & 0 deletions packages/rebox/ios/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use_frameworks!
platform :ios, '9.0'

target 'rebox' do
Expand Down

0 comments on commit 0054ea1

Please sign in to comment.