Skip to content

Commit

Permalink
MapLibre: allow SPM on ios, and allow full customization on gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Apr 17, 2021
1 parent ddb34e0 commit 5c21ba8
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 11 deletions.
30 changes: 20 additions & 10 deletions android/rctmgl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,31 @@ android {
}
}

def customizableDependencies(name, defaultDependencies) {
if (rootProject.ext.has(name)) {
def libs = rootProject.ext.get(name)
if (libs instanceof CharSequence) {
libs.split(';').each {
implementation it
}
} else {
libs.delegate = defaultDependencies.owner.delegate
libs.call()
}
} else {
defaultDependencies.delegate = defaultDependencies.owner.delegate
defaultDependencies.call()
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// React Native
implementation "com.facebook.react:react-native:+"

// Mapbox SDK
if (rootProject.ext.has('rnmbglMapboxLibs')) {
rootProject.ext.get('rnmbglMapboxLibs').split(';').each {
implementation it
}
} else {
customizableDependencies('rnmbglMapboxLibs') {
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0'
Expand All @@ -51,12 +64,9 @@ dependencies {
implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttpVersion', '3.12.1')}"


// Mapbox plugins
if (rootProject.ext.has('rnmbglMapboxPlugins')) {
rootProject.ext.get('rnmbglMapboxPlugins').split(';').each {
implementation it
}
} else {
customizableDependencies('rnmbglMapboxPlugins') {
implementation 'com.mapbox.mapboxsdk:mapbox-android-gestures:0.6.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v9:0.12.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v9:0.4.0'
Expand Down
28 changes: 28 additions & 0 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ buildscript {
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29

useMapLibre = false

if (useMapLibre) {
rnmbglMapboxLibs = {
implementation ("org.maplibre.gl:android-sdk:9.2.1")
implementation ("com.mapbox.mapboxsdk:mapbox-sdk-turf:5.3.0")
}

rnmbglMapboxPlugins = {
implementation ("com.mapbox.mapboxsdk:mapbox-android-gestures:0.7.0")
implementation ("com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v9:0.12.0") {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk'
}
implementation ("com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0") {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk'
}
implementation ("com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v9:0.4.0") {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk'
}
}
}
}
repositories {
google()
Expand All @@ -31,6 +53,12 @@ allprojects {
url("$rootDir/../node_modules/jsc-android/dist")
}

if (rootProject.ext.get('useMapLibre')) {
maven {
url = "https://dl.bintray.com/maplibre/maplibre-gl-native"
}
}

google()
jcenter()
maven { url 'https://jitpack.io' }
Expand Down
13 changes: 13 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ

platform :ios, '10.0'

useMapLibre = false

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

# We ingore warning except for RNMBGL
INHIBIT_WARNING_BY_DEFAULT = true

Expand Down
58 changes: 57 additions & 1 deletion react-native-mapbox-gl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,62 @@ TargetsToChangeToDynamic = ['MapboxMobileEvents']

$RNMBGL = Object.new

def $RNMBGL._add_spm_to_target(project, target, url, requirement, product_name)
pkg_class = Xcodeproj::Project::Object::XCRemoteSwiftPackageReference
ref_class = Xcodeproj::Project::Object::XCSwiftPackageProductDependency
pkg = project.root_object.package_references.find { |p| p.class == pkg_class && p.repositoryURL == url }
if !pkg
pkg = project.new(pkg_class)
pkg.repositoryURL = url
pkg.requirement = requirement
project.root_object.package_references << pkg
end
ref = target.package_product_dependencies.find { |r| r.class == ref_class && r.package == pkg && r.product_name == product_name }
if !ref
ref = project.new(ref_class)
ref.package = pkg
ref.product_name = product_name
target.package_product_dependencies << ref
end
end

def $RNMBGL.post_install(installer)
# Noop
if $RNMBGL_Use_SPM
spm_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)
spm_spec = $RNMBGL_Use_SPM
end
project = installer.pods_project
self._add_spm_to_target(
project,
project.targets.find { |t| t.name == "react-native-mapbox-gl"},
spm_spec[:url],
spm_spec[:requirement],
spm_spec[:product_name]
)

installer.aggregate_targets.group_by(&:user_project).each do |project, targets|
targets.each do |target|
target.user_targets.each do |user_target|
self._add_spm_to_target(
project,
user_target,
spm_spec[:url],
spm_spec[:requirement],
spm_spec[:product_name]
)
end
end
end
end
end

def $RNMBGL.pre_install(installer)
Expand All @@ -36,7 +90,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 5c21ba8

Please sign in to comment.