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: Add expo plugin property for v11 on iOS #3125

Merged
merged 4 commits into from
Oct 20, 2023
Merged
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
1 change: 1 addition & 0 deletions ios/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ $RNMapboxMapsUseV11 = true # use 11 version
$RNMapboxMapsVersion = '= 11.0.0-beta.3'
```

If using expo managed workflow, set the "RNMapboxMapsVersion" variable and the "RNMapboxMapsUseV11" variable to `true`. See the [expo guide](/plugin/install.md)

## Troubleshooting

Expand Down
9 changes: 5 additions & 4 deletions plugin/build/withMapbox.d.ts
Original file line number Diff line number Diff line change
@@ -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<MapboxPlugProps>;
Expand Down
65 changes: 46 additions & 19 deletions plugin/build/withMapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -115,6 +124,7 @@ const withCocoaPodsInstallerBlocks = (config, { RNMapboxMapsImpl, RNMapboxMapsVe
RNMapboxMapsImpl,
RNMapboxMapsVersion,
RNMapboxMapsDownloadToken,
RNMapboxMapsUseV11,
}), 'utf-8');
return exportedConfig;
},
Expand All @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down
20 changes: 20 additions & 0 deletions plugin/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
49 changes: 49 additions & 0 deletions plugin/src/__tests__/__snapshots__/withMapbox-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 9 additions & 0 deletions plugin/src/__tests__/withMapbox-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}),
Expand Down
Loading
Loading