Skip to content

Commit ae64aba

Browse files
tomaszrybakiewiczrunner
authored andcommitted
[Drop-In UI] Changes RoadName positioning and customization (#6792)
* Increased InfoPanel bottom guideline max pos to 50% of the NavigationView height and made it customizable via ViewStyleCustomization.infoPanelGuidelineMaxPosPercent. * CHANGELOG entry * Rename changelog files Co-authored-by: runner <runner@fv-az465-655>
1 parent f3845f7 commit ae64aba

5 files changed

Lines changed: 56 additions & 14 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Introduced `ViewStyleCustomization.infoPanelGuidelineMaxPosPercent` that allows customization of the `NavigationView` InfoPanel bottom guideline maximum position. Increased default value to 50%.

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/ViewStyleCustomization.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mapbox.navigation.dropin
22

33
import android.content.Context
44
import androidx.annotation.DrawableRes
5+
import androidx.annotation.FloatRange
56
import androidx.annotation.Px
67
import androidx.annotation.StyleRes
78
import androidx.core.content.ContextCompat
@@ -64,6 +65,14 @@ class ViewStyleCustomization {
6465
@DrawableRes
6566
var infoPanelBackground: Int? = null
6667

68+
/**
69+
* Info panel guideline maximum position within its parent view.
70+
* This value must be within 0.0f..1.0f range.
71+
* Use [defaultInfoPanelGuidelineMaxPosPercent] to reset to default.
72+
*/
73+
@FloatRange(from = 0.0, to = 1.0)
74+
var infoPanelGuidelineMaxPosPercent: Float? = null
75+
6776
/**
6877
* Provide custom [POINameComponent] [TextAppearance].
6978
* Use [defaultPoiNameTextAppearance] to reset to default.
@@ -208,6 +217,12 @@ class ViewStyleCustomization {
208217
@DrawableRes
209218
fun defaultInfoPanelBackground(): Int = R.drawable.mapbox_bg_info_panel
210219

220+
/**
221+
* Default info panel guideline maximum position within its parent view.
222+
*/
223+
@FloatRange(from = 0.0, to = 1.0)
224+
fun defaultInfoPanelGuidelineMaxPosPercent(): Float = 0.5f
225+
211226
/**
212227
* Default [PointAnnotationOptions] for showing destination marker.
213228
*/

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/infopanel/InfoPanelCoordinator.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ internal class InfoPanelCoordinator(
8181
coroutineScope.launch {
8282
context.systemBarsInsets.collect { updateGuidelinePosition(systemBarsInsets = it) }
8383
}
84+
coroutineScope.launch {
85+
context.styles.infoPanelGuidelineMaxPosPercent.collect {
86+
updateGuidelinePosition(maxPosPercent = it)
87+
}
88+
}
89+
coroutineScope.launch {
90+
infoPanelTop.collect { updateGuidelinePosition(infoPanelTop = it) }
91+
}
8492
coroutineScope.launch {
8593
context.options.isInfoPanelHideable.collect { hideable ->
8694
if (behavior.state != BottomSheetBehavior.STATE_HIDDEN) {
@@ -95,9 +103,6 @@ internal class InfoPanelCoordinator(
95103
coroutineScope.launch {
96104
bottomSheetPeekHeight().collect { behavior.peekHeight = it }
97105
}
98-
coroutineScope.launch {
99-
infoPanelTop.collect { updateGuidelinePosition(infoPanelTop = it) }
100-
}
101106
}
102107

103108
override fun onDetached(mapboxNavigation: MapboxNavigation) {
@@ -158,11 +163,14 @@ internal class InfoPanelCoordinator(
158163
private fun updateGuidelinePosition(
159164
systemBarsInsets: Insets = context.systemBarsInsets.value,
160165
infoPanelTop: Int = infoPanel.top,
166+
maxPosPercent: Float = context.styles.infoPanelGuidelineMaxPosPercent.value
161167
) {
162168
val parentHeight = (infoPanel.parent as ViewGroup).height
163-
val maxPos = (parentHeight * GUIDELINE_MAX_POSITION_PERCENT).toInt()
164-
val pos = parentHeight - infoPanelTop - systemBarsInsets.bottom
165-
guidelineBottom.setGuidelineEnd(pos.coerceIn(0, maxPos))
169+
val maxPos = (parentHeight * maxPosPercent).toInt() - systemBarsInsets.bottom
170+
if (0 < maxPos) {
171+
val pos = parentHeight - infoPanelTop - systemBarsInsets.bottom
172+
guidelineBottom.setGuidelineEnd(pos.coerceIn(0, maxPos))
173+
}
166174
}
167175

168176
private fun resetSlideOffset(prevBottomSheetState: Int, bottomSheetState: Int) {
@@ -206,12 +214,4 @@ internal class InfoPanelCoordinator(
206214
}
207215
}
208216
}
209-
210-
private companion object {
211-
/**
212-
* Guideline bottom maximum position within its parent view.
213-
* This value must be within 0.0f..1.0f range.
214-
*/
215-
const val GUIDELINE_MAX_POSITION_PERCENT = 0.3f
216-
}
217217
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/navigationview/NavigationViewStyles.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ internal class NavigationViewStyles(context: Context) {
1919
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelMarginEnd())
2020
private val _infoPanelBackground: MutableStateFlow<Int> =
2121
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelBackground())
22+
private val _infoPanelGuidelineMaxPosPercent: MutableStateFlow<Float> =
23+
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelGuidelineMaxPosPercent())
2224
private val _poiNameTextAppearance: MutableStateFlow<Int> =
2325
MutableStateFlow(ViewStyleCustomization.defaultPoiNameTextAppearance())
2426
private val _tripProgressStyle: MutableStateFlow<Int> =
@@ -60,6 +62,8 @@ internal class NavigationViewStyles(context: Context) {
6062
val infoPanelMarginStart: StateFlow<Int> = _infoPanelMarginStart.asStateFlow()
6163
val infoPanelMarginEnd: StateFlow<Int> = _infoPanelMarginEnd.asStateFlow()
6264
val infoPanelBackground: StateFlow<Int> = _infoPanelBackground.asStateFlow()
65+
val infoPanelGuidelineMaxPosPercent: StateFlow<Float> =
66+
_infoPanelGuidelineMaxPosPercent.asStateFlow()
6367
val poiNameTextAppearance: StateFlow<Int> = _poiNameTextAppearance.asStateFlow()
6468
val tripProgressStyle: StateFlow<Int> = _tripProgressStyle.asStateFlow()
6569

@@ -86,6 +90,9 @@ internal class NavigationViewStyles(context: Context) {
8690
customization.infoPanelMarginStart?.also { _infoPanelMarginStart.value = it }
8791
customization.infoPanelMarginEnd?.also { _infoPanelMarginEnd.value = it }
8892
customization.infoPanelBackground?.also { _infoPanelBackground.value = it }
93+
customization.infoPanelGuidelineMaxPosPercent?.also {
94+
_infoPanelGuidelineMaxPosPercent.value = it.coerceIn(0.0f, 1.0f)
95+
}
8996
customization.poiNameTextAppearance?.also { _poiNameTextAppearance.value = it }
9097
customization.tripProgressStyle?.also { _tripProgressStyle.value = it }
9198

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/navigationview/NavigationViewStylesTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class NavigationViewStylesTest {
3737
assertEquals(c.infoPanelMarginStart, sut.infoPanelMarginStart.value)
3838
assertEquals(c.infoPanelMarginEnd, sut.infoPanelMarginEnd.value)
3939
assertEquals(c.infoPanelBackground, sut.infoPanelBackground.value)
40+
assertEquals(c.infoPanelGuidelineMaxPosPercent, sut.infoPanelGuidelineMaxPosPercent.value)
4041
assertEquals(c.poiNameTextAppearance, sut.poiNameTextAppearance.value)
4142
assertEquals(c.tripProgressStyle, sut.tripProgressStyle.value)
4243
assertEquals(c.compassButtonStyle, sut.compassButtonStyle.value)
@@ -59,11 +60,29 @@ class NavigationViewStylesTest {
5960
assertEquals(c.locationPuckOptions, sut.locationPuckOptions.value)
6061
}
6162

63+
@Test
64+
fun `applyCustomization should clamp infoPanelGuidelineMaxPosPercent value`() {
65+
sut.applyCustomization(
66+
ViewStyleCustomization().apply {
67+
infoPanelGuidelineMaxPosPercent = -0.1f
68+
}
69+
)
70+
assertEquals(0.0f, sut.infoPanelGuidelineMaxPosPercent.value)
71+
72+
sut.applyCustomization(
73+
ViewStyleCustomization().apply {
74+
infoPanelGuidelineMaxPosPercent = 1.1f
75+
}
76+
)
77+
assertEquals(1.0f, sut.infoPanelGuidelineMaxPosPercent.value)
78+
}
79+
6280
private fun customization() = ViewStyleCustomization().apply {
6381
infoPanelPeekHeight = 1
6482
infoPanelMarginStart = 2
6583
infoPanelMarginEnd = 3
6684
infoPanelBackground = android.R.drawable.spinner_background
85+
infoPanelGuidelineMaxPosPercent = 0.25f
6786
poiNameTextAppearance = android.R.style.TextAppearance_DeviceDefault_Large
6887
tripProgressStyle = R.style.MapboxStyleTripProgressView
6988
compassButtonStyle = R.style.MapboxStyleExtendableButton_Circle

0 commit comments

Comments
 (0)