From ae47bc45081ed2cdbcd20941dc373db9cfbe7d29 Mon Sep 17 00:00:00 2001 From: Vitaly Zayankovsky Date: Wed, 4 Jan 2023 22:24:33 +0300 Subject: [PATCH] fix info panel dimensions in landscape with a full screen theme --- CHANGELOG.md | 1 + .../dropin/infopanel/InfoPanelComponent.kt | 24 ++++--------- .../infopanel/InfoPanelComponentTest.kt | 36 ++++++++++++------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 711fbb04fd7..aea3913495d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone. ## Unreleased #### Features #### Bug fixes and improvements +- 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) ## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022 ### Changelog diff --git a/libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponent.kt b/libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponent.kt index 661b288a1e6..f24272a4dc7 100644 --- a/libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponent.kt +++ b/libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponent.kt @@ -38,13 +38,12 @@ internal class InfoPanelComponent( } } - stylesFlow().observe { (background, marginLeft, marginRight) -> - layout.updateMargins( - left = marginLeft, - right = marginRight - ) - layout.setBackgroundResource(background) - } + context.styles.infoPanelBackground.observe { layout.setBackgroundResource(it) } + context.styles.infoPanelMarginStart.observe { layout.updateMargins(left = it) } + context.styles.infoPanelMarginEnd.observe { layout.updateMargins(right = it) } + + val parent = layout.parent as ViewGroup + context.systemBarsInsets.observe { parent.updateMargins(left = it.left, right = it.right) } } private fun findNavigationView(): NavigationView? { @@ -54,15 +53,4 @@ internal class InfoPanelComponent( } return v as? NavigationView } - - private fun stylesFlow() = context.styles.let { styles -> - combine( - styles.infoPanelBackground, - styles.infoPanelMarginStart, - styles.infoPanelMarginEnd, - context.systemBarsInsets - ) { background, marginStart, marginEnd, insets -> - Triple(background, marginStart + insets.left, marginEnd + insets.right) - } - } } diff --git a/libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponentTest.kt b/libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponentTest.kt index 1ea32c1cea4..1120cf902d5 100644 --- a/libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponentTest.kt +++ b/libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/infopanel/InfoPanelComponentTest.kt @@ -3,6 +3,7 @@ package com.mapbox.navigation.dropin.infopanel import android.content.Context import android.view.ViewGroup import android.widget.FrameLayout +import androidx.core.graphics.Insets import androidx.test.core.app.ApplicationProvider import com.mapbox.navigation.dropin.R import com.mapbox.navigation.dropin.navigationview.NavigationViewContext @@ -12,7 +13,6 @@ import com.mapbox.navigation.dropin.util.TestStore import com.mapbox.navigation.testing.LoggingFrontendTestRule import com.mapbox.navigation.testing.MainCoroutineRule import io.mockk.mockk -import io.mockk.spyk import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Assert.assertEquals import org.junit.Before @@ -26,37 +26,39 @@ import org.robolectric.RobolectricTestRunner class InfoPanelComponentTest { @get:Rule - var coroutineRule = MainCoroutineRule() + val coroutineRule = MainCoroutineRule() @get:Rule val loggerRule = LoggingFrontendTestRule() - private lateinit var ctx: Context private lateinit var layout: StubLayout + private lateinit var parent: ViewGroup private lateinit var navContext: NavigationViewContext private lateinit var sut: InfoPanelComponent @Before fun setUp() { - ctx = ApplicationProvider.getApplicationContext() + val ctx = ApplicationProvider.getApplicationContext() layout = StubLayout(ctx).apply { layoutParams = ViewGroup.MarginLayoutParams(1, 1) } - navContext = spyk( - NavigationViewContext( - context = ctx, - lifecycleOwner = TestLifecycleOwner(), - viewModel = NavigationViewModel(), - storeProvider = { TestStore() } - ) + parent = FrameLayout(ctx).apply { + addView(layout) + layoutParams = ViewGroup.MarginLayoutParams(1, 1) + } + navContext = NavigationViewContext( + context = ctx, + lifecycleOwner = TestLifecycleOwner(), + viewModel = NavigationViewModel(), + storeProvider = { TestStore() }, ) sut = InfoPanelComponent(layout, navContext) } @Test - fun `onAttached should observe and apply info panel styles`() = coroutineRule.runBlockingTest { + fun `onAttached should observe and apply info panel styles`() { navContext.applyStyleCustomization { infoPanelBackground = R.drawable.mapbox_ic_puck infoPanelMarginStart = 11 @@ -70,6 +72,16 @@ class InfoPanelComponentTest { assertEquals(R.drawable.mapbox_ic_puck, layout.backgroundResId) } + @Test + fun `onAttached should observe and apply insets`() { + navContext.systemBarsInsets.value = Insets.of(33, 44, 55, 66) + sut.onAttached(mockk()) + + val lp = parent.layoutParams as ViewGroup.MarginLayoutParams + assertEquals(33, lp.leftMargin) + assertEquals(55, lp.rightMargin) + } + // Stub layout that exposes assigned background resource id. private class StubLayout(context: Context) : FrameLayout(context) { var backgroundResId = 0