Skip to content

Commit ed017b6

Browse files
committed
fix: android messaging channel
1 parent 4f09ae1 commit ed017b6

File tree

18 files changed

+422
-413
lines changed

18 files changed

+422
-413
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Keys.plist
3939
.idea
4040
.project
4141
.settings
42+
.kotlin
4243
local.properties
4344
android.iml
4445

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nodejs 18.20.1
1+
nodejs 22.14.0
Lines changed: 213 additions & 213 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
nodeLinker: node-modules
1615
nmHoistingLimits: workspaces
1716

17+
nodeLinker: node-modules
18+
1819
plugins:
1920
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
20-
spec: "@yarnpkg/plugin-interactive-tools"
21+
spec: '@yarnpkg/plugin-interactive-tools'
2122
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
22-
spec: "@yarnpkg/plugin-workspace-tools"
23+
spec: '@yarnpkg/plugin-workspace-tools'
2324

24-
yarnPath: .yarn/releases/yarn-3.6.1.cjs
25+
yarnPath: .yarn/releases/yarn-3.6.4.cjs

android/build.gradle

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
66
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
7+
// http://www.apache.org/licenses/LICENSE-2.0
88
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,16 +15,16 @@
1515
import groovy.json.JsonSlurper
1616

1717
buildscript {
18-
ext.kotlin_version = '2.1.21'
19-
repositories {
20-
google()
21-
mavenCentral()
22-
}
18+
ext.kotlin_version = '2.1.21'
19+
repositories {
20+
google()
21+
mavenCentral()
22+
}
2323

24-
dependencies {
25-
classpath("com.android.tools.build:gradle:8.4.0")
26-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
27-
}
24+
dependencies {
25+
classpath "com.android.tools.build:gradle:8.7.2"
26+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
27+
}
2828
}
2929

