Skip to content

Commit

Permalink
Allow to use Mapbox or MapLibre from SPM
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Apr 14, 2021
1 parent ddb34e0 commit 1c97aaf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
9 changes: 9 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ

platform :ios, '10.0'

$RNMBGL_Use_SPM = {
url: "https://github.com/maplibre/maplibre-gl-native-distribution",
requirement: {
kind: "upToNextMajorVersion",
minimumVersion: "5.11.0"
},
product_name: "Mapbox"
}

# We ingore warning except for RNMBGL
INHIBIT_WARNING_BY_DEFAULT = true

Expand Down
21 changes: 0 additions & 21 deletions example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
13B07F8C1A680F5B00A75B9A /* Frameworks */,
13B07F8E1A680F5B00A75B9A /* Resources */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
E8948F16DF738C997C01FB08 /* [CP] Embed Pods Frameworks */,
7BC27FFD4688D6914F2322C7 /* [CP] Copy Pods Resources */,
);
buildRules = (
Expand Down Expand Up @@ -543,26 +542,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
E8948F16DF738C997C01FB08 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-frameworks.sh",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
"${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
FCA9706C7D689F287412B48F /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
44 changes: 43 additions & 1 deletion react-native-mapbox-gl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,48 @@ TargetsToChangeToDynamic = ['MapboxMobileEvents']

$RNMBGL = Object.new

def $RNMBGL._add_spm_to_target(project, target_name, url, requirement, product_name)
project.targets.each do |target|
if target.name == target_name

pkg = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
pkg.repositoryURL = url
pkg.requirement = requirement
ref = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
ref.package = pkg
ref.product_name = product_name

target.package_product_dependencies << ref

project.root_object.package_references << pkg
end
end

project.save
end

def $RNMBGL.post_install(installer)
# Noop
if $RNMBGL_Use_SPM
rpm_spec = {
url: "https://github.com/maplibre/maplibre-gl-native-distribution",
requirement: {
kind: "upToNextMajorVersion",
minimumVersion: "5.11.0"
},
product_name: "Mapbox"
}

if $RNMBGL_Use_SPM.is_a?(Hash)
rpm_spec = $RNMBGL_Use_SPM
end
self._add_spm_to_target(
installer.pods_project,
"react-native-mapbox-gl",
rpm_spec[:url],
rpm_spec[:requirement],
rpm_spec[:product_name]
)
end
end

def $RNMBGL.pre_install(installer)
Expand All @@ -36,7 +76,9 @@ Pod::Spec.new do |s|
s.license = "MIT"
s.platform = :ios, "8.0"

if !$RNMBGL_Use_SPM
s.dependency 'Mapbox-iOS-SDK', rnmbgl_ios_version
end
s.dependency 'React-Core'
s.dependency 'React'

Expand Down

0 comments on commit 1c97aaf

Please sign in to comment.