From 988ef998ecd177f719b63e76668fb3b820e25d57 Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Wed, 18 Sep 2024 12:40:42 +0100 Subject: [PATCH] fix react-native-screens dependencies for new arch --- scripts/generate-react-native-fixture.js | 55 +++++++++++++++++------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/scripts/generate-react-native-fixture.js b/scripts/generate-react-native-fixture.js index dc391c76d..97c2398e8 100644 --- a/scripts/generate-react-native-fixture.js +++ b/scripts/generate-react-native-fixture.js @@ -18,8 +18,10 @@ const notifierVersion = process.env.NOTIFIER_VERSION || common.determineVersion( const reactNativeVersion = process.env.RN_VERSION const ROOT_DIR = resolve(__dirname, '../') +const isNewArchEnabled = process.env.RCT_NEW_ARCH_ENABLED === 'true' || process.env.RCT_NEW_ARCH_ENABLED === '1' + let fixturePath = 'test/react-native/features/fixtures/generated/' -if (process.env.RCT_NEW_ARCH_ENABLED === '1') { +if (isNewArchEnabled) { fixturePath += 'new-arch/' } else { fixturePath += 'old-arch/' @@ -34,14 +36,6 @@ const DEPENDENCIES = [ `@bugsnag/react-native@${notifierVersion}` ] -const REACT_NAVIGATION_DEPENDENCIES = [ - `@bugsnag/plugin-react-navigation@${notifierVersion}`, - '@react-navigation/native', - '@react-navigation/native-stack', - 'react-native-screens', - 'react-native-safe-area-context' -] - if (!process.env.SKIP_GENERATE_FIXTURE) { // remove the fixture directory if it already exists if (fs.existsSync(fixtureDir)) { @@ -58,7 +52,7 @@ if (!process.env.SKIP_GENERATE_FIXTURE) { } if (process.env.BUILD_ANDROID === 'true' || process.env.BUILD_ANDROID === '1') { - if (process.env.RCT_NEW_ARCH_ENABLED === 'true' || process.env.RCT_NEW_ARCH_ENABLED === '1') { + if (isNewArchEnabled) { // If we're building with the new architecture, replace the gradle.properties file fs.copyFileSync( resolve(replacementFilesDir, 'android/newarch.gradle.properties'), @@ -113,8 +107,9 @@ if (process.env.BUILD_IOS === 'true' || process.env.BUILD_IOS === '1') { execFileSync('xcrun', exportArgs, { cwd: fixtureDir, stdio: 'inherit' }) } -function installFixtureDependencies() { - DEPENDENCIES.push(...REACT_NAVIGATION_DEPENDENCIES) +function installFixtureDependencies () { + const reactNavigationDependencies = getReactNavigationDependencies() + DEPENDENCIES.push(...reactNavigationDependencies) const fixtureDependencyArgs = DEPENDENCIES.join(' ') @@ -128,11 +123,11 @@ function installFixtureDependencies() { } /** Replace native files generated by react-native cli with pre-configured files */ -function replaceGeneratedFixtureFiles() { +function replaceGeneratedFixtureFiles () { // replace the App.js/App.tsx file with our own App.js file fs.readdirSync(resolve(fixtureDir)) - .filter((file) => /App\.[tj]sx?$/.test(file)) - .map((file) => fs.unlinkSync(resolve(fixtureDir, file))) + .filter((file) => /App\.[tj]sx?$/.test(file)) + .map((file) => fs.unlinkSync(resolve(fixtureDir, file))) fs.copyFileSync( resolve(replacementFilesDir, 'App.js'), @@ -220,4 +215,32 @@ class MainActivity : ReactActivity() { let mainActivityContents = fs.readFileSync(mainActivityPath, 'utf8') mainActivityContents = mainActivityContents.replace(mainActivityPattern, mainActivityReplacement) fs.writeFileSync(mainActivityPath, mainActivityContents) -} \ No newline at end of file +} + +function getReactNavigationDependencies () { + let reactNativeScreensVersion + switch (reactNativeVersion) { + case '0.71': + reactNativeScreensVersion = isNewArchEnabled ? '3.19.0' : '3.32.0' + break + case '0.72': + reactNativeScreensVersion = isNewArchEnabled ? '3.21.0' : '3.33.0' + break + case '0.73': + reactNativeScreensVersion = isNewArchEnabled ? '3.28.0' : '3.33.0' + break + case '0.74': + reactNativeScreensVersion = isNewArchEnabled ? '3.28.0' : '3.33.0' + break + default: + reactNativeScreensVersion = 'latest' + } + + return [ + `@bugsnag/plugin-react-navigation@${notifierVersion}`, + '@react-navigation/native', + '@react-navigation/native-stack', + `react-native-screens@${reactNativeScreensVersion}`, + 'react-native-safe-area-context' + ] +}