Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix info panel dimensions in landscape with a full screen theme #6811

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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