Skip to content

Commit

Permalink
Merge pull request #66 from JorgeQuevedoC/feature/mapbox-sdk-2.0
Browse files Browse the repository at this point in the history
Upgrade Mapbox SDK 2.0
  • Loading branch information
gciluffo authored Feb 3, 2022
2 parents 3c0088f + dda1ecc commit 763ce02
Show file tree
Hide file tree
Showing 77 changed files with 14,738 additions and 5,958 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ Build Settings Screenshot 2

</details>

Place your public token in your Xcode project's `Info.plist` and add a `MGLMapboxAccessToken` key whose value is your public access token.
Place your public token in your Xcode project's `Info.plist` and add a `MBXAccessToken` key whose value is your public access token.

NOTE: `MGLMapboxAccessToken` is deprecated, now you should use `MBXAccessToken` instead

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.

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

```jsx
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import MapboxNavigation from '@homee/react-native-mapbox-navigation';
import * as React from "react";
import { StyleSheet, View } from "react-native";
import MapboxNavigation from "@homee/react-native-mapbox-navigation";

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

#### `showsEndOfRouteFeedback`

Boolean that controls showing the end of route feedback UI when the route controller arrives at the final destination. Defaults to `false`.
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.

#### `mute`

Expand Down
22 changes: 12 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

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

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 19
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_COMPILE_SDK_VERSION = 30
def DEFAULT_BUILD_TOOLS_VERSION = '30.0.2'
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 30

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

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

Expand Down Expand Up @@ -73,6 +73,9 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
viewBinding true
}
}

repositories {
Expand All @@ -93,9 +96,10 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.mapbox.navigation:core:1.5.0'
implementation 'com.mapbox.navigation:ui:1.5.0'
implementation "com.mapbox.navigation:android:2.0.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.cardview:cardview:1.0.0'
}

def configureReactNativePom(def pom) {
Expand Down Expand Up @@ -130,12 +134,10 @@ afterEvaluate { project ->
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.maps.ResourceOptionsManager
import com.mapbox.maps.TileStoreUsageMode
import javax.annotation.Nonnull

class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : SimpleViewManager<MapboxNavigationView>() {
private var accessToken: String? = null

init {
mCallerContext.runOnUiQueueThread {
try {
val app = mCallerContext.packageManager.getApplicationInfo(mCallerContext.packageName, PackageManager.GET_META_DATA)
val bundle = app.metaData
val accessToken = bundle.getString("MAPBOX_ACCESS_TOKEN")
Mapbox.getInstance(mCallerContext, accessToken)
this.accessToken = accessToken
ResourceOptionsManager.getDefault(mCallerContext, accessToken).update {
tileStoreUsageMode(TileStoreUsageMode.READ_ONLY)
}
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
Expand All @@ -30,7 +36,7 @@ class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : Sim
}

public override fun createViewInstance(@Nonnull reactContext: ThemedReactContext): MapboxNavigationView {
return MapboxNavigationView(reactContext)
return MapboxNavigationView(reactContext, this.accessToken)
}

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

@ReactProp(name = "mute")
fun setMute(view: MapboxNavigationView, mute: Boolean) {
val isMuted = view.isVoiceGuidanceMuted()
if (mute != isMuted) {
view.toggleMute()
}
view.setMute(mute)
}
}
Loading

0 comments on commit 763ce02

Please sign in to comment.