Skip to content

Commit 8322e43

Browse files
Zayankovskyrunner
andauthored
fix info panel dimensions in landscape with a full screen theme (#6780)
* fix info panel dimensions in landscape with a full screen theme * Rename changelog files Co-authored-by: runner <runner@fv-az308-698>
1 parent b329337 commit 8322e43

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed an issue with `NavigationView` that caused info panel to shrink in landscape mode with a full screen theme.

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ internal class InfoPanelComponent(
3838
}
3939
}
4040

41-
stylesFlow().observe { (background, marginLeft, marginRight) ->
42-
layout.updateMargins(
43-
left = marginLeft,
44-
right = marginRight
45-
)
46-
layout.setBackgroundResource(background)
47-
}
41+
context.styles.infoPanelBackground.observe { layout.setBackgroundResource(it) }
42+
context.styles.infoPanelMarginStart.observe { layout.updateMargins(left = it) }
43+
context.styles.infoPanelMarginEnd.observe { layout.updateMargins(right = it) }
44+
45+
val parent = layout.parent as ViewGroup
46+
context.systemBarsInsets.observe { parent.updateMargins(left = it.left, right = it.right) }
4847
}
4948

5049
private fun findNavigationView(): NavigationView? {
@@ -54,15 +53,4 @@ internal class InfoPanelComponent(
5453
}
5554
return v as? NavigationView
5655
}
57-
58-
private fun stylesFlow() = context.styles.let { styles ->
59-
combine(
60-
styles.infoPanelBackground,
61-
styles.infoPanelMarginStart,
62-
styles.infoPanelMarginEnd,
63-
context.systemBarsInsets
64-
) { background, marginStart, marginEnd, insets ->
65-
Triple(background, marginStart + insets.left, marginEnd + insets.right)
66-
}
67-
}
6856
}

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponentTest.kt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mapbox.navigation.dropin.infopanel
33
import android.content.Context
44
import android.view.ViewGroup
55
import android.widget.FrameLayout
6+
import androidx.core.graphics.Insets
67
import androidx.test.core.app.ApplicationProvider
78
import com.mapbox.navigation.dropin.R
89
import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
@@ -12,7 +13,6 @@ import com.mapbox.navigation.dropin.util.TestStore
1213
import com.mapbox.navigation.testing.LoggingFrontendTestRule
1314
import com.mapbox.navigation.testing.MainCoroutineRule
1415
import io.mockk.mockk
15-
import io.mockk.spyk
1616
import kotlinx.coroutines.ExperimentalCoroutinesApi
1717
import org.junit.Assert.assertEquals
1818
import org.junit.Before
@@ -26,37 +26,39 @@ import org.robolectric.RobolectricTestRunner
2626
class InfoPanelComponentTest {
2727

2828
@get:Rule
29-
var coroutineRule = MainCoroutineRule()
29+
val coroutineRule = MainCoroutineRule()
3030

3131
@get:Rule
3232
val loggerRule = LoggingFrontendTestRule()
3333

34-
private lateinit var ctx: Context
3534
private lateinit var layout: StubLayout
35+
private lateinit var parent: ViewGroup
3636
private lateinit var navContext: NavigationViewContext
3737

3838
private lateinit var sut: InfoPanelComponent
3939

4040
@Before
4141
fun setUp() {
42-
ctx = ApplicationProvider.getApplicationContext()
42+
val ctx = ApplicationProvider.getApplicationContext<Context>()
4343
layout = StubLayout(ctx).apply {
4444
layoutParams = ViewGroup.MarginLayoutParams(1, 1)
4545
}
46-
navContext = spyk(
47-
NavigationViewContext(
48-
context = ctx,
49-
lifecycleOwner = TestLifecycleOwner(),
50-
viewModel = NavigationViewModel(),
51-
storeProvider = { TestStore() }
52-
)
46+
parent = FrameLayout(ctx).apply {
47+
addView(layout)
48+
layoutParams = ViewGroup.MarginLayoutParams(1, 1)
49+
}
50+
navContext = NavigationViewContext(
51+
context = ctx,
52+
lifecycleOwner = TestLifecycleOwner(),
53+
viewModel = NavigationViewModel(),
54+
storeProvider = { TestStore() },
5355
)
5456

5557
sut = InfoPanelComponent(layout, navContext)
5658
}
5759

5860
@Test
59-
fun `onAttached should observe and apply info panel styles`() = coroutineRule.runBlockingTest {
61+
fun `onAttached should observe and apply info panel styles`() {
6062
navContext.applyStyleCustomization {
6163
infoPanelBackground = R.drawable.mapbox_ic_puck
6264
infoPanelMarginStart = 11
@@ -70,6 +72,16 @@ class InfoPanelComponentTest {
7072
assertEquals(R.drawable.mapbox_ic_puck, layout.backgroundResId)
7173
}
7274

75+
@Test
76+
fun `onAttached should observe and apply insets`() {
77+
navContext.systemBarsInsets.value = Insets.of(33, 44, 55, 66)
78+
sut.onAttached(mockk())
79+
80+
val lp = parent.layoutParams as ViewGroup.MarginLayoutParams
81+
assertEquals(33, lp.leftMargin)
82+
assertEquals(55, lp.rightMargin)
83+
}
84+
7385
// Stub layout that exposes assigned background resource id.
7486
private class StubLayout(context: Context) : FrameLayout(context) {
7587
var backgroundResId = 0

0 commit comments

Comments
 (0)