Skip to content

Commit

Permalink
chore: Set initial map padding (#326) (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkris authored Oct 29, 2024
1 parent e660791 commit e9df1cf
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ internal class MapPropertiesNode(
contentDescription: String?,
var density: Density,
var layoutDirection: LayoutDirection,
contentPadding: PaddingValues
) : MapNode {

init {
applyContentPadding(map, contentPadding)
// set camera position after padding for correct centering
cameraPositionState.setMap(map)
if (contentDescription != null) {
map.setContentDescription(contentDescription)
Expand Down Expand Up @@ -111,6 +114,7 @@ internal inline fun MapUpdater(mapUpdaterState: MapUpdaterState) = with(mapUpdat
cameraPositionState = cameraPositionState,
density = density,
layoutDirection = layoutDirection,
contentPadding = contentPadding
)
}
) {
Expand All @@ -119,6 +123,9 @@ internal inline fun MapUpdater(mapUpdaterState: MapUpdaterState) = with(mapUpdat
update(density) { this.density = it }
update(layoutDirection) { this.layoutDirection = it }
update(contentDescription) { this.contentDescription = it }
update(contentPadding) {
applyContentPadding(map, it)
}

set(locationSource) { map.setLocationSource(it) }
set(mapProperties.isBuildingEnabled) { map.isBuildingsEnabled = it }
Expand All @@ -135,17 +142,6 @@ internal inline fun MapUpdater(mapUpdaterState: MapUpdaterState) = with(mapUpdat
map.mapColorScheme = 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()
)
}
}

set(mapUiSettings.compassEnabled) { map.uiSettings.isCompassEnabled = it }
set(mapUiSettings.indoorLevelPickerEnabled) { map.uiSettings.isIndoorLevelPickerEnabled = it }
Expand All @@ -161,3 +157,15 @@ internal inline fun MapUpdater(mapUpdaterState: MapUpdaterState) = with(mapUpdat
update(cameraPositionState) { this.cameraPositionState = 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 e9df1cf

Please sign in to comment.