Skip to content

Commit d301b97

Browse files
Seth BourgetSeth Bourget
andauthored
When initialize layers methods are called the existing layers are removed so that new options will take effect. (#6466) (#6816)
Co-authored-by: Seth Bourget <[email protected]> Co-authored-by: Seth Bourget <[email protected]>
1 parent 375fb27 commit d301b97

File tree

10 files changed

+206
-31
lines changed

10 files changed

+206
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone.
77
#### Bug fixes and improvements
88
- Fixed an issue with `NavigationView` that caused info panel to shrink in landscape mode with a full screen theme. [#6811](https://github.com/mapbox/mapbox-navigation-android/pull/6811)
99
- Fixed standalone `MapboxManeuverView` appearance when the app also integrates Drop-In UI. [#6810](https://github.com/mapbox/mapbox-navigation-android/pull/6810)
10+
- Each newly instantiated MapboxRouteArrowView class will initialize the layers with the provided options on the first render call. Previously this would only be done if the layers hadn't already been initialized. [#6466](https://github.com/mapbox/mapbox-navigation-android/pull/6466)
1011

1112
## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022
1213
### Changelog
@@ -31,7 +32,6 @@ This release depends on, and has been tested with, the following Mapbox dependen
3132
- Mapbox Core Common `v23.2.1`
3233
- Mapbox Java `v6.10.0-beta.3` ([release notes](https://github.com/mapbox/mapbox-java/releases/tag/v6.10.0-beta.3))
3334

34-
3535
## Mapbox Navigation SDK 2.9.5 - 13 December, 2022
3636
### Changelog
3737
[Changes between v2.9.4 and v2.9.5](https://github.com/mapbox/mapbox-navigation-android/compare/v2.9.4...v2.9.5)
@@ -223,7 +223,6 @@ This release depends on, and has been tested with, the following Mapbox dependen
223223
- Mapbox Java `v6.9.0` ([release notes](https://github.com/mapbox/mapbox-java/releases/tag/v6.9.0))
224224
- Mapbox Android Core `v5.0.2` ([release notes](https://github.com/mapbox/mapbox-events-android/releases/tag/core-5.0.2))
225225

226-
227226
## Mapbox Navigation SDK 2.9.2 - 18 November, 2022
228227
### Changelog
229228
[Changes between v2.9.1 and v2.9.2](https://github.com/mapbox/mapbox-navigation-android/compare/v2.9.1...v2.9.2)
@@ -552,7 +551,6 @@ This release depends on, and has been tested with, the following Mapbox dependen
552551
- Mapbox Java `v6.8.0` ([release notes](https://github.com/mapbox/mapbox-java/releases/tag/v6.8.0))
553552
- Mapbox Android Core `v5.0.2` ([release notes](https://github.com/mapbox/mapbox-events-android/releases/tag/core-5.0.2))
554553

555-
556554
## Mapbox Navigation SDK 2.9.0-beta.2 - 14 October, 2022
557555
### Changelog
558556
[Changes between v2.9.0-beta.1 and v2.9.0-beta.2](https://github.com/mapbox/mapbox-navigation-android/compare/v2.9.0-beta.1...v2.9.0-beta.2)
@@ -597,7 +595,6 @@ This release depends on, and has been tested with, the following Mapbox dependen
597595
- Mapbox Java `v6.8.0` ([release notes](https://github.com/mapbox/mapbox-java/releases/tag/v6.8.0))
598596
- Mapbox Android Core `v5.0.2` ([release notes](https://github.com/mapbox/mapbox-events-android/releases/tag/core-5.0.2))
599597

600-
601598
## Mapbox Navigation SDK 2.9.0-beta.1 - 06 October, 2022
602599
### Changelog
603600
[Changes between v2.9.0-alpha.4 and v2.9.0-beta.1](https://github.com/mapbox/mapbox-navigation-android/compare/v2.9.0-alpha.4...v2.9.0-beta.1)

libnavui-maps/api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ package com.mapbox.navigation.ui.maps.route.line.api {
10171017
method public void renderClearRouteLineValue(com.mapbox.maps.Style style, com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteLineClearValue> clearRouteLineValue);
10181018
method public void renderRouteDrawData(com.mapbox.maps.Style style, com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteSetValue> routeDrawData);
10191019
method public void renderRouteLineUpdate(com.mapbox.maps.Style style, com.mapbox.bindgen.Expected<com.mapbox.navigation.ui.maps.route.line.model.RouteLineError,com.mapbox.navigation.ui.maps.route.line.model.RouteLineUpdateValue> update);
1020-
method public void setOptions(com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineOptions);
1020+
method @Deprecated public void setOptions(com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineOptions);
10211021
method public void showAlternativeRoutes(com.mapbox.maps.Style style);
10221022
method public void showOriginAndDestinationPoints(com.mapbox.maps.Style style);
10231023
method public void showPrimaryRoute(com.mapbox.maps.Style style);

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/ui/RouteArrowComponent.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.mapbox.navigation.core.MapboxNavigation
55
import com.mapbox.navigation.core.internal.extensions.flowRouteProgress
66
import com.mapbox.navigation.core.internal.extensions.flowRoutesUpdated
77
import com.mapbox.navigation.ui.base.lifecycle.UIComponent
8-
import com.mapbox.navigation.ui.maps.route.arrow.RouteArrowUtils
98
import com.mapbox.navigation.ui.maps.route.arrow.api.MapboxRouteArrowApi
109
import com.mapbox.navigation.ui.maps.route.arrow.api.MapboxRouteArrowView
1110
import com.mapbox.navigation.ui.maps.route.arrow.model.RouteArrowOptions
@@ -44,7 +43,6 @@ class RouteArrowComponent(
4443
super.onDetached(mapboxNavigation)
4544
mapboxMap.getStyle()?.also { style ->
4645
routeArrowView.render(style, routeArrowApi.clearArrows())
47-
RouteArrowUtils.removeLayers(style)
4846
}
4947
}
5048
}

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/arrow/RouteArrowUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ internal object RouteArrowUtils {
261261
style.styleLayerExists(RouteLayerConstants.ARROW_HEAD_LAYER_ID)
262262
}
263263

264-
internal fun removeLayers(style: Style) {
264+
internal fun removeLayersAndSources(style: Style) {
265265
style.removeStyleImage(RouteLayerConstants.ARROW_HEAD_ICON_CASING)
266266
style.removeStyleImage(RouteLayerConstants.ARROW_HEAD_ICON)
267267
style.removeStyleLayer(RouteLayerConstants.ARROW_SHAFT_CASING_LINE_LAYER_ID)

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/arrow/api/MapboxRouteArrowView.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
1212
import com.mapbox.maps.extension.style.sources.getSourceAs
1313
import com.mapbox.navigation.ui.maps.internal.route.line.MapboxRouteLineUtils
1414
import com.mapbox.navigation.ui.maps.route.RouteLayerConstants
15+
import com.mapbox.navigation.ui.maps.route.arrow.RouteArrowUtils
1516
import com.mapbox.navigation.ui.maps.route.arrow.RouteArrowUtils.initializeLayers
17+
import com.mapbox.navigation.ui.maps.route.arrow.RouteArrowUtils.layersAreInitialized
1618
import com.mapbox.navigation.ui.maps.route.arrow.model.ArrowAddedValue
1719
import com.mapbox.navigation.ui.maps.route.arrow.model.ArrowVisibilityChangeValue
1820
import com.mapbox.navigation.ui.maps.route.arrow.model.ClearArrowsValue
@@ -31,10 +33,16 @@ import com.mapbox.navigation.utils.internal.logE
3133
* See [Style.addPersistentStyleLayer].
3234
*
3335
* @param options the options used for determining the rendering appearance and/or behavior.
36+
*
37+
* If you're recreating the the [MapboxRouteArrowView] instance, for example to change the
38+
* [RouteArrowOptions], make sure that your first interaction restores the state and re-applies
39+
* the options by calling [MapboxRouteArrowApi.redraw] and passing the result to [MapboxRouteArrowView.render].
3440
*/
3541
@UiThread
3642
class MapboxRouteArrowView(private val options: RouteArrowOptions) {
3743

44+
private var rebuildLayersOnFirstRender: Boolean = true
45+
3846
private companion object {
3947
private const val LOG_CATEGORY = "MapboxRouteArrowView"
4048
}
@@ -47,7 +55,7 @@ class MapboxRouteArrowView(private val options: RouteArrowOptions) {
4755
* @param visibilityChange a state containing data for applying the view side effects.
4856
*/
4957
fun render(style: Style, visibilityChange: ArrowVisibilityChangeValue) {
50-
initializeLayers(style, options)
58+
rebuildSourcesAndLayersIfNeeded(style)
5159

5260
visibilityChange.layerVisibilityModifications.forEach {
5361
updateLayerVisibility(style, it.first, it.second)
@@ -65,7 +73,7 @@ class MapboxRouteArrowView(private val options: RouteArrowOptions) {
6573
style: Style,
6674
expectedValue: Expected<InvalidPointError, UpdateManeuverArrowValue>
6775
) {
68-
initializeLayers(style, options)
76+
rebuildSourcesAndLayersIfNeeded(style)
6977

7078
expectedValue.onError {
7179
logE(it.errorMessage, LOG_CATEGORY)
@@ -90,7 +98,7 @@ class MapboxRouteArrowView(private val options: RouteArrowOptions) {
9098
* @param arrowAdded a state containing data for applying the view side effects.
9199
*/
92100
fun render(style: Style, arrowAdded: ArrowAddedValue) {
93-
initializeLayers(style, options)
101+
rebuildSourcesAndLayersIfNeeded(style)
94102

95103
updateSource(
96104
style,
@@ -128,7 +136,7 @@ class MapboxRouteArrowView(private val options: RouteArrowOptions) {
128136
* @param state a state containing data for applying the view side effects.
129137
*/
130138
fun render(style: Style, state: RemoveArrowValue) {
131-
initializeLayers(style, options)
139+
rebuildSourcesAndLayersIfNeeded(style)
132140

133141
updateSource(
134142
style,
@@ -149,7 +157,7 @@ class MapboxRouteArrowView(private val options: RouteArrowOptions) {
149157
* @param state a state containing data for applying the view side effects.
150158
*/
151159
fun render(style: Style, state: ClearArrowsValue) {
152-
initializeLayers(style, options)
160+
rebuildSourcesAndLayersIfNeeded(style)
153161

154162
updateSource(
155163
style,
@@ -196,4 +204,16 @@ class MapboxRouteArrowView(private val options: RouteArrowOptions) {
196204
style.getSourceAs<GeoJsonSource>(sourceId)?.featureCollection(featureCollection)
197205
}
198206
}
207+
208+
private fun rebuildLayersAndSources(style: Style, options: RouteArrowOptions) {
209+
RouteArrowUtils.removeLayersAndSources(style)
210+
initializeLayers(style, options)
211+
}
212+
213+
private fun rebuildSourcesAndLayersIfNeeded(style: Style) {
214+
if (rebuildLayersOnFirstRender || !layersAreInitialized(style)) {
215+
rebuildLayersOnFirstRender = false
216+
rebuildLayersAndSources(style, options)
217+
}
218+
}
199219
}

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,22 @@ import org.jetbrains.annotations.TestOnly
7676
* @param options resource options used rendering the route line on the map
7777
*/
7878
@UiThread
79-
class MapboxRouteLineView(var options: MapboxRouteLineOptions) {
79+
class MapboxRouteLineView(options: MapboxRouteLineOptions) {
8080

8181
private companion object {
8282
private const val TAG = "MbxRouteLineView"
8383
}
84+
85+
/**
86+
* Resource options used rendering the route line on the map
87+
*/
88+
var options: MapboxRouteLineOptions = options
89+
@Deprecated(
90+
message = "Avoid using this setter as it will not correctly " +
91+
"re-apply all mutated parameters."
92+
)
93+
set
94+
8495
private val sourceToFeatureMap = mutableMapOf<RouteLineSourceKey, RouteLineFeatureId>(
8596
Pair(MapboxRouteLineUtils.layerGroup1SourceKey, RouteLineFeatureId(null)),
8697
Pair(MapboxRouteLineUtils.layerGroup2SourceKey, RouteLineFeatureId(null)),
@@ -127,7 +138,7 @@ class MapboxRouteLineView(var options: MapboxRouteLineOptions) {
127138
}
128139

129140
/**
130-
* Will initialize the route line related layers. Other calls in this class will initialize
141+
* Initializes the route line related layers. Other calls in this class will initialize
131142
* the layers if they have not yet been initialized. If you have a use case for initializing
132143
* the layers in advance of any API calls this method may be used.
133144
*

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/VanishingRouteLine.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ internal class VanishingRouteLine {
9797
point
9898
)
9999

100-
/**
101-
* Calculate the percentage of the route traveled and update the expression.
102-
*/
103100
/**
104101
* Calculate the percentage of the route traveled and update the expression.
105102
*/

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/internal/ui/RouteArrowComponentTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RouteArrowComponentTest {
4949
every { intrinsicHeight } returns 24
5050
every { intrinsicWidth } returns 24
5151
}
52-
every { RouteArrowUtils.removeLayers(any()) } just Runs
52+
every { RouteArrowUtils.removeLayersAndSources(any()) } just Runs
5353
}
5454

5555
@After
@@ -136,7 +136,6 @@ class RouteArrowComponentTest {
136136
sut.onDetached(mockMapboxNavigation)
137137

138138
verify { mockView.render(mockStyle, clearValue) }
139-
verify { RouteArrowUtils.removeLayers(mockStyle) }
140139
}
141140

142141
private fun mockMapWithStyleLoaded(style: Style): MapboxMap = mockk {

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/arrow/RouteArrowUtilsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class RouteArrowUtilsTest {
403403
every { removeStyleImage(ARROW_HEAD_ICON) } returns mockk()
404404
}
405405

406-
RouteArrowUtils.removeLayers(style)
406+
RouteArrowUtils.removeLayersAndSources(style)
407407

408408
verifySequence {
409409
style.removeStyleImage(ARROW_HEAD_ICON_CASING)

0 commit comments

Comments
 (0)