-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add Expo config plugin for SDK 56+ #22
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,3 +60,6 @@ jobs: | |
|
|
||
| - name: Build | ||
| run: bun run build | ||
|
|
||
| - name: Test | ||
| run: bun run --filter react-native-nitro-maps test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ dist/ | |
|
|
||
| # Build outputs | ||
| package/lib/ | ||
| package/plugin/build/ | ||
| package/nitrogen/ | ||
|
|
||
| # Expo | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Expo setup (SDK 56+) | ||
|
|
||
| This guide covers configuring `react-native-nitro-maps` in an Expo app with the New Architecture enabled. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Expo SDK 56+ | ||
| - React Native 0.78+ with New Architecture enabled (`newArchEnabled: true` in `app.json`) | ||
| - `react-native-nitro-modules` installed alongside `react-native-nitro-maps` | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| bun add react-native-nitro-maps react-native-nitro-modules | ||
| ``` | ||
|
|
||
| ## Config plugin | ||
|
|
||
| Add the plugin to `app.json` or `app.config.js`: | ||
|
|
||
| ```js | ||
| /** @type {import('expo/config').ExpoConfig} */ | ||
| module.exports = { | ||
| expo: { | ||
| // ...your existing config | ||
| plugins: [ | ||
| [ | ||
| 'react-native-nitro-maps', | ||
| { | ||
| googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY, | ||
| locationPermission: | ||
| 'Allow $(PRODUCT_NAME) to use your location for map features.', | ||
| }, | ||
| ], | ||
| ], | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| ### Plugin options | ||
|
|
||
| | Option | Type | Default | Description | | ||
| | --- | --- | --- | --- | | ||
| | `googleMapsApiKey` | `string` | — | Android: injects `com.google.android.geo.API_KEY` meta-data. iOS: no-op (MapKit needs no key; reserved for future Google Maps iOS support in [#2](https://github.com/gmi-software/react-native-nitro-maps/issues/2)). | | ||
| | `locationPermission` | `string \| false` | — | When set to a string: iOS `NSLocationWhenInUseUsageDescription` + Android `ACCESS_FINE_LOCATION` and `ACCESS_COARSE_LOCATION`. | | ||
| | `locationAlwaysPermission` | `string \| false` | — | When set to a string: iOS `NSLocationAlwaysAndWhenInUseUsageDescription` + Android `ACCESS_BACKGROUND_LOCATION`. | | ||
|
|
||
| Omitting `googleMapsApiKey` does not fail prebuild. Android maps will not render until a key is provided (via the plugin or manually). iOS MapKit works without a key. | ||
|
|
||
| ## Google Maps API key | ||
|
|
||
| ### Local development | ||
|
|
||
| Create a `.env` file (see `example/.env.example`): | ||
|
|
||
| ```dotenv | ||
| GOOGLE_MAPS_API_KEY=your-google-maps-api-key | ||
| ``` | ||
|
|
||
| Load it in `app.config.js` with `process.env.GOOGLE_MAPS_API_KEY` as shown above. | ||
|
|
||
| ### EAS Build | ||
|
|
||
| Store the key as an EAS secret: | ||
|
|
||
| ```bash | ||
| eas secret:create --name GOOGLE_MAPS_API_KEY --value your-google-maps-api-key | ||
| ``` | ||
|
|
||
| Reference it in `app.config.js` via `process.env.GOOGLE_MAPS_API_KEY`. EAS injects secrets into the build environment automatically. | ||
|
|
||
| ### Alternative: Expo built-in Google Maps config | ||
|
|
||
| You can use Expo's native `android.config.googleMaps.apiKey` instead of the plugin's `googleMapsApiKey`. Pick one source — do not configure both. | ||
|
|
||
| ## Prebuild | ||
|
|
||
| Generate native projects: | ||
|
|
||
| ```bash | ||
| expo prebuild --clean | ||
| ``` | ||
|
|
||
| The plugin injects: | ||
|
|
||
| - **Android:** `com.google.android.geo.API_KEY` meta-data (when `googleMapsApiKey` is set) and location permissions (when location options are set) | ||
| - **iOS:** location usage description strings (when location options are set) | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| expo run:android | ||
| expo run:ios | ||
| ``` | ||
|
|
||
| ## Example app | ||
|
|
||
| The monorepo example at `example/` uses this plugin. From the repo root: | ||
|
|
||
| ```bash | ||
| GOOGLE_MAPS_API_KEY=your-key bun example prebuild | ||
| GOOGLE_MAPS_API_KEY=your-key bun example android | ||
| ``` | ||
|
|
||
| The example's `prebuild` script builds the plugin (`build:plugin`) before running `expo prebuild`, since the workspace symlink requires compiled plugin output. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Symptom | Fix | | ||
| | --- | --- | | ||
| | Blank map on Android | Ensure `googleMapsApiKey` is set and `expo prebuild` was run after adding the plugin. | | ||
| | Location dot not showing | Set `locationPermission` in the plugin options and re-run prebuild. | | ||
| | Plugin not found | Confirm `react-native-nitro-maps` is installed and listed in `plugins`. | | ||
| | `Cannot find module './plugin/build/index'` | Run `bun run build:plugin` in the package (or `bun run build` from the repo root) before prebuild when using a workspace link. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1 @@ | ||
| const IOS_GOOGLE_MAPS_API_KEY = 'GoogleMapsIosApiKey'; | ||
|
|
||
| /** | ||
| * @typedef {object} NitroMapsPluginProps | ||
| * @property {string=} googleMapsApiKey Shared Google Maps API key for both platforms. | ||
| * @property {string=} iosGoogleMapsApiKey Google Maps API key for iOS. | ||
| * @property {string=} androidGoogleMapsApiKey Google Maps API key for Android. | ||
| */ | ||
|
|
||
| /** | ||
| * @param {import('expo/config').ExpoConfig} config | ||
| * @param {NitroMapsPluginProps=} props | ||
| * @returns {import('expo/config').ExpoConfig} | ||
| */ | ||
| function withNitroMaps(config, props = {}) { | ||
| const iosGoogleMapsApiKey = | ||
| props.iosGoogleMapsApiKey ?? props.googleMapsApiKey; | ||
| const androidGoogleMapsApiKey = | ||
| props.androidGoogleMapsApiKey ?? props.googleMapsApiKey; | ||
|
|
||
| if (iosGoogleMapsApiKey != null) { | ||
| config.ios = { | ||
| ...config.ios, | ||
| infoPlist: { | ||
| ...config.ios?.infoPlist, | ||
| [IOS_GOOGLE_MAPS_API_KEY]: iosGoogleMapsApiKey, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| if (androidGoogleMapsApiKey != null) { | ||
| config.android = { | ||
| ...config.android, | ||
| config: { | ||
| ...config.android?.config, | ||
| googleMaps: { | ||
| ...config.android?.config?.googleMaps, | ||
| apiKey: androidGoogleMapsApiKey, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| module.exports = withNitroMaps; | ||
| module.exports = require('./plugin/build/index').default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** @type {import('jest').Config} */ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'node', | ||
| roots: ['<rootDir>/plugin/src'], | ||
| testMatch: ['**/*.test.ts'], | ||
| moduleFileExtensions: ['ts', 'js'], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.