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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set initial map padding (#326) #327

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Comment on lines +41 to 42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a brief comment here to inform a reader why padding must precede camera position?

Suggested change
applyContentPadding(map, contentPadding)
cameraPositionState.setMap(map)
applyContentPadding(map, contentPadding)
// set camera position after padding for correct centering
cameraPositionState.setMap(map)

if (contentDescription != null) {
map.setContentDescription(contentDescription)
Expand Down Expand Up @@ -132,6 +134,7 @@ internal inline fun MapUpdater(
clickListeners = clickListeners,
density = density,
layoutDirection = layoutDirection,
contentPadding = contentPadding
)
}
) {
Expand All @@ -152,15 +155,7 @@ internal inline fun MapUpdater(
set(mapProperties.maxZoomPreference) { map.setMaxZoomPreference(it) }
set(mapProperties.minZoomPreference) { map.setMinZoomPreference(it) }
set(contentPadding) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to change from set() to update(). Perhaps could move up to the other update() calls purely for consistency.

Suggested change
set(contentPadding) {
update(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 @@ -178,3 +173,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()
)
}
}