Skip to content

Commit 2922fc6

Browse files
authored
fix: view lifecycle issue (#473)
1 parent a808726 commit 2922fc6

File tree

24 files changed

+848
-386
lines changed

24 files changed

+848
-386
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
import androidx.annotation.NonNull;
1717

1818
public enum Command {
19-
CREATE_FRAGMENT(1, "createFragment"),
2019
MOVE_CAMERA(2, "moveCamera"),
2120
SET_MY_LOCATION_ENABLED(3, "setMyLocationEnabled"),
2221
SET_TRIP_PROGRESS_BAR_ENABLED(4, "setTripProgressBarEnabled"),
2322
SET_NAVIGATION_UI_ENABLED(5, "setNavigationUIEnabled"),
2423
SET_FOLLOWING_PERSPECTIVE(6, "setFollowingPerspective"),
2524
SET_NIGHT_MODE(7, "setNightMode"),
26-
DELETE_FRAGMENT(8, "deleteFragment"),
2725
SET_SPEEDOMETER_ENABLED(9, "setSpeedometerEnabled"),
2826
SET_SPEED_LIMIT_ICON_ENABLED(10, "setSpeedLimitIconEnabled"),
2927
SET_ZOOM_LEVEL(11, "setZoomLevel"),

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ public static int getMapTypeFromJsValue(int jsValue) {
9090
}
9191

9292
public static CustomTypes.FragmentType getFragmentTypeFromJsValue(int jsValue) {
93-
switch (jsValue) {
94-
case 0:
95-
default:
96-
return CustomTypes.FragmentType.MAP;
97-
case 1:
98-
return CustomTypes.FragmentType.NAVIGATION;
99-
}
93+
return switch (jsValue) {
94+
case 0 -> CustomTypes.FragmentType.MAP;
95+
case 1 -> CustomTypes.FragmentType.NAVIGATION;
96+
default -> throw new IllegalStateException("Unexpected FragmentType value: " + jsValue);
97+
};
10098
}
10199
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void initializeNavigator(
194194
}
195195

196196
private void onNavigationReady() {
197-
mNavViewManager.applyStylingOptions();
197+
mNavViewManager.onNavigationReady();
198198

199199
sendCommandToReactNative("onNavigationReady", null);
200200

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public void applyStylingOptions() {
119119

120120
public void setStylingOptions(StylingOptions stylingOptions) {
121121
mStylingOptions = stylingOptions;
122+
applyStylingOptions();
122123
}
123124

124125
public void setNightModeOption(int jsValue) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
*
4+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* <p>http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.google.android.react.navsdk;
15+
16+
import android.content.Context;
17+
import android.widget.FrameLayout;
18+
import androidx.annotation.Nullable;
19+
import com.google.android.libraries.navigation.StylingOptions;
20+
21+
public class NavViewLayout extends FrameLayout {
22+
private CustomTypes.FragmentType fragmentType;
23+
private StylingOptions stylingOptions;
24+
private boolean isFragmentCreated = false;
25+
26+
public NavViewLayout(Context context) {
27+
super(context);
28+
}
29+
30+
public void setFragmentType(CustomTypes.FragmentType type) {
31+
this.fragmentType = type;
32+
}
33+
34+
@Nullable
35+
public CustomTypes.FragmentType getFragmentType() {
36+
return this.fragmentType;
37+
}
38+
39+
public void setStylingOptions(@Nullable StylingOptions options) {
40+
this.stylingOptions = options;
41+
}
42+
43+
@Nullable
44+
public StylingOptions getStylingOptions() {
45+
return this.stylingOptions;
46+
}
47+
48+
public boolean isFragmentCreated() {
49+
return this.isFragmentCreated;
50+
}
51+
52+
public void setFragmentCreated(boolean created) {
53+
this.isFragmentCreated = created;
54+
}
55+
}

0 commit comments

Comments
 (0)