Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gciluffo/upgrade android sdk #1

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Build Settings Screenshot 2

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
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 @@ -237,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 @@ -301,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