config-plugins
config-plugins copied to clipboard
feat: add react-native-maps config plugin
Why
To use google maps with react-native-maps, native code including the google maps api key needs to be included in the build.
How
This plugin was built by taking a look at the other Expo Config Plugins in this repo and copying their implementation.
Test Plan
This plugin was first implemented and tested outside of this repo by running expo prebuild with the plugin added to the list of plugins in app.config.js like this:
{
"expo": {
"plugins": [
[
"@config-plugins/react-native-maps",
{ googleMapsApiKey: "YOUR_GOOGLE_MAPS_API_KEY" }
]
]
}
}
This is the output:
App Delegate
// @generated begin react-native-maps-import - expo prebuild (DO NOT MODIFY) sync-8f65874a731887f79fac875cf4dacbb5e4f31d3a
#import <GoogleMaps/GoogleMaps.h>
// @generated end react-native-maps-import
...
// @generated begin react-native-maps-didFinishLaunchingWithOptions - expo prebuild (DO NOT MODIFY) sync-9c40b9e5696919daf2287f497d109555798aaed9
[GMSServices provideAPIKey:@"YOUR_GOOGLE_MAPS_API_KEY"];
// @generated end react-native-maps-didFinishLaunchingWithOptions
Podfile
# @generated begin react-native-maps-podfile - expo prebuild (DO NOT MODIFY) sync-8e1d9447a345393e41550db6e0a6ecd6c1d7e105
rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-google-maps', :path => rn_maps_path
# @generated end react-native-maps-podfile
I have already built this and tested that google maps works on both ios and android, so hopefully no further testing is needed.
This is included by default in Expo CLI since it was part of Expo Go when we migrated build systems. https://github.com/expo/expo/blob/8ceea398fb1a13ef70ea736f69fc9f61b15db3ff/packages/%40expo/config-plugins/src/ios/Maps.ts#L16
Just set values such as ios.config.googleMapsApiKey and it will be setup.