Skip to content

Commit

Permalink
fix info panel dimensions in landscape with a full screen theme (#6780)
Browse files Browse the repository at this point in the history
* fix info panel dimensions in landscape with a full screen theme

* Rename changelog files

Co-authored-by: runner <runner@fv-az308-698>
  • Loading branch information
Zayankovsky and runner authored Jan 4, 2023
1 parent b329337 commit 8322e43
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/bugfixes/6780.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed an issue with `NavigationView` that caused info panel to shrink in landscape mode with a full screen theme.
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<Context>()
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
Expand All @@ -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
Expand Down

0 comments on commit 8322e43

Please sign in to comment.