@@ -2,17 +2,17 @@ package com.mapbox.navigation.dropin.camera
2
2
3
3
import android.content.res.Configuration
4
4
import android.view.View
5
+ import com.google.android.material.bottomsheet.BottomSheetBehavior
5
6
import com.mapbox.maps.EdgeInsets
6
7
import com.mapbox.navigation.core.MapboxNavigation
7
8
import com.mapbox.navigation.dropin.R
8
9
import com.mapbox.navigation.dropin.databinding.MapboxNavigationViewLayoutBinding
9
- import com.mapbox.navigation.ui.app.internal.Store
10
+ import com.mapbox.navigation.dropin.navigationview.NavigationViewContext
10
11
import com.mapbox.navigation.ui.app.internal.camera.CameraAction
11
- import com.mapbox.navigation.ui.app.internal.navigation.NavigationState
12
12
import com.mapbox.navigation.ui.base.lifecycle.UIComponent
13
13
14
14
internal class CameraLayoutObserver (
15
- private val store : Store ,
15
+ private val context : NavigationViewContext ,
16
16
private val mapView : View ,
17
17
private val binding : MapboxNavigationViewLayoutBinding ,
18
18
) : UIComponent() {
@@ -21,63 +21,43 @@ internal class CameraLayoutObserver(
21
21
.getDimensionPixelSize(R .dimen.mapbox_camera_overview_padding_v).toDouble()
22
22
private val hPadding = binding.root.resources
23
23
.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()
28
24
29
25
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()
35
27
}
36
28
37
29
override fun onAttached (mapboxNavigation : MapboxNavigation ) {
38
30
super .onAttached(mapboxNavigation)
39
31
binding.coordinatorLayout.addOnLayoutChangeListener(layoutListener)
32
+ context.behavior.infoPanelBehavior.bottomSheetState.observe { updateCameraPadding() }
40
33
}
41
34
42
35
override fun onDetached (mapboxNavigation : MapboxNavigation ) {
43
36
super .onDetached(mapboxNavigation)
44
37
binding.coordinatorLayout.removeOnLayoutChangeListener(layoutListener)
45
38
}
46
39
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()
60
44
}
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)
61
52
}
62
53
63
54
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)
81
61
}
82
62
83
63
private fun deviceOrientation () = binding.root.resources.configuration.orientation
0 commit comments