Skip to content

Commit db7bb16

Browse files
committed
use maneuver view visibility instead of height
1 parent 420d326 commit db7bb16

11 files changed

Lines changed: 50 additions & 73 deletions

File tree

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/component/maneuver/ManeuverBehavior.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ internal class ManeuverBehavior {
99
private val _maneuverBehavior = MutableStateFlow<MapboxManeuverViewState>(
1010
MapboxManeuverViewState.COLLAPSED
1111
)
12-
private val _maneuverViewHeight = MutableStateFlow(0)
12+
private val _maneuverViewVisibility = MutableStateFlow(false)
1313

1414
val maneuverBehavior = _maneuverBehavior.asStateFlow()
15-
val maneuverViewHeight = _maneuverViewHeight.asStateFlow()
15+
val maneuverViewVisibility = _maneuverViewVisibility.asStateFlow()
1616

1717
fun updateBehavior(newState: MapboxManeuverViewState) {
1818
_maneuverBehavior.value = newState
1919
}
2020

21-
fun updateViewHeight(newHeight: Int) {
22-
_maneuverViewHeight.value = newHeight
21+
fun updateViewVisibility(visibility: Boolean) {
22+
_maneuverViewVisibility.value = visibility
2323
}
2424
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/component/maneuver/ManeuverComponentContractImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class ManeuverComponentContractImpl(
1414
context.maneuverBehavior.updateBehavior(state)
1515
}
1616

17-
override fun onManeuverViewHeightChanged(newHeight: Int) {
18-
context.maneuverBehavior.updateViewHeight(newHeight)
17+
override fun onManeuverViewVisibilityChanged(isVisible: Boolean) {
18+
context.maneuverBehavior.updateViewVisibility(isVisible)
1919
}
2020
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/component/map/ScalebarPlaceholderComponent.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import kotlinx.coroutines.launch
1414
internal class ScalebarPlaceholderComponent(
1515
private val scalebarPlaceholder: View,
1616
private val scalebarParams: StateFlow<MapboxMapScalebarParams>,
17-
private val maneuverHeight: StateFlow<Int>,
17+
private val maneuverViewVisible: StateFlow<Boolean>,
1818
) : UIComponent() {
1919

2020
override fun onAttached(mapboxNavigation: MapboxNavigation) {
2121
super.onAttached(mapboxNavigation)
2222
coroutineScope.launch {
23-
combine(scalebarParams, maneuverHeight) { params, height ->
23+
combine(scalebarParams, maneuverViewVisible) { params, maneuverViewVisible ->
2424
scalebarPlaceholder.visibility =
25-
if (params.enabled && height == 0) {
25+
if (params.enabled && !maneuverViewVisible) {
2626
View.VISIBLE
2727
} else {
2828
View.GONE

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class ScalebarPlaceholderBinder(
2020
return ScalebarPlaceholderComponent(
2121
binding.scalebarPlaceholder,
2222
context.styles.mapScalebarParams,
23-
context.maneuverBehavior.maneuverViewHeight
23+
context.maneuverBehavior.maneuverViewVisibility
2424
)
2525
}
2626

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/component/maneuver/ManeuverBehaviorTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ class ManeuverBehaviorTest {
1616
}
1717

1818
@Test
19-
fun `when maneuver view height is updated`() {
19+
fun `when maneuver view visibility is updated to true`() {
2020
val sut = ManeuverBehavior()
2121

22-
sut.updateViewHeight(43)
22+
sut.updateViewVisibility(true)
2323

24-
assertEquals(43, sut.maneuverViewHeight.value)
24+
assertEquals(true, sut.maneuverViewVisibility.value)
25+
}
26+
27+
@Test
28+
fun `when maneuver view visibility is updated to false`() {
29+
val sut = ManeuverBehavior()
30+
sut.updateViewVisibility(true)
31+
32+
sut.updateViewVisibility(false)
33+
34+
assertEquals(false, sut.maneuverViewVisibility.value)
2535
}
2636
}

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/component/maneuver/ManeuverComponentContractImplTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class ManeuverComponentContractImplTest {
2929

3030
@Test
3131
fun `when maneuver view height is changed, contract is notified`() {
32-
sut.onManeuverViewHeightChanged(23)
32+
sut.onManeuverViewVisibilityChanged(true)
3333

3434
verify {
35-
navigationViewContext.maneuverBehavior.updateViewHeight(23)
35+
navigationViewContext.maneuverBehavior.updateViewVisibility(true)
3636
}
3737
}
3838
}

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/component/map/ScalebarPlaceholderComponentTest.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,25 @@ class ScalebarPlaceholderComponentTest {
2727
private val context = ApplicationProvider.getApplicationContext<Context>()
2828
private val mapboxNavigation = mockk<MapboxNavigation>()
2929
private val scalebarPlaceholderView = mockk<View>(relaxed = true)
30-
private val initialHeight = 7
31-
private val heightFlow = MutableStateFlow(initialHeight)
30+
private val visibilityFlow = MutableStateFlow(false)
3231
private val mapScalebarParams = MutableStateFlow(
3332
MapboxMapScalebarParams.Builder(context).build()
3433
)
3534
private val component = ScalebarPlaceholderComponent(
3635
scalebarPlaceholderView,
3736
mapScalebarParams,
38-
heightFlow
37+
visibilityFlow
3938
)
4039

4140
@Test
42-
fun visibilityIsChangedOnOnAttachedHasHeight() {
41+
fun visibilityIsChangedOnOnAttachedVisible() {
42+
visibilityFlow.tryEmit(true)
4343
component.onAttached(mapboxNavigation)
4444
verify { scalebarPlaceholderView.visibility = View.GONE }
4545
}
4646

4747
@Test
48-
fun visibilityIsChangedOnOnAttachedNoHeight() {
49-
heightFlow.tryEmit(0)
48+
fun visibilityIsChangedOnOnAttachedNotVisible() {
5049
component.onAttached(mapboxNavigation)
5150
verify { scalebarPlaceholderView.visibility = View.GONE }
5251
}
@@ -58,43 +57,45 @@ class ScalebarPlaceholderComponentTest {
5857
}
5958

6059
@Test
61-
fun heightChangeBeforeOnAttached() {
62-
heightFlow.tryEmit(8)
60+
fun maneuverVisibilityChangeBeforeOnAttached() {
61+
visibilityFlow.tryEmit(true)
6362
verify(exactly = 0) { scalebarPlaceholderView.visibility = any() }
6463
}
6564

6665
@Test
67-
fun mapScalebarParamsChangeAfterOnAttachedHasHeight() {
66+
fun mapScalebarParamsChangeAfterOnAttachedVisible() {
67+
visibilityFlow.tryEmit(true)
6868
component.onAttached(mapboxNavigation)
6969
clearMocks(scalebarPlaceholderView)
7070
mapScalebarParams.tryEmit(MapboxMapScalebarParams.Builder(context).enabled(true).build())
7171
verify { scalebarPlaceholderView.visibility = View.GONE }
7272
}
7373

7474
@Test
75-
fun mapScalebarParamsChangeAfterOnAttachedNoHeight() {
76-
heightFlow.tryEmit(0)
75+
fun mapScalebarParamsChangeAfterOnAttachedNotVisible() {
7776
component.onAttached(mapboxNavigation)
7877
clearMocks(scalebarPlaceholderView)
7978
mapScalebarParams.tryEmit(MapboxMapScalebarParams.Builder(context).enabled(true).build())
8079
verify { scalebarPlaceholderView.visibility = View.VISIBLE }
8180
}
8281

8382
@Test
84-
fun heightChangeAfterOnAttachedHasHeight() {
83+
fun maneuverVisibilityChangeAfterOnAttachedVisible() {
8584
mapScalebarParams.tryEmit(MapboxMapScalebarParams.Builder(context).enabled(true).build())
8685
component.onAttached(mapboxNavigation)
8786
clearMocks(scalebarPlaceholderView)
88-
heightFlow.tryEmit(8)
87+
visibilityFlow.tryEmit(true)
8988
verify { scalebarPlaceholderView.visibility = View.GONE }
9089
}
9190

9291
@Test
93-
fun heightChangeAfterOnAttachedNoHeight() {
92+
fun maneuverVisibilityChangeAfterOnAttachedNotVisible() {
93+
// so that it will <i>change</i> to false later
94+
visibilityFlow.tryEmit(true)
9495
mapScalebarParams.tryEmit(MapboxMapScalebarParams.Builder(context).enabled(true).build())
9596
component.onAttached(mapboxNavigation)
9697
clearMocks(scalebarPlaceholderView)
97-
heightFlow.tryEmit(0)
98+
visibilityFlow.tryEmit(false)
9899
verify { scalebarPlaceholderView.visibility = View.VISIBLE }
99100
}
100101

@@ -108,12 +109,12 @@ class ScalebarPlaceholderComponentTest {
108109
}
109110

110111
@Test
111-
fun heightChangeAfterOnDetached() {
112+
fun maneuverVisibilityChangeAfterOnDetached() {
112113
mapScalebarParams.tryEmit(MapboxMapScalebarParams.Builder(context).enabled(true).build())
113114
component.onAttached(mapboxNavigation)
114115
clearMocks(scalebarPlaceholderView)
115116
component.onDetached(mapboxNavigation)
116-
heightFlow.tryEmit(9)
117+
visibilityFlow.tryEmit(true)
117118
verify(exactly = 0) { scalebarPlaceholderView.visibility = any() }
118119
}
119120
}

libnavui-maneuver/src/main/java/com/mapbox/navigation/ui/maneuver/internal/ManeuverComponent.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import kotlinx.coroutines.launch
2020

2121
interface ManeuverComponentContract {
2222
fun onManeuverViewStateChanged(state: MapboxManeuverViewState)
23-
fun onManeuverViewHeightChanged(newHeight: Int)
23+
fun onManeuverViewVisibilityChanged(isVisible: Boolean)
2424
}
2525

2626
@ExperimentalPreviewMapboxNavigationAPI
@@ -43,11 +43,7 @@ class ManeuverComponent(
4343
contract?.get()?.onManeuverViewStateChanged(it)
4444
}
4545
}
46-
coroutineScope.launch {
47-
maneuverView.heightFlow.collect {
48-
contract?.get()?.onManeuverViewHeightChanged(it)
49-
}
50-
}
46+
contract?.get()?.onManeuverViewVisibilityChanged(true)
5147
coroutineScope.launch {
5248
combine(
5349
mapboxNavigation.flowRoutesUpdated(),
@@ -78,6 +74,6 @@ class ManeuverComponent(
7874

7975
override fun onDetached(mapboxNavigation: MapboxNavigation) {
8076
super.onDetached(mapboxNavigation)
81-
contract?.get()?.onManeuverViewHeightChanged(0)
77+
contract?.get()?.onManeuverViewVisibilityChanged(false)
8278
}
8379
}

libnavui-maneuver/src/main/java/com/mapbox/navigation/ui/maneuver/view/MapboxManeuverView.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import kotlinx.coroutines.flow.asStateFlow
4545
*/
4646
class MapboxManeuverView : ConstraintLayout {
4747

48-
private val _heightFlow = MutableStateFlow(0)
4948
private val _maneuverViewState = MutableStateFlow<MapboxManeuverViewState>(
5049
MapboxManeuverViewState.COLLAPSED
5150
)
@@ -55,8 +54,6 @@ class MapboxManeuverView : ConstraintLayout {
5554
*/
5655
val maneuverViewState = _maneuverViewState.asStateFlow()
5756

58-
internal val heightFlow = _heightFlow.asStateFlow()
59-
6057
private var maneuverViewOptions = ManeuverViewOptions.Builder().build()
6158

6259
/**
@@ -752,11 +749,4 @@ class MapboxManeuverView : ConstraintLayout {
752749
internal fun getUpcomingManeuverAdapter(): MapboxUpcomingManeuverAdapter {
753750
return upcomingManeuverAdapter
754751
}
755-
756-
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
757-
super.onSizeChanged(w, h, oldw, oldh)
758-
if (h != oldh) {
759-
_heightFlow.tryEmit(h)
760-
}
761-
}
762752
}

libnavui-maneuver/src/test/java/com/mapbox/navigation/ui/maneuver/internal/ManeuverComponentTest.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class ManeuverComponentTest {
5454
@get:Rule
5555
var coroutineRule = MainCoroutineRule()
5656

57-
private val initialHeight = 53
5857
private val maneuverViewOptions = ManeuverViewOptions.Builder().build()
5958

6059
@Before
@@ -309,14 +308,11 @@ class ManeuverComponentTest {
309308
}
310309

311310
@Test
312-
fun `maneuver view height is collected`() =
311+
fun `maneuver view visibility is set to true on onAttached`() =
313312
coroutineRule.runBlockingTest {
314313
val contract = mockk<ManeuverComponentContract>(relaxed = true) {
315314
every { onManeuverViewStateChanged(any()) } just Runs
316315
}
317-
every {
318-
maneuverView.heightFlow
319-
} returns MutableStateFlow(initialHeight)
320316
val maneuverComponent =
321317
ManeuverComponent(
322318
maneuverView = maneuverView,
@@ -331,19 +327,16 @@ class ManeuverComponentTest {
331327
maneuverComponent.onAttached(mockNavigation)
332328

333329
verify {
334-
contract.onManeuverViewHeightChanged(initialHeight)
330+
contract.onManeuverViewVisibilityChanged(true)
335331
}
336332
}
337333

338334
@Test
339-
fun `onDetached proxies zero height`() =
335+
fun `maneuver view visibility is set to false on onDetached`() =
340336
coroutineRule.runBlockingTest {
341337
val contract = mockk<ManeuverComponentContract>(relaxed = true) {
342338
every { onManeuverViewStateChanged(any()) } just Runs
343339
}
344-
every {
345-
maneuverView.heightFlow
346-
} returns MutableStateFlow(initialHeight)
347340
val maneuverComponent =
348341
ManeuverComponent(
349342
maneuverView = maneuverView,
@@ -360,7 +353,7 @@ class ManeuverComponentTest {
360353
maneuverComponent.onDetached(mockNavigation)
361354

362355
verify {
363-
contract.onManeuverViewHeightChanged(0)
356+
contract.onManeuverViewVisibilityChanged(false)
364357
}
365358
}
366359
}

0 commit comments

Comments
 (0)