Skip to content

Commit 61415ea

Browse files
tomaszrybakiewiczrunner
andauthored
[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 2f76cdf commit 61415ea

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed
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
@@ -66,6 +67,14 @@ class ViewStyleCustomization {
6667
@DrawableRes
6768
var infoPanelBackground: Int? = null
6869

70+
/**
71+
* Info panel guideline maximum position within its parent view.
72+
* This value must be within 0.0f..1.0f range.
73+
* Use [defaultInfoPanelGuidelineMaxPosPercent] to reset to default.
74+
*/
75+
@FloatRange(from = 0.0, to = 1.0)
76+
var infoPanelGuidelineMaxPosPercent: Float? = null
77+
6978
/**
7079
* Provide custom [POINameComponent] [TextAppearance].
7180
* Use [defaultPoiNameTextAppearance] to reset to default.
@@ -224,6 +233,12 @@ class ViewStyleCustomization {
224233
@DrawableRes
225234
fun defaultInfoPanelBackground(): Int = R.drawable.mapbox_bg_info_panel
226235

236+
/**
237+
* Default info panel guideline maximum position within its parent view.
238+
*/
239+
@FloatRange(from = 0.0, to = 1.0)
240+
fun defaultInfoPanelGuidelineMaxPosPercent(): Float = 0.5f
241+
227242
/**
228243
* Default [PointAnnotationOptions] for showing destination marker.
229244
*/

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
@@ -20,6 +20,8 @@ internal class NavigationViewStyles(context: Context) {
2020
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelMarginEnd())
2121
private val _infoPanelBackground: MutableStateFlow<Int> =
2222
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelBackground())
23+
private val _infoPanelGuidelineMaxPosPercent: MutableStateFlow<Float> =
24+
MutableStateFlow(ViewStyleCustomization.defaultInfoPanelGuidelineMaxPosPercent())
2325
private val _poiNameTextAppearance: MutableStateFlow<Int> =
2426
MutableStateFlow(ViewStyleCustomization.defaultPoiNameTextAppearance())
2527
private val _tripProgressStyle: MutableStateFlow<Int> =
@@ -67,6 +69,8 @@ internal class NavigationViewStyles(context: Context) {
6769
val infoPanelMarginStart: StateFlow<Int> = _infoPanelMarginStart.asStateFlow()
6870
val infoPanelMarginEnd: StateFlow<Int> = _infoPanelMarginEnd.asStateFlow()
6971
val infoPanelBackground: StateFlow<Int> = _infoPanelBackground.asStateFlow()
72+
val infoPanelGuidelineMaxPosPercent: StateFlow<Float> =
73+
_infoPanelGuidelineMaxPosPercent.asStateFlow()
7074
val poiNameTextAppearance: StateFlow<Int> = _poiNameTextAppearance.asStateFlow()
7175
val tripProgressStyle: StateFlow<Int> = _tripProgressStyle.asStateFlow()
7276

@@ -104,6 +108,9 @@ internal class NavigationViewStyles(context: Context) {
104108
customization.infoPanelMarginStart?.also { _infoPanelMarginStart.value = it }
105109
customization.infoPanelMarginEnd?.also { _infoPanelMarginEnd.value = it }
106110
customization.infoPanelBackground?.also { _infoPanelBackground.value = it }
111+
customization.infoPanelGuidelineMaxPosPercent?.also {
112+
_infoPanelGuidelineMaxPosPercent.value = it.coerceIn(0.0f, 1.0f)
113+
}
107114
customization.poiNameTextAppearance?.also { _poiNameTextAppearance.value = it }
108115
customization.tripProgressStyle?.also { _tripProgressStyle.value = it }
109116

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
@@ -39,6 +39,7 @@ class NavigationViewStylesTest {
3939
assertEquals(c.infoPanelMarginStart, sut.infoPanelMarginStart.value)
4040
assertEquals(c.infoPanelMarginEnd, sut.infoPanelMarginEnd.value)
4141
assertEquals(c.infoPanelBackground, sut.infoPanelBackground.value)
42+
assertEquals(c.infoPanelGuidelineMaxPosPercent, sut.infoPanelGuidelineMaxPosPercent.value)
4243
assertEquals(c.poiNameTextAppearance, sut.poiNameTextAppearance.value)
4344
assertEquals(c.tripProgressStyle, sut.tripProgressStyle.value)
4445
assertEquals(c.compassButtonStyle, sut.compassButtonStyle.value)
@@ -62,11 +63,29 @@ class NavigationViewStylesTest {
6263
assertEquals(c.speedInfoOptions, sut.speedInfoOptions.value)
6364
}
6465

66+
@Test
67+
fun `applyCustomization should clamp infoPanelGuidelineMaxPosPercent value`() {
68+
sut.applyCustomization(
69+
ViewStyleCustomization().apply {
70+
infoPanelGuidelineMaxPosPercent = -0.1f
71+
}
72+
)
73+
assertEquals(0.0f, sut.infoPanelGuidelineMaxPosPercent.value)
74+
75+
sut.applyCustomization(
76+
ViewStyleCustomization().apply {
77+
infoPanelGuidelineMaxPosPercent = 1.1f
78+
}
79+
)
80+
assertEquals(1.0f, sut.infoPanelGuidelineMaxPosPercent.value)
81+
}
82+
6583
private fun customization() = ViewStyleCustomization().apply {
6684
infoPanelPeekHeight = 1
6785
infoPanelMarginStart = 2
6886
infoPanelMarginEnd = 3
6987
infoPanelBackground = android.R.drawable.spinner_background
88+
infoPanelGuidelineMaxPosPercent = 0.25f
7089
poiNameTextAppearance = android.R.style.TextAppearance_DeviceDefault_Large
7190
tripProgressStyle = R.style.MapboxStyleTripProgressView
7291
compassButtonStyle = R.style.MapboxStyleExtendableButton_Circle

0 commit comments

Comments
 (0)