Skip to content

Commit 951e9cf

Browse files
authored
feat: support new arch through interop layer (#483)
* chore: enable new arch in expo exampe * chore: use versions from expo-doctor * fix: replace spread with Object.create * fix: replace UIManagerModule for new arch * fix: drop RCT prefix from modules * fix: add NSLocationWhenInUseUsageDescription in expo
1 parent c9c5597 commit 951e9cf

File tree

13 files changed

+260
-79
lines changed

13 files changed

+260
-79
lines changed

android/rctmln/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ def safeExtGet(prop, fallback) {
44
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
55
}
66

7+
def isNewArchitectureEnabled() {
8+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
9+
}
10+
711
android {
812
compileSdkVersion safeExtGet("compileSdkVersion", 33)
913
buildToolsVersion safeExtGet("buildToolsVersion", '33.0.1')
@@ -13,6 +17,7 @@ android {
1317
targetSdkVersion safeExtGet('targetSdkVersion', 26)
1418
versionCode 1
1519
versionName "1.0"
20+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
1621
}
1722

1823
compileOptions {

android/rctmln/src/main/java/com/maplibre/rctmln/components/AbstractEventEmitter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import android.view.ViewGroup;
44

5+
import com.maplibre.rctmln.BuildConfig;
56
import com.facebook.react.bridge.ReactApplicationContext;
67
import com.facebook.react.common.MapBuilder;
78
import com.facebook.react.uimanager.ThemedReactContext;
9+
import com.facebook.react.uimanager.UIManagerHelper;
810
import com.facebook.react.uimanager.UIManagerModule;
911
import com.facebook.react.uimanager.ViewGroupManager;
1012
import com.facebook.react.uimanager.events.EventDispatcher;
13+
import com.facebook.react.uimanager.common.UIManagerType;
14+
1115
import com.maplibre.rctmln.events.IEvent;
1216

1317
import java.util.HashMap;
@@ -45,7 +49,11 @@ public void handleEvent(IEvent event) {
4549

4650
@Override
4751
protected void addEventEmitters(ThemedReactContext context, @Nonnull T view) {
48-
mEventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher();
52+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
53+
mEventDispatcher = UIManagerHelper.getUIManager(context, UIManagerType.FABRIC).getEventDispatcher();
54+
} else {
55+
mEventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher();
56+
}
4957
}
5058

5159
@Nullable

android/rctmln/src/main/java/com/maplibre/rctmln/modules/RCTMLNLocationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
@ReactModule(name = RCTMLNLocationModule.REACT_CLASS)
2020
public class RCTMLNLocationModule extends ReactContextBaseJavaModule {
21-
public static final String REACT_CLASS = "RCTMLNLocationModule";
21+
public static final String REACT_CLASS = "MLNLocationModule";
2222
public static final String LOCATION_UPDATE = "MapboxUserLocationUpdate";
2323

2424
private boolean isEnabled;

android/rctmln/src/main/java/com/maplibre/rctmln/modules/RCTMLNLogging.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
@ReactModule(name = RCTMLNLogging.REACT_CLASS)
1515
public class RCTMLNLogging extends ReactContextBaseJavaModule {
16-
public static final String REACT_CLASS = "RCTMLNLogging";
16+
public static final String REACT_CLASS = "MLNLogging";
1717
private ReactApplicationContext mReactContext;
1818

1919
public RCTMLNLogging(ReactApplicationContext reactApplicationContext) {

android/rctmln/src/main/java/com/maplibre/rctmln/modules/RCTMLNModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
@ReactModule(name = RCTMLNModule.REACT_CLASS)
3838
public class RCTMLNModule extends ReactContextBaseJavaModule {
39-
public static final String REACT_CLASS = "RCTMLNModule";
39+
public static final String REACT_CLASS = "MLNModule";
4040

4141
private static boolean customHeaderInterceptorAdded = false;
4242

android/rctmln/src/main/java/com/maplibre/rctmln/modules/RCTMLNOfflineModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
@ReactModule(name = RCTMLNOfflineModule.REACT_CLASS)
4040
public class RCTMLNOfflineModule extends ReactContextBaseJavaModule {
41-
public static final String REACT_CLASS = "RCTMLNOfflineModule";
41+
public static final String REACT_CLASS = "MLNOfflineModule";
4242

4343
public static final int INACTIVE_REGION_DOWNLOAD_STATE = OfflineRegion.STATE_INACTIVE;
4444
public static final int ACTIVE_REGION_DOWNLOAD_STATE = OfflineRegion.STATE_ACTIVE;

android/rctmln/src/main/java/com/maplibre/rctmln/modules/RCTMLNSnapshotModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
@ReactModule(name = RCTMLNSnapshotModule.REACT_CLASS)
4242
public class RCTMLNSnapshotModule extends ReactContextBaseJavaModule {
43-
public static final String REACT_CLASS = "RCTMLNSnapshotModule";
43+
public static final String REACT_CLASS = "MLNSnapshotModule";
4444

4545
private ReactApplicationContext mContext;
4646

javascript/MLNModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface IMLNModule {
2424
setConnected(connected: boolean): void;
2525
}
2626

27-
const MLNModule: IMLNModule = { ...NativeModules.MLNModule };
27+
const MLNModule: IMLNModule = Object.create(NativeModules.MLNModule);
2828

2929
export const {
3030
StyleURL,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@babel/eslint-parser": "^7.22.9",
6464
"@babel/plugin-proposal-class-properties": "7.18.6",
6565
"@babel/runtime": "7.17.2",
66-
"@expo/config-plugins": "^7.2.5",
66+
"@expo/config-plugins": "^8.0.10",
6767
"@react-native/babel-preset": "^0.74.88",
6868
"@react-native/metro-config": "^0.74.88",
6969
"@sinonjs/fake-timers": "^11.2.2",

packages/expo-app/app.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
1515
ios: {
1616
supportsTablet: true,
1717
bundleIdentifier: "org.maplibre.expo.example",
18+
infoPlist: {
19+
NSLocationWhenInUseUsageDescription:
20+
"Permission is necessary to display user location",
21+
},
1822
},
1923
android: {
2024
adaptiveIcon: {
@@ -26,5 +30,12 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
2630
plugins: [
2731
["expo-dev-launcher", { launchMode: "most-recent" }],
2832
"@maplibre/maplibre-react-native",
33+
[
34+
"expo-build-properties",
35+
{
36+
ios: { newArchEnabled: true },
37+
android: { newArchEnabled: true },
38+
},
39+
],
2940
],
3041
});

packages/expo-app/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
"@maplibre/maplibre-react-native": "workspace:*",
1515
"@react-native-masked-view/masked-view": "^0.3.1",
1616
"expo": "^51.0.38",
17+
"expo-build-properties": "^0.12.5",
1718
"expo-dev-client": "^4.0.28",
1819
"expo-status-bar": "^1.12.1",
1920
"react": "18.2.0",
20-
"react-native": "^0.74.6",
21-
"react-native-gesture-handler": "^2.20.1",
22-
"react-native-safe-area-context": "^4.11.1",
23-
"react-native-screens": "^3.34.0"
21+
"react-native": "0.74.5",
22+
"react-native-gesture-handler": "~2.16.1",
23+
"react-native-safe-area-context": "4.10.5",
24+
"react-native-screens": "3.31.1"
2425
},
2526
"devDependencies": {
2627
"@babel/core": "^7.25.8"

packages/react-native-app/ios/MapLibreReactNativeExample/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<true/>
3333
</dict>
3434
<key>NSLocationWhenInUseUsageDescription</key>
35-
<string></string>
35+
<string>Permission is necessary to display user location</string>
3636
<key>UILaunchStoryboardName</key>
3737
<string>LaunchScreen</string>
3838
<key>UIRequiredDeviceCapabilities</key>

0 commit comments

Comments
 (0)