Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supporting apps that have enabled New Architecture #481

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.facebook.react.uimanager.events.EventDispatcher;
import com.maplibre.rctmln.events.IEvent;

import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.common.UIManagerType;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -45,7 +48,8 @@ public void handleEvent(IEvent event) {

@Override
protected void addEventEmitters(ThemedReactContext context, @Nonnull T view) {
mEventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher();
// Replace deprecated UIManagerModule with UIManager (via UIManagerHelper)
mEventDispatcher = UIManagerHelper.getUIManager(context, UIManagerType.FABRIC).getEventDispatcher();
}

@Nullable
Expand Down
8 changes: 6 additions & 2 deletions javascript/components/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
useMemo,
useRef,
} from "react";
import { NativeModules, requireNativeComponent, ViewProps } from "react-native";
import { NativeModules, Platform, requireNativeComponent, ViewProps } from "react-native";

Check warning on line 11 in javascript/components/Camera.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

Replace `·NativeModules,·Platform,·requireNativeComponent,·ViewProps·` with `⏎··NativeModules,⏎··Platform,⏎··requireNativeComponent,⏎··ViewProps,⏎`

import { useNativeRef } from "../hooks/useNativeRef";
import { MaplibreGLEvent } from "../types";
import { makeNativeBounds } from "../utils/makeNativeBounds";

const MapLibreGL = NativeModules.MLNModule;
// Android cannot access the MLNModule for some reason, so we need to access the RCTMLNModule directly
const MapLibreGL = Platform.select({
ios: NativeModules.MLNModule,
android: NativeModules.RCTMLNModule,
});

export const NATIVE_MODULE_NAME = "RCTMLNCamera";

Expand Down
8 changes: 7 additions & 1 deletion javascript/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ViewProps,
NativeMethods,
NativeSyntheticEvent,
Platform,
} from "react-native";

import useNativeBridge from "../hooks/useNativeBridge";
Expand All @@ -30,7 +31,12 @@ import Logger from "../utils/Logger";
import { FilterExpression } from "../utils/MaplibreStyles";
import { getFilter } from "../utils/filterUtils";

const MapLibreGL = NativeModules.MLNModule;
// Android cannot access the MLNModule for some reason, so we need to access the RCTMLNModule directly
const MapLibreGL = Platform.select({
ios: NativeModules.MLNModule,
android: NativeModules.RCTMLNModule,
});

if (MapLibreGL == null) {
console.error(
"Native module of @maplibre/maplibre-react-native library was not registered properly, please consult the docs: https://github.com/maplibre/maplibre-react-native",
Expand Down
8 changes: 4 additions & 4 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"@react-native-masked-view/masked-view": "^0.3.1",
"react": "18.2.0",
"react-native": ">=0.74.0",
"react-native-gesture-handler": "^2.20.0",
"react-native-gesture-handler": "^2.16.1",
"react-native-safe-area-context": "^4.11.1",
"react-native-screens": "^3.34.0"
"react-native-screens": "^3.31.0"
},
"dependencies": {
"@mapbox/geo-viewport": "^0.5.0",
Expand All @@ -38,9 +38,9 @@
"@types/react": "^18.2.61",
"react": "18.2.0",
"react-native": "^0.74.6",
"react-native-gesture-handler": "^2.20.0",
"react-native-gesture-handler": "^2.16.1",
"react-native-safe-area-context": "^4.11.1",
"react-native-screens": "^3.34.0",
"react-native-screens": "^3.31.0",
"typescript": "^5.5.3"
}
}
16 changes: 14 additions & 2 deletions packages/examples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import MapLibreGL from "@maplibre/maplibre-react-native";
import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, LogBox } from "react-native";
import {
StyleSheet,
Text,
View,
LogBox,
NativeModules,
Platform,
} from "react-native";
import { SafeAreaView, SafeAreaProvider } from "react-native-safe-area-context";
import "react-native-gesture-handler";

Expand All @@ -21,7 +28,12 @@ const styles = StyleSheet.create({
},
});

MapLibreGL.setAccessToken(null);
// Android cannot access the MLNModule for some reason, so we need to access the RCTMLNModule directly
if (Platform.OS === "android") {
NativeModules.RCTMLNModule.setAccessToken(null);
} else {
NativeModules.MLNModule.setAccessToken(null);
}

