Skip to content

Commit

Permalink
fix: Set initial map padding (googlemaps#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkris committed Aug 1, 2023
1 parent 2422f06 commit ae012d1
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ internal class MapPropertiesNode(
var clickListeners: MapClickListeners,
var density: Density,
var layoutDirection: LayoutDirection,
contentPadding: PaddingValues
) : MapNode {

init {
applyContentPadding(map, contentPadding)
cameraPositionState.setMap(map)
if (contentDescription != null) {
map.setContentDescription(contentDescription)
Expand Down Expand Up @@ -130,6 +132,7 @@ internal inline fun MapUpdater(
clickListeners = clickListeners,
density = density,
layoutDirection = layoutDirection,
contentPadding = contentPadding
)
}
) {
Expand All @@ -150,15 +153,7 @@ internal inline fun MapUpdater(
set(mapProperties.maxZoomPreference) { map.setMaxZoomPreference(it) }
set(mapProperties.minZoomPreference) { map.setMinZoomPreference(it) }
set(contentPadding) {
val node = this
with(this.density) {
map.setPadding(
it.calculateLeftPadding(node.layoutDirection).roundToPx(),
it.calculateTopPadding().roundToPx(),
it.calculateRightPadding(node.layoutDirection).roundToPx(),
it.calculateBottomPadding().roundToPx()
)
}
applyContentPadding(map, it)
}

set(mapUiSettings.compassEnabled) { map.uiSettings.isCompassEnabled = it }
Expand All @@ -176,3 +171,15 @@ internal inline fun MapUpdater(
update(clickListeners) { this.clickListeners = it }
}
}

private fun MapPropertiesNode.applyContentPadding(map: GoogleMap, contentPadding: PaddingValues) {
val node = this
with (this.density) {
map.setPadding(
contentPadding.calculateLeftPadding(node.layoutDirection).roundToPx(),
contentPadding.calculateTopPadding().roundToPx(),
contentPadding.calculateRightPadding(node.layoutDirection).roundToPx(),
contentPadding.calculateBottomPadding().roundToPx()
)
}
}

0 comments on commit ae012d1

Please sign in to comment.