3030
def isNewArchitectureEnabled() {
@@ -38,44 +38,50 @@ if (isNewArchitectureEnabled()) {
3838
}
3939

4040
android {
41-
namespace "com.google.android.react.navsdk"
42-
compileSdkVersion 35
41+
namespace "com.google.android.react.navsdk"
42+
compileSdkVersion 35
4343

44-
compileOptions {
45-
sourceCompatibility JavaVersion.VERSION_1_8
46-
targetCompatibility JavaVersion.VERSION_1_8
47-
}
44+
compileOptions {
45+
sourceCompatibility JavaVersion.VERSION_1_8
46+
targetCompatibility JavaVersion.VERSION_1_8
47+
}
4848

49-
defaultConfig {
50-
minSdkVersion 24
51-
targetSdkVersion 34
52-
versionCode 1
53-
// get version name from package.json version
54-
versionName "1.0"
55-
}
49+
defaultConfig {
50+
minSdkVersion 24
51+
targetSdkVersion 34
52+
}
5653

57-
buildTypes {
58-
release {
59-
minifyEnabled true
60-
}
61-
}
54+
buildFeatures {
55+
buildConfig true
56+
}
6257

63-
lintOptions {
64-
abortOnError false
65-
disable "GradleCompatible"
58+
buildTypes {
59+
release {
60+
minifyEnabled true
6661
}
62+
}
63+
64+
lintOptions {
65+
abortOnError false
66+
disable "GradleCompatible"
67+
}
68+
69+
compileOptions {
70+
sourceCompatibility JavaVersion.VERSION_1_8
71+
targetCompatibility JavaVersion.VERSION_1_8
72+
}
6773
}
6874

6975
repositories {
70-
google()
71-
mavenCentral()
76+
google()
77+
mavenCentral()
7278
}
7379

7480
dependencies {
75-
implementation "androidx.car.app:app:1.4.0"
76-
implementation "androidx.car.app:app-projected:1.4.0"
77-
implementation 'com.facebook.react:react-native:+'
78-
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
79-
implementation "com.google.android.libraries.navigation:navigation:6.3.1"
80-
api 'com.google.guava:guava:31.0.1-android'
81+
implementation 'com.facebook.react:react-native:+'
82+
implementation "androidx.car.app:app:1.4.0"
83+
implementation "androidx.car.app:app-projected:1.4.0"
84+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
85+
implementation "com.google.android.libraries.navigation:navigation:6.3.1"
86+
api 'com.google.guava:guava:31.0.1-android'
8187
}

android/src/main/java/com/google/android/react/navsdk/Constants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
package com.google.android.react.navsdk;
1515

1616
public class Constants {
17-
public static final String NAV_JAVASCRIPT_FLAG = "NavJavascriptBridge";
18-
public static final String NAV_AUTO_JAVASCRIPT_FLAG = "NavAutoJavascriptBridge";
1917
public static final String LAT_FIELD_KEY = "lat";
2018
public static final String LNG_FIELD_KEY = "lng";
2119
}

android/src/main/java/com/google/android/react/navsdk/MapViewController.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,10 @@ public GroundOverlay addGroundOverlay(Map<String, Object> map) {
284284
Double lng = null;
285285
if (map.containsKey("location")) {
286286
Map<String, Object> latlng = (Map<String, Object>) map.get("location");
287-
if (latlng.get("lat") != null) lat = Double.parseDouble(latlng.get("lat").toString());
288-
if (latlng.get("lng") != null) lng = Double.parseDouble(latlng.get("lng").toString());
287+
if (latlng.get(Constants.LAT_FIELD_KEY) != null)
288+
lat = Double.parseDouble(latlng.get(Constants.LAT_FIELD_KEY).toString());
289+
if (latlng.get(Constants.LNG_FIELD_KEY) != null)
290+
lng = Double.parseDouble(latlng.get(Constants.LNG_FIELD_KEY).toString());
289291
}
290292

291293
GroundOverlayOptions options = new GroundOverlayOptions();
@@ -568,9 +570,11 @@ private String fetchJsonFromUrl(String urlString) throws IOException {
568570
private LatLng createLatLng(Map<String, Object> map) {
569571
Double lat = null;
570572
Double lng = null;
571-
if (map.containsKey("lat") && map.containsKey("lng")) {
572-
if (map.get("lat") != null) lat = Double.parseDouble(map.get("lat").toString());
573-
if (map.get("lng") != null) lng = Double.parseDouble(map.get("lng").toString());
573+
if (map.containsKey(Constants.LAT_FIELD_KEY) && map.containsKey(Constants.LNG_FIELD_KEY)) {
574+
if (map.get(Constants.LAT_FIELD_KEY) != null)
575+
lat = Double.parseDouble(map.get(Constants.LAT_FIELD_KEY).toString());
576+
if (map.get(Constants.LNG_FIELD_KEY) != null)
577+
lng = Double.parseDouble(map.get(Constants.LNG_FIELD_KEY).toString());
574578
}
575579

576580
return new LatLng(lat, lng);

android/src/main/java/com/google/android/react/navsdk/NavAutoModule.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
package com.google.android.react.navsdk;
1515

1616
import android.location.Location;
17+
import androidx.annotation.NonNull;
18+
import androidx.annotation.Nullable;
1719
import com.facebook.react.bridge.Arguments;
18-
import com.facebook.react.bridge.CatalystInstance;
19-
import com.facebook.react.bridge.NativeArray;
2020
import com.facebook.react.bridge.Promise;
2121
import com.facebook.react.bridge.ReactApplicationContext;
22-
import com.facebook.react.bridge.ReactContext;
2322
import com.facebook.react.bridge.ReactContextBaseJavaModule;
2423
import com.facebook.react.bridge.ReactMethod;
2524
import com.facebook.react.bridge.ReadableMap;
2625
import com.facebook.react.bridge.UiThreadUtil;
2726
import com.facebook.react.bridge.WritableMap;
2827
import com.facebook.react.bridge.WritableNativeArray;
28+
import com.facebook.react.modules.core.DeviceEventManagerModule;
2929
import com.google.android.gms.maps.UiSettings;
3030
import com.google.android.gms.maps.model.CameraPosition;
3131
import com.google.android.gms.maps.model.Circle;
@@ -34,15 +34,13 @@
3434
import com.google.android.gms.maps.model.Polygon;
3535
import com.google.android.gms.maps.model.Polyline;
3636
import com.google.android.libraries.navigation.StylingOptions;
37-
import java.util.Map;
3837

3938
/**
40-
* This exposes a series of methods that can be called diretly from the React Native code. They have
41-
* been implemented using promises as it's not recommended for them to be synchronous.
39+
* This exposes a series of methods that can be called directly from the React Native code. They
40+
* have been implemented using promises as it's not recommended for them to be synchronous.
4241
*/
4342
public class NavAutoModule extends ReactContextBaseJavaModule implements INavigationAutoCallback {
4443
public static final String REACT_CLASS = "NavAutoModule";
45-
private static final String TAG = "AndroidAutoModule";
4644
private static NavAutoModule instance;
4745
private static ModuleReadyListener moduleReadyListener;
4846

@@ -64,6 +62,7 @@ public NavAutoModule(ReactApplicationContext reactContext) {
6462
}
6563
}
6664

65+
@NonNull
6766
@Override
6867
public String getName() {
6968
return REACT_CLASS;
@@ -100,13 +99,6 @@ public void androidAutoNavigationScreenDisposed() {
10099
mNavigationViewController = null;
101100
}
102101

103-
public void setStylingOptions(Map<String, Object> stylingOptions) {
104-
mStylingOptions = new StylingOptionsBuilder.Builder(stylingOptions).build();
105-
if (mStylingOptions != null && mNavigationViewController != null) {
106-
mNavigationViewController.setStylingOptions(mStylingOptions);
107-
}
108-
}
109-
110102
@ReactMethod
111103
public void setMapType(int jsValue) {
112104
UiThreadUtil.runOnUiThread(
@@ -408,11 +400,6 @@ public void getCameraPosition(final Promise promise) {
408400

409401
CameraPosition cp = mMapViewController.getGoogleMap().getCameraPosition();
410402

411-
if (cp == null) {
412-
promise.resolve(null);
413-
return;
414-
}
415-
416403
LatLng target = cp.target;
417404
WritableMap map = Arguments.createMap();
418405
map.putDouble("bearing", cp.bearing);
@@ -438,7 +425,6 @@ public void getMyLocation(final Promise promise) {
438425
promise.resolve(ObjectTranslationUtil.getMapFromLocation(location));
439426
} catch (Exception e) {
440427
promise.resolve(null);
441-
return;
442428
}
443429
});
444430
}
@@ -539,12 +525,11 @@ public void onCustomNavigationAutoEvent(String type, ReadableMap data) {
539525
}
540526

541527
/** Send command to react native. */
542-
private void sendCommandToReactNative(String functionName, NativeArray params) {
543-
ReactContext reactContext = getReactApplicationContext();
544-
545-
if (reactContext != null) {
546-
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
547-
catalystInstance.callFunction(Constants.NAV_AUTO_JAVASCRIPT_FLAG, functionName, params);
528+
private void sendCommandToReactNative(String functionName, @Nullable Object params) {
529+
if (reactContext.hasActiveReactInstance()) {
530+
reactContext
531+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
532+
.emit(functionName, params);
548533
}
549534
}
550535
}

0 commit comments

Comments
 (0)