diff --git a/ios/install.md b/ios/install.md index 9656a21b2..fcf6bfe09 100644 --- a/ios/install.md +++ b/ios/install.md @@ -93,6 +93,7 @@ $RNMapboxMapsUseV11 = true # use 11 version $RNMapboxMapsVersion = '= 11.0.0-beta.5' ``` +If using expo managed workflow, set the "RNMapboxMapsVersion" variable and the "RNMapboxMapsUseV11" variable to `true`. See the [expo guide](/plugin/install.md) ## Troubleshooting diff --git a/plugin/build/withMapbox.d.ts b/plugin/build/withMapbox.d.ts index 2e16827b1..8bea75622 100644 --- a/plugin/build/withMapbox.d.ts +++ b/plugin/build/withMapbox.d.ts @@ -1,16 +1,17 @@ import { ConfigPlugin } from 'expo/config-plugins'; declare type InstallerBlockName = 'pre' | 'post'; export declare type MapboxPlugProps = { - RNMapboxMapsImpl?: string; /** - * @platform ios + * @deprecated */ + RNMapboxMapsImpl?: 'mapbox'; RNMapboxMapsVersion?: string; RNMapboxMapsDownloadToken?: string; + RNMapboxMapsUseV11?: boolean; }; export declare const addInstallerBlock: (src: string, blockName: InstallerBlockName) => string; -export declare const addConstantBlock: (src: string, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, }: MapboxPlugProps) => string; -export declare const applyCocoaPodsModifications: (contents: string, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, }: MapboxPlugProps) => string; +export declare const addConstantBlock: (src: string, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, RNMapboxMapsUseV11, }: MapboxPlugProps) => string; +export declare const applyCocoaPodsModifications: (contents: string, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, RNMapboxMapsUseV11, }: MapboxPlugProps) => string; export declare const addMapboxInstallerBlock: (src: string, blockName: InstallerBlockName) => string; export declare const addMapboxMavenRepo: (src: string) => string; declare const _default: ConfigPlugin; diff --git a/plugin/build/withMapbox.js b/plugin/build/withMapbox.js index dd37d05d1..4eb98c9fe 100644 --- a/plugin/build/withMapbox.js +++ b/plugin/build/withMapbox.js @@ -46,9 +46,11 @@ const addInstallerBlock = (src, blockName) => { }).contents; }; exports.addInstallerBlock = addInstallerBlock; -const addConstantBlock = (src, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, }) => { +const addConstantBlock = (src, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, RNMapboxMapsUseV11, }) => { const tag = `@rnmapbox/maps-rnmapboxmapsimpl`; - if (RNMapboxMapsImpl == null) { + if (RNMapboxMapsVersion == null && + RNMapboxMapsDownloadToken == null && + RNMapboxMapsUseV11 == null) { const modified = (0, generateCode_1.removeGeneratedContents)(src, tag); if (!modified) { return src; @@ -57,13 +59,19 @@ const addConstantBlock = (src, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapbox return modified; } } - const newSrc = [ - `$RNMapboxMapsImpl = '${RNMapboxMapsImpl}'`, - `$RNMapboxMapsDownloadToken = '${RNMapboxMapsDownloadToken}'`, - ]; + const newSrc = []; + if (RNMapboxMapsDownloadToken) { + newSrc.push(`$RNMapboxMapsDownloadToken = '${RNMapboxMapsDownloadToken}'`); + } + if (RNMapboxMapsImpl) { + newSrc.push(`$RNMapboxMapsImpl = '${RNMapboxMapsImpl}'`); + } if (RNMapboxMapsVersion) { newSrc.push(`$RNMapboxMapsVersion = '${RNMapboxMapsVersion}'`); } + if (RNMapboxMapsUseV11) { + newSrc.push(`$RNMapboxMapsUseV11 = true`); + } return (0, generateCode_1.mergeContents)({ tag, src, @@ -77,12 +85,13 @@ const addConstantBlock = (src, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapbox exports.addConstantBlock = addConstantBlock; // Only the preinstaller block is required, the post installer block is // used for spm (swift package manager) which Expo doesn't currently support. -const applyCocoaPodsModifications = (contents, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, }) => { +const applyCocoaPodsModifications = (contents, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, RNMapboxMapsUseV11, }) => { // Ensure installer blocks exist let src = (0, exports.addConstantBlock)(contents, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }); src = (0, exports.addInstallerBlock)(src, 'pre'); src = (0, exports.addInstallerBlock)(src, 'post'); @@ -106,7 +115,7 @@ exports.addMapboxInstallerBlock = addMapboxInstallerBlock; * * https://github.com/rnmapbox/maps/blob/main/ios/install.md#react-native--0600 */ -const withCocoaPodsInstallerBlocks = (config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken }) => (0, config_plugins_1.withDangerousMod)(config, [ +const withCocoaPodsInstallerBlocks = (config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, RNMapboxMapsUseV11, }) => (0, config_plugins_1.withDangerousMod)(config, [ 'ios', async (exportedConfig) => { const file = path_1.default.join(exportedConfig.modRequest.platformProjectRoot, 'Podfile'); @@ -115,6 +124,7 @@ const withCocoaPodsInstallerBlocks = (config, { RNMapboxMapsImpl, RNMapboxMapsVe RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }), 'utf-8'); return exportedConfig; }, @@ -134,27 +144,40 @@ const withAndroidPropertiesDownloadToken = (config, { RNMapboxMapsDownloadToken } return config; }; -const withAndroidPropertiesImpl2 = (config, { RNMapboxMapsImpl }) => { - const key = 'expoRNMapboxMapsImpl'; - if (RNMapboxMapsImpl) { +const withAndroidPropertiesImpl2 = (config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsUseV11 }) => { + const keyValues = { + expoRNMapboxMapsImpl: RNMapboxMapsImpl, + expoRNMapboxMapsVersion: RNMapboxMapsVersion, + expoRNMapboxMapsUseV11: RNMapboxMapsUseV11, + }; + const keys = Object.keys(keyValues); + const values = Object.values(keyValues); + if (values.filter((v) => v).length > 0) { return (0, config_plugins_1.withGradleProperties)(config, (exportedConfig) => { - exportedConfig.modResults = exportedConfig.modResults.filter((item) => !(item.type === 'property' && item.key === key)); - exportedConfig.modResults.push({ - type: 'property', - key: key, - value: RNMapboxMapsImpl, + exportedConfig.modResults = exportedConfig.modResults.filter((item) => !(item.type === 'property' && keys.includes(item.key))); + keys.forEach((key) => { + const value = keyValues[key]; + if (value != null) { + exportedConfig.modResults.push({ + type: 'property', + key: key, + value: value.toString(), + }); + } }); return exportedConfig; }); } return config; }; -const withAndroidProperties = (config, { RNMapboxMapsImpl, RNMapboxMapsDownloadToken }) => { +const withAndroidProperties = (config, { RNMapboxMapsImpl, RNMapboxMapsDownloadToken, RNMapboxMapsVersion, RNMapboxMapsUseV11, }) => { config = withAndroidPropertiesDownloadToken(config, { RNMapboxMapsDownloadToken, }); config = withAndroidPropertiesImpl2(config, { RNMapboxMapsImpl, + RNMapboxMapsVersion, + RNMapboxMapsUseV11, }); return config; }; @@ -239,25 +262,29 @@ const withAndroidProjectGradle = (config) => (0, config_plugins_1.withProjectBui modResults.contents = (0, exports.addMapboxMavenRepo)(modResults.contents); return { modResults, ...exportedConfig }; }); -const withMapboxAndroid = (config, { RNMapboxMapsImpl, RNMapboxMapsDownloadToken }) => { +const withMapboxAndroid = (config, { RNMapboxMapsImpl, RNMapboxMapsDownloadToken, RNMapboxMapsVersion, RNMapboxMapsUseV11, }) => { config = withAndroidProperties(config, { RNMapboxMapsImpl, RNMapboxMapsDownloadToken, + RNMapboxMapsVersion, + RNMapboxMapsUseV11, }); config = withAndroidProjectGradle(config, { RNMapboxMapsImpl }); config = withAndroidAppGradle(config, { RNMapboxMapsImpl }); return config; }; -const withMapbox = (config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken }) => { +const withMapbox = (config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, RNMapboxMapsUseV11, }) => { config = withMapboxAndroid(config, { RNMapboxMapsImpl, RNMapboxMapsVersion, + RNMapboxMapsUseV11, RNMapboxMapsDownloadToken, }); config = withCocoaPodsInstallerBlocks(config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }); return config; }; diff --git a/plugin/install.md b/plugin/install.md index 5aa34559d..acbd5ce06 100644 --- a/plugin/install.md +++ b/plugin/install.md @@ -90,6 +90,26 @@ For `mapbox` or `mapbox-gl` on iOS it's possible to overwrite the native SDK ver } ``` +If using V11, on iOS, you can use property `RNMapboxMapsUseV11`, see [the ios guide](/ios/install.md): + +```json +{ + "expo": { + "plugins": [ + [ + "@rnmapbox/maps", + { + "RNMapboxMapsImpl": "mapbox", + "RNMapboxMapsVersion": "11.XX.XX", + "RNMapboxMapsDownloadToken": "sk.ey...qg", + "RNMapboxMapsUseV11": true + } + ] + ] + } +} +``` + ## Manual Setup For bare workflow projects, you can follow the manual setup guides: diff --git a/plugin/src/__tests__/__snapshots__/withMapbox-test.ts.snap b/plugin/src/__tests__/__snapshots__/withMapbox-test.ts.snap index 62964ef11..9ac29ba6e 100644 --- a/plugin/src/__tests__/__snapshots__/withMapbox-test.ts.snap +++ b/plugin/src/__tests__/__snapshots__/withMapbox-test.ts.snap @@ -396,6 +396,55 @@ end " `; +exports[`applyCocoaPodsModifications adds blocks to a react native template podfile with params 1`] = ` +" +require_relative '../node_modules/react-native/scripts/react_native_pods' +require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' + +platform :ios, '11.0' + +# @generated begin @rnmapbox/maps-rnmapboxmapsimpl - expo prebuild (DO NOT MODIFY) sync-34c61e5da1766e1b145fac98d54e353b10c6b74f +$RNMapboxMapsDownloadToken = 'pk.123' +$RNMapboxMapsVersion = '11.0.0.beta4' +$RNMapboxMapsUseV11 = true +# @generated end @rnmapbox/maps-rnmapboxmapsimpl +target 'HelloWorld' do + config = use_native_modules! + +# @generated begin pre_installer - expo prebuild (DO NOT MODIFY) sync-c8812095000d6054b846ce74840f0ffb540c2757 + pre_install do |installer| +# @generated begin @rnmapbox/maps-pre_installer - expo prebuild (DO NOT MODIFY) sync-ea4905840bf9fcea0acc62e92aa2e784f9d760f8 + $RNMapboxMaps.pre_install(installer) +# @generated end @rnmapbox/maps-pre_installer + end +# @generated end pre_installer + use_react_native!( + :path => config[:reactNativePath], + # to enable hermes on iOS, change \`false\` to \`true\` and then install pods + :hermes_enabled => false + ) + + target 'HelloWorldTests' do + inherit! :complete + # Pods for testing + end + + # Enables Flipper. + # + # Note that if you have use_frameworks! enabled, Flipper will not work and + # you should disable the next line. + use_flipper!() + + post_install do |installer| +# @generated begin @rnmapbox/maps-post_installer - expo prebuild (DO NOT MODIFY) sync-c4e8f90e96f6b6c6ea9241dd7b52ab5f57f7bf36 + $RNMapboxMaps.post_install(installer) +# @generated end @rnmapbox/maps-post_installer + react_native_post_install(installer) + end +end +" +`; + exports[`applyCocoaPodsModifications does not work with revisions to blocks after comments 1`] = ` " require_relative '../node_modules/react-native/scripts/react_native_pods' diff --git a/plugin/src/__tests__/withMapbox-test.ts b/plugin/src/__tests__/withMapbox-test.ts index abef9f2ba..29adc2aea 100644 --- a/plugin/src/__tests__/withMapbox-test.ts +++ b/plugin/src/__tests__/withMapbox-test.ts @@ -33,6 +33,15 @@ describe('applyCocoaPodsModifications', () => { applyCocoaPodsModifications(iosFixtures.reactNativeTemplatePodfile, {}), ).toMatchSnapshot(); }); + it('adds blocks to a react native template podfile with params', () => { + expect( + applyCocoaPodsModifications(iosFixtures.reactNativeTemplatePodfile, { + RNMapboxMapsUseV11: true, + RNMapboxMapsVersion: '11.0.0.beta4', + RNMapboxMapsDownloadToken: 'pk.123', + }), + ).toMatchSnapshot(); + }); it('adds blocks to a expo prebuild template podfile', () => { expect( applyCocoaPodsModifications(iosFixtures.expoTemplatePodfile, {}), diff --git a/plugin/src/withMapbox.ts b/plugin/src/withMapbox.ts index 0140b6776..f4db97d07 100644 --- a/plugin/src/withMapbox.ts +++ b/plugin/src/withMapbox.ts @@ -30,14 +30,16 @@ try { type InstallerBlockName = 'pre' | 'post'; export type MapboxPlugProps = { - RNMapboxMapsImpl?: string; - /** - * @platform ios + * @deprecated */ + RNMapboxMapsImpl?: 'mapbox'; + RNMapboxMapsVersion?: string; RNMapboxMapsDownloadToken?: string; + + RNMapboxMapsUseV11?: boolean; }; export const addInstallerBlock = ( @@ -80,11 +82,16 @@ export const addConstantBlock = ( RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }: MapboxPlugProps, ): string => { const tag = `@rnmapbox/maps-rnmapboxmapsimpl`; - if (RNMapboxMapsImpl == null) { + if ( + RNMapboxMapsVersion == null && + RNMapboxMapsDownloadToken == null && + RNMapboxMapsUseV11 == null + ) { const modified = removeGeneratedContents(src, tag); if (!modified) { return src; @@ -93,15 +100,24 @@ export const addConstantBlock = ( } } - const newSrc = [ - `$RNMapboxMapsImpl = '${RNMapboxMapsImpl}'`, - `$RNMapboxMapsDownloadToken = '${RNMapboxMapsDownloadToken}'`, - ]; + const newSrc = []; + + if (RNMapboxMapsDownloadToken) { + newSrc.push(`$RNMapboxMapsDownloadToken = '${RNMapboxMapsDownloadToken}'`); + } + + if (RNMapboxMapsImpl) { + newSrc.push(`$RNMapboxMapsImpl = '${RNMapboxMapsImpl}'`); + } if (RNMapboxMapsVersion) { newSrc.push(`$RNMapboxMapsVersion = '${RNMapboxMapsVersion}'`); } + if (RNMapboxMapsUseV11) { + newSrc.push(`$RNMapboxMapsUseV11 = true`); + } + return mergeContents({ tag, src, @@ -121,6 +137,7 @@ export const applyCocoaPodsModifications = ( RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }: MapboxPlugProps, ): string => { // Ensure installer blocks exist @@ -128,6 +145,7 @@ export const applyCocoaPodsModifications = ( RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }); src = addInstallerBlock(src, 'pre'); src = addInstallerBlock(src, 'post'); @@ -158,7 +176,12 @@ export const addMapboxInstallerBlock = ( */ const withCocoaPodsInstallerBlocks: ConfigPlugin = ( config, - { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken }, + { + RNMapboxMapsImpl, + RNMapboxMapsVersion, + RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, + }, ) => withDangerousMod(config, [ 'ios', @@ -175,6 +198,7 @@ const withCocoaPodsInstallerBlocks: ConfigPlugin = ( RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }), 'utf-8', ); @@ -209,19 +233,32 @@ const withAndroidPropertiesDownloadToken: ConfigPlugin = ( const withAndroidPropertiesImpl2: ConfigPlugin = ( config, - { RNMapboxMapsImpl }, + { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsUseV11 }, ) => { - const key = 'expoRNMapboxMapsImpl'; - - if (RNMapboxMapsImpl) { + const keyValues = { + expoRNMapboxMapsImpl: RNMapboxMapsImpl, + expoRNMapboxMapsVersion: RNMapboxMapsVersion, + expoRNMapboxMapsUseV11: RNMapboxMapsUseV11, + } as const; + type Keys = keyof typeof keyValues; + const keys = Object.keys(keyValues) as Keys[]; + const values = Object.values(keyValues); + + if (values.filter((v) => v).length > 0) { return withGradleProperties(config, (exportedConfig) => { exportedConfig.modResults = exportedConfig.modResults.filter( - (item) => !(item.type === 'property' && item.key === key), + (item) => + !(item.type === 'property' && (keys as string[]).includes(item.key)), ); - exportedConfig.modResults.push({ - type: 'property', - key: key, - value: RNMapboxMapsImpl, + keys.forEach((key) => { + const value = keyValues[key]; + if (value != null) { + exportedConfig.modResults.push({ + type: 'property', + key: key, + value: value.toString(), + }); + } }); return exportedConfig; @@ -233,13 +270,20 @@ const withAndroidPropertiesImpl2: ConfigPlugin = ( const withAndroidProperties: ConfigPlugin = ( config, - { RNMapboxMapsImpl, RNMapboxMapsDownloadToken }, + { + RNMapboxMapsImpl, + RNMapboxMapsDownloadToken, + RNMapboxMapsVersion, + RNMapboxMapsUseV11, + }, ) => { config = withAndroidPropertiesDownloadToken(config, { RNMapboxMapsDownloadToken, }); config = withAndroidPropertiesImpl2(config, { RNMapboxMapsImpl, + RNMapboxMapsVersion, + RNMapboxMapsUseV11, }); return config; @@ -361,11 +405,18 @@ const withAndroidProjectGradle: ConfigPlugin = (config) => const withMapboxAndroid: ConfigPlugin = ( config, - { RNMapboxMapsImpl, RNMapboxMapsDownloadToken }, + { + RNMapboxMapsImpl, + RNMapboxMapsDownloadToken, + RNMapboxMapsVersion, + RNMapboxMapsUseV11, + }, ) => { config = withAndroidProperties(config, { RNMapboxMapsImpl, RNMapboxMapsDownloadToken, + RNMapboxMapsVersion, + RNMapboxMapsUseV11, }); config = withAndroidProjectGradle(config, { RNMapboxMapsImpl }); config = withAndroidAppGradle(config, { RNMapboxMapsImpl }); @@ -375,17 +426,24 @@ const withMapboxAndroid: ConfigPlugin = ( const withMapbox: ConfigPlugin = ( config, - { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken }, + { + RNMapboxMapsImpl, + RNMapboxMapsVersion, + RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, + }, ) => { config = withMapboxAndroid(config, { RNMapboxMapsImpl, RNMapboxMapsVersion, + RNMapboxMapsUseV11, RNMapboxMapsDownloadToken, }); config = withCocoaPodsInstallerBlocks(config, { RNMapboxMapsImpl, RNMapboxMapsVersion, RNMapboxMapsDownloadToken, + RNMapboxMapsUseV11, }); return config;