export function App() {
const [isFetchingAndroidPermission, setIsFetchingAndroidPermission] =
Expand Down
90 changes: 59 additions & 31 deletions packages/examples/src/examples/Map/ShowMap.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,76 @@
import MapLibreGL from "@maplibre/maplibre-react-native";
// import MapLibreGL from "@maplibre/maplibre-react-native";
import React, { useEffect, useState } from "react";

Check warning on line 2 in packages/examples/src/examples/Map/ShowMap.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

'useEffect' is defined but never used

Check warning on line 2 in packages/examples/src/examples/Map/ShowMap.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

'useState' is defined but never used

Check failure on line 2 in packages/examples/src/examples/Map/ShowMap.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

'useEffect' is declared but its value is never read.

Check failure on line 2 in packages/examples/src/examples/Map/ShowMap.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

'useState' is declared but its value is never read.
import { Alert } from "react-native";
import { Alert, View } from "react-native";

Check warning on line 3 in packages/examples/src/examples/Map/ShowMap.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

'Alert' is defined but never used

Check failure on line 3 in packages/examples/src/examples/Map/ShowMap.tsx

View workflow job for this annotation

GitHub Actions / lint_test_generate

'Alert' is declared but its value is never read.

import sheet from "../../styles/sheet";
import { onSortOptions } from "../../utils";
import TabBarPage from "../common/TabBarPage";
// import sheet from "../../styles/sheet";
// import { onSortOptions } from "../../utils";
// import TabBarPage from "../common/TabBarPage";

const OPTIONS = Object.keys(MapLibreGL.StyleURL)
.map((key) => {
return {
label: key,
data: (MapLibreGL.StyleURL as any)[key], // bad any, because enums
};
})
.sort(onSortOptions);
let MapLibreGL: any;
try {
console.log("Attempting to import MapLibreGL");
MapLibreGL = require("@maplibre/maplibre-react-native");
// native modules do exist on MapLibreGL, but we can't access them from the JS side for some reason
console.log("Available Native Modules:", Object.keys(MapLibreGL));
console.log("MapLibreGL import successful");
} catch (error) {
console.error("Error importing MapLibreGL:", error);
}

// const OPTIONS = Object.keys(MapLibreGL)
// .map((key) => {
// return {
// label: key,
// data: (MapLibreGL as any)[key], // bad any, because enums
// };
// })
// .sort(onSortOptions);

export default function ShowMap() {
const [styleURL, setStyleURL] = useState(OPTIONS[0].data);
// const [styleURL, setStyleURL] = useState(OPTIONS[0].data);

useEffect(() => {
MapLibreGL.locationManager.start();
// useEffect(() => {
// MapLibreGL.locationManager.start();

return (): void => {
MapLibreGL.locationManager.stop();
};
}, []);
// return (): void => {
// MapLibreGL.locationManager.stop();
// };
// }, []);

return (
<TabBarPage
scrollable
options={OPTIONS}
onOptionPress={(index, data): void => {
setStyleURL(data);
// <TabBarPage
// scrollable
// options={OPTIONS}
// onOptionPress={(index, data): void => {
// setStyleURL(data);
// }}
// >
<View
style={{
flex: 1,
backgroundColor: "blue",
}}
>
<MapLibreGL.MapView styleURL={styleURL} style={sheet.matchParent}>
<MapLibreGL.Camera followZoomLevel={6} followUserLocation />

<MapLibreGL.UserLocation
<MapLibreGL.MapView
style={{
flex: 1,
alignSelf: "stretch",
}}
logoEnabled={false}
>
<MapLibreGL.Camera
defaultSettings={{
centerCoordinate: [-2.15761, 53.40979],
zoomLevel: 5,
}}
/>
{/* <MapLibreGL.UserLocation
onPress={() => {
Alert.alert("You pressed on the user location annotation");
}}
/>
/> */}
</MapLibreGL.MapView>
</TabBarPage>
</View>
// </TabBarPage>
);
}
11 changes: 11 additions & 0 deletions packages/expo-app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
plugins: [
["expo-dev-launcher", { launchMode: "most-recent" }],
"@maplibre/maplibre-react-native",
[
"expo-build-properties",
{
ios: {
newArchEnabled: true,
},
android: {
newArchEnabled: true,
},
},
],
],
});
7 changes: 4 additions & 3 deletions packages/expo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"@maplibre/maplibre-react-native": "workspace:*",
"@react-native-masked-view/masked-view": "^0.3.1",
"expo": "^51.0.38",
"expo-build-properties": "~0.12.5",
"expo-dev-client": "^4.0.28",
"expo-status-bar": "^1.12.1",
"react": "18.2.0",
"react-native": "^0.74.6",
"react-native-gesture-handler": "^2.20.1",
"react-native": "^0.74.5",
"react-native-gesture-handler": "~2.16.1",
"react-native-safe-area-context": "^4.11.1",
"react-native-screens": "^3.34.0"
"react-native-screens": "3.31.1"
},
"devDependencies": {
"@babel/core": "^7.25.8"
Expand Down
Loading
Loading