Skip to content

Commit

Permalink
Add example demonstrating missing initial content padding
Browse files Browse the repository at this point in the history
  • Loading branch information
kkris committed Oct 18, 2024
1 parent e660791 commit 9ef58d0
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<activity
android:name=".markerexamples.draggablemarkerscollectionwithpolygon.DraggableMarkersCollectionWithPolygonActivity"
android:exported="false"/>
<activity
android:name=".PaddedMapActivity"
android:exported="false"/>

<!-- Used by createComponentActivity() for unit testing -->
<activity android:name="androidx.activity.ComponentActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ class MainActivity : ComponentActivity() {
}) {
Text(getString(R.string.draggable_markers_collection_with_polygon))
}
Button(
onClick = {
context.startActivity(Intent(context, PaddedMapActivity::class.java))
}) {
Text("Map with content padding")
}
}
}
}
Expand Down
110 changes: 110 additions & 0 deletions app/src/main/java/com/google/maps/android/compose/PaddedMapActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.google.maps.android.compose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Button
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng

class PaddedMapActivity : ComponentActivity() {

companion object {
private val OVERLAY_HEIGHT = 250.dp
private val center = LatLng(1.35, 103.87)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
var isMapLoaded by remember { mutableStateOf(false) }
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(center, 11f)
}
val singaporeState = rememberMarkerState(position = center)

Box(Modifier.fillMaxSize()) {
GoogleMap(
cameraPositionState = cameraPositionState,
onMapLoaded = {
isMapLoaded = true
},
contentPadding = PaddingValues(
bottom = OVERLAY_HEIGHT
),
) {
Marker(
state = singaporeState,
title = "Center"
)
}
Column(
modifier = Modifier
.fillMaxWidth()
.background(Color.White.copy(alpha = 0.75f))
.height(OVERLAY_HEIGHT)
.align(Alignment.BottomCenter)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
modifier = Modifier.padding(10.dp).fillMaxWidth(),
text = "This overlay covers the bottom part of the map",
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
)
Button(
onClick = {
cameraPositionState.position = CameraPosition.fromLatLngZoom(center, 11f)
}
) {
Text("Set camera position to initial value")

}
}
}
if (!isMapLoaded) {
AnimatedVisibility(
modifier = Modifier
.matchParentSize(),
visible = !isMapLoaded,
enter = EnterTransition.None,
exit = fadeOut()
) {
CircularProgressIndicator(
modifier = Modifier
.background(MaterialTheme.colors.background)
.wrapContentSize()
)
}
}
}
}
}
}

0 comments on commit 9ef58d0

Please sign in to comment.