Skip to content

Commit 05b217e

Browse files
committed
feat: support Expo 55 in react-native-brownfield expo config plugin
1 parent 8f63bf3 commit 05b217e

5 files changed

Lines changed: 66 additions & 7 deletions

File tree

packages/react-native-brownfield/src/expo-config-plugin/android/withAndroidModuleFiles.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
} from '../types';
1010
import { Logger } from '../logging';
1111
import { renderTemplate } from '../template/engine';
12+
import { getExpoInfo } from '../expoUtils';
1213

1314
/**
1415
* Creates the Android library module directory structure and files
@@ -17,7 +18,13 @@ export function createAndroidModule({
1718
androidDir,
1819
config,
1920
rnVersion,
21+
isExpoPre55,
2022
}: {
23+
/**
24+
* Whether the Expo project is pre-55
25+
*/
26+
isExpoPre55: boolean;
27+
2128
/**
2229
* The root Android directory path
2330
*/
@@ -62,9 +69,15 @@ export function createAndroidModule({
6269
},
6370
{
6471
relativePath: `src/main/java/${config.android.packageName.replace(/\./g, '/')}/ReactNativeHostManager.kt`,
65-
content: renderTemplate('android', 'ReactNativeHostManager.kt', {
66-
'{{PACKAGE_NAME}}': android.packageName,
67-
}),
72+
content: renderTemplate(
73+
'android',
74+
isExpoPre55
75+
? 'ReactNativeHostManager-pre55.kt'
76+
: 'ReactNativeHostManager-post55.kt',
77+
{
78+
'{{PACKAGE_NAME}}': android.packageName,
79+
}
80+
),
6881
},
6982
{
7083
relativePath: 'consumer-rules.pro',
@@ -127,10 +140,13 @@ export const withAndroidModuleFiles: ConfigPlugin<
127140
);
128141
}
129142

143+
const { isExpoPre55 } = getExpoInfo(config);
144+
130145
createAndroidModule({
131146
androidDir,
132147
config: props,
133148
rnVersion,
149+
isExpoPre55,
134150
});
135151

136152
return dangerousConfig;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { ExpoConfig } from '@expo/config-types';
2+
3+
export function getExpoInfo(config: ExpoConfig) {
4+
const expoMajor = config.sdkVersion
5+
? parseInt(config.sdkVersion.split('.')[0], 10)
6+
: -1;
7+
const isExpoPre55 = expoMajor < 55;
8+
return {
9+
expoMajor,
10+
isExpoPre55,
11+
};
12+
}

packages/react-native-brownfield/src/expo-config-plugin/ios/withBrownfieldIos.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { modifyPodfile } from './podfileHelpers';
1414
import { withIosFrameworkFiles } from './withIosFrameworkFiles';
1515
import type { ResolvedBrownfieldPluginConfigWithIos } from '../types';
1616
import { Logger } from '../logging';
17+
import { getExpoInfo } from '../expoUtils';
1718

1819
/**
1920
* iOS Config Plugin for integration with @callstack/react-native-brownfield.
@@ -28,10 +29,8 @@ import { Logger } from '../logging';
2829
export const withBrownfieldIos: ConfigPlugin<
2930
ResolvedBrownfieldPluginConfigWithIos
3031
> = (config, props) => {
31-
const expoMajor = config.sdkVersion
32-
? parseInt(config.sdkVersion.split('.')[0], 10)
33-
: -1;
34-
const isExpoPre55 = expoMajor < 55;
32+
const { isExpoPre55 } = getExpoInfo(config);
33+
3534
// Step 1: modify the Xcode project to add framework target &
3635
config = withXcodeProject(config, (xcodeConfig) => {
3736
const { modResults: project, modRequest } = xcodeConfig;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package {{PACKAGE_NAME}}
2+
3+
import android.app.Application
4+
import android.content.res.Configuration
5+
import com.callstack.reactnativebrownfield.OnJSBundleLoaded
6+
import com.callstack.reactnativebrownfield.ReactNativeBrownfield
7+
import com.facebook.react.PackageList
8+
import com.facebook.react.ReactHost
9+
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
10+
import expo.modules.ApplicationLifecycleDispatcher
11+
import expo.modules.ExpoReactHostFactory
12+
13+
object ReactNativeHostManager {
14+
fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
15+
loadReactNative(application)
16+
17+
ApplicationLifecycleDispatcher.onApplicationCreate(application)
18+
19+
val reactHost: ReactHost by lazy {
20+
ExpoReactHostFactory.getDefaultReactHost(
21+
context = application.applicationContext,
22+
packageList = PackageList(application).packages,
23+
)
24+
}
25+
26+
ReactNativeBrownfield.initialize(application, reactHost, onJSBundleLoaded)
27+
}
28+
29+
fun onConfigurationChanged(application: Application, newConfig: Configuration) {
30+
ApplicationLifecycleDispatcher.onConfigurationChanged(application, newConfig)
31+
}
32+
}

packages/react-native-brownfield/src/expo-config-plugin/template/android/ReactNativeHostManager.kt renamed to packages/react-native-brownfield/src/expo-config-plugin/template/android/ReactNativeHostManager-pre55.kt

File renamed without changes.

0 commit comments

Comments
 (0)