diff --git a/android/rctmgl/build.gradle b/android/rctmgl/build.gradle index 14fe2c8a3..6b88dfc42 100644 --- a/android/rctmgl/build.gradle +++ b/android/rctmgl/build.gradle @@ -28,6 +28,23 @@ 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']) @@ -35,11 +52,7 @@ dependencies { 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' @@ -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' diff --git a/example/android/build.gradle b/example/android/build.gradle index e958706c1..b64e7c856 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -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() @@ -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' } diff --git a/example/ios/Podfile b/example/ios/Podfile index 2be0e084a..33dcdab71 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -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 diff --git a/react-native-mapbox-gl.podspec b/react-native-mapbox-gl.podspec index 279a132e5..03c135b9a 100644 --- a/react-native-mapbox-gl.podspec +++ b/react-native-mapbox-gl.podspec @@ -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) @@ -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'