Skip to content

Commit 763ce02

Browse files
authored
Merge pull request #66 from JorgeQuevedoC/feature/mapbox-sdk-2.0
Upgrade Mapbox SDK 2.0
2 parents 3c0088f + dda1ecc commit 763ce02

File tree

77 files changed

+14738
-5958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+14738
-5958
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ Build Settings Screenshot 2
8080

8181
</details>
8282

83-
Place your public token in your Xcode project's `Info.plist` and add a `MGLMapboxAccessToken` key whose value is your public access token.
83+
Place your public token in your Xcode project's `Info.plist` and add a `MBXAccessToken` key whose value is your public access token.
84+
85+
NOTE: `MGLMapboxAccessToken` is deprecated, now you should use `MBXAccessToken` instead
8486

8587
Add the `UIBackgroundModes` key to `Info.plist` with `audio` and `location` if it is not already present. This will allow your app to deliver audible instructions while it is in the background or the device is locked.
8688

@@ -235,9 +237,9 @@ For more information you can read the [docs provided by Mapbox](https://docs.map
235237
## Usage
236238

237239
```jsx
238-
import * as React from 'react';
239-
import { StyleSheet, View } from 'react-native';
240-
import MapboxNavigation from '@homee/react-native-mapbox-navigation';
240+
import * as React from "react";
241+
import { StyleSheet, View } from "react-native";
242+
import MapboxNavigation from "@homee/react-native-mapbox-navigation";
241243

242244
export const SomeComponent = () => {
243245
return (
@@ -299,7 +301,7 @@ Boolean that controls route simulation. Set this as `true` to auto navigate whic
299301

300302
#### `showsEndOfRouteFeedback`
301303

302-
Boolean that controls showing the end of route feedback UI when the route controller arrives at the final destination. Defaults to `false`.
304+
Boolean that controls showing the end of route feedback UI when the route controller arrives at the final destination. Defaults to `false`. Currently this prop is only available for iOS as the Android Mapbox SDK does not support drop-in UI for this functionality. Will need to implement this manually in Android.
303305

304306
#### `mute`
305307

android/build.gradle

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
// https://www.cognizantsoftvision.com/blog/creating-an-android-native-module-for-react-native/
1414

15-
def DEFAULT_COMPILE_SDK_VERSION = 28
16-
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
17-
def DEFAULT_MIN_SDK_VERSION = 19
18-
def DEFAULT_TARGET_SDK_VERSION = 28
15+
def DEFAULT_COMPILE_SDK_VERSION = 30
16+
def DEFAULT_BUILD_TOOLS_VERSION = '30.0.2'
17+
def DEFAULT_MIN_SDK_VERSION = 21
18+
def DEFAULT_TARGET_SDK_VERSION = 30
1919

2020
def safeExtGet(prop, fallback) {
2121
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626
apply plugin: 'maven'
2727

2828
buildscript {
29-
ext.kotlin_version = '1.4.10'
29+
ext.kotlin_version = '1.5.21'
3030
// The Android Gradle plugin is only required when opening the android folder stand-alone.
3131
// This avoids unnecessary downloads and potential conflicts when the library is included as a
3232
// module dependency in an application project.
@@ -37,7 +37,7 @@ buildscript {
3737
jcenter()
3838
}
3939
dependencies {
40-
classpath 'com.android.tools.build:gradle:3.4.1'
40+
classpath 'com.android.tools.build:gradle:4.2.2'
4141
}
4242
}
4343

@@ -73,6 +73,9 @@ android {
7373
kotlinOptions {
7474
jvmTarget = "1.8"
7575
}
76+
buildFeatures {
77+
viewBinding true
78+
}
7679
}
7780

7881
repositories {
@@ -93,9 +96,10 @@ repositories {
9396
dependencies {
9497
//noinspection GradleDynamicVersion
9598
implementation 'com.facebook.react:react-native:+' // From node_modules
96-
implementation 'com.mapbox.navigation:core:1.5.0'
97-
implementation 'com.mapbox.navigation:ui:1.5.0'
99+
implementation "com.mapbox.navigation:android:2.0.0"
98100
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
101+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
102+
implementation 'androidx.cardview:cardview:1.0.0'
99103
}
100104

101105
def configureReactNativePom(def pom) {
@@ -130,12 +134,10 @@ afterEvaluate { project ->
130134
}
131135

132136
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
133-
classifier = 'javadoc'
134137
from androidJavadoc.destinationDir
135138
}
136139

137140
task androidSourcesJar(type: Jar) {
138-
classifier = 'sources'
139141
from android.sourceSets.main.java.srcDirs
140142
include '**/*.java'
141143
}

android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationManager.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ import com.facebook.react.uimanager.SimpleViewManager
88
import com.facebook.react.uimanager.ThemedReactContext
99
import com.facebook.react.uimanager.annotations.ReactProp
1010
import com.mapbox.geojson.Point
11-
import com.mapbox.mapboxsdk.Mapbox
11+
import com.mapbox.maps.ResourceOptionsManager
12+
import com.mapbox.maps.TileStoreUsageMode
1213
import javax.annotation.Nonnull
1314

1415
class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : SimpleViewManager<MapboxNavigationView>() {
16+
private var accessToken: String? = null
17+
1518
init {
1619
mCallerContext.runOnUiQueueThread {
1720
try {
1821
val app = mCallerContext.packageManager.getApplicationInfo(mCallerContext.packageName, PackageManager.GET_META_DATA)
1922
val bundle = app.metaData
2023
val accessToken = bundle.getString("MAPBOX_ACCESS_TOKEN")
21-
Mapbox.getInstance(mCallerContext, accessToken)
24+
this.accessToken = accessToken
25+
ResourceOptionsManager.getDefault(mCallerContext, accessToken).update {
26+
tileStoreUsageMode(TileStoreUsageMode.READ_ONLY)
27+
}
2228
} catch (e: PackageManager.NameNotFoundException) {
2329
e.printStackTrace()
2430
}
@@ -30,7 +36,7 @@ class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : Sim
3036
}
3137

3238
public override fun createViewInstance(@Nonnull reactContext: ThemedReactContext): MapboxNavigationView {
33-
return MapboxNavigationView(reactContext)
39+
return MapboxNavigationView(reactContext, this.accessToken)
3440
}
3541

3642
override fun onDropViewInstance(view: MapboxNavigationView) {
@@ -78,10 +84,6 @@ class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : Sim
7884

7985
@ReactProp(name = "mute")
8086
fun setMute(view: MapboxNavigationView, mute: Boolean) {
81-
val isMuted = view.isVoiceGuidanceMuted()
82-
if (mute != isMuted) {
83-
view.toggleMute()
84-
}
8587
view.setMute(mute)
8688
}
8789
}

0 commit comments

Comments
 (0)