@@ -2,17 +2,17 @@ package com.mapbox.navigation.dropin.camera
22
33import android.content.res.Configuration
44import android.view.View
5+ import com.google.android.material.bottomsheet.BottomSheetBehavior
56import com.mapbox.maps.EdgeInsets
67import com.mapbox.navigation.core.MapboxNavigation
78import com.mapbox.navigation.dropin.R
89import com.mapbox.navigation.dropin.databinding.MapboxNavigationViewLayoutBinding
9- import com.mapbox.navigation.ui.app.internal.Store
10+ import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
1011import com.mapbox.navigation.ui.app.internal.camera.CameraAction
11- import com.mapbox.navigation.ui.app.internal.navigation.NavigationState
1212import com.mapbox.navigation.ui.base.lifecycle.UIComponent
1313
1414internal class CameraLayoutObserver (
15- private val store : Store ,
15+ private val context : NavigationViewContext ,
1616 private val mapView : View ,
1717 private val binding : MapboxNavigationViewLayoutBinding ,
1818) : UIComponent() {
@@ -21,63 +21,43 @@ internal class CameraLayoutObserver(
2121 .getDimensionPixelSize(R .dimen.mapbox_camera_overview_padding_v).toDouble()
2222 private val hPadding = binding.root.resources
2323 .getDimensionPixelSize(R .dimen.mapbox_camera_overview_padding_h).toDouble()
24- private val vPaddingLandscape = binding.root.resources
25- .getDimensionPixelSize(R .dimen.mapbox_camera_overview_padding_landscape_v).toDouble()
26- private val hPaddingLandscape = binding.root.resources
27- .getDimensionPixelSize(R .dimen.mapbox_camera_overview_padding_landscape_h).toDouble()
2824
2925 private val layoutListener = View .OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
30- val edgeInsets = when (deviceOrientation()) {
31- Configuration .ORIENTATION_LANDSCAPE -> getLandscapePadding()
32- else -> getPortraitPadding()
33- }
34- store.dispatch(CameraAction .UpdatePadding (edgeInsets))
26+ updateCameraPadding()
3527 }
3628
3729 override fun onAttached (mapboxNavigation : MapboxNavigation ) {
3830 super .onAttached(mapboxNavigation)
3931 binding.coordinatorLayout.addOnLayoutChangeListener(layoutListener)
32+ context.behavior.infoPanelBehavior.bottomSheetState.observe { updateCameraPadding() }
4033 }
4134
4235 override fun onDetached (mapboxNavigation : MapboxNavigation ) {
4336 super .onDetached(mapboxNavigation)
4437 binding.coordinatorLayout.removeOnLayoutChangeListener(layoutListener)
4538 }
4639
47- private fun getPortraitPadding (): EdgeInsets {
48- val top = binding.guidanceLayout.height.toDouble()
49- val bottom = mapView.height.toDouble() - binding.roadNameLayout.top.toDouble()
50- return when (store.state.value.navigation) {
51- is NavigationState .DestinationPreview ,
52- is NavigationState .FreeDrive ,
53- is NavigationState .RoutePreview -> {
54- EdgeInsets (vPadding, hPadding, bottom, hPadding)
55- }
56- is NavigationState .ActiveNavigation ,
57- is NavigationState .Arrival -> {
58- EdgeInsets (vPadding + top, hPadding, bottom, hPadding)
59- }
40+ private fun updateCameraPadding () {
41+ val edgeInsets = when (deviceOrientation()) {
42+ Configuration .ORIENTATION_LANDSCAPE -> getLandscapePadding()
43+ else -> getPortraitPadding()
6044 }
45+ context.store.dispatch(CameraAction .UpdatePadding (edgeInsets))
46+ }
47+
48+ private fun getPortraitPadding (): EdgeInsets {
49+ val top = binding.guidanceLayout.bottom
50+ val bottom = mapView.height - binding.roadNameLayout.top
51+ return EdgeInsets (vPadding + top, hPadding, vPadding + bottom, hPadding)
6152 }
6253
6354 private fun getLandscapePadding (): EdgeInsets {
64- val bottom = mapView.height.toDouble() - binding.roadNameLayout.top.toDouble()
65- return when (store.state.value.navigation) {
66- is NavigationState .FreeDrive -> {
67- EdgeInsets (vPaddingLandscape, hPaddingLandscape, bottom, hPaddingLandscape)
68- }
69- is NavigationState .DestinationPreview ,
70- is NavigationState .RoutePreview ,
71- is NavigationState .ActiveNavigation ,
72- is NavigationState .Arrival -> {
73- EdgeInsets (
74- vPaddingLandscape,
75- hPaddingLandscape + binding.infoPanelLayout.right.toDouble(),
76- bottom,
77- hPaddingLandscape
78- )
79- }
80- }
55+ val bottomSheetState = context.behavior.infoPanelBehavior.bottomSheetState.value
56+ val isBottomSheetVisible =
57+ bottomSheetState != null && bottomSheetState != BottomSheetBehavior .STATE_HIDDEN
58+ val bottomSheetWidth = if (isBottomSheetVisible) binding.infoPanelLayout.right else 0
59+ val bottom = mapView.height - binding.roadNameLayout.top
60+ return EdgeInsets (vPadding, hPadding + bottomSheetWidth, vPadding + bottom, hPadding)
8161 }
8262
8363 private fun deviceOrientation () = binding.root.resources.configuration.orientation
0 commit comments