Skip to content

Commit

Permalink
fix: enable edge-to-edge in sample (#614)
Browse files Browse the repository at this point in the history
* fix: enable edge-to-edge in sample

https://developer.android.com/develop/ui/views/layout/edge-to-edge

* fix: changes MarkerClusteringActivity to use a Box vs a Surface which interfaces with map touch events

---------

Co-authored-by: dkhawk <[email protected]>
  • Loading branch information
Goooler and dkhawk authored Aug 27, 2024
1 parent 53830c5 commit a87a3b0
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -33,6 +35,7 @@ class AccessibilityActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
val singaporeState = rememberMarkerState(position = singapore)
val cameraPositionState = rememberCameraPositionState {
Expand All @@ -43,7 +46,10 @@ class AccessibilityActivity : ComponentActivity() {
mutableStateOf(MapProperties(mapType = MapType.NORMAL))
}

Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
) {
GoogleMap(
// mergeDescendants will remove accessibility from the entire map and content inside.
mergeDescendants = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.fadeOut
Expand All @@ -33,6 +34,7 @@ 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.systemBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
Expand Down Expand Up @@ -94,14 +96,18 @@ class BasicMapActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
var isMapLoaded by remember { mutableStateOf(false) }
// Observing and controlling the camera's state can be done with a CameraPositionState
val cameraPositionState = rememberCameraPositionState {
position = defaultCameraPosition
}

Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding()
) {
GoogleMapView(
cameraPositionState = cameraPositionState,
onMapLoaded = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.fadeOut
Expand All @@ -27,6 +28,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
Expand All @@ -49,7 +51,7 @@ class CustomControlsActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
var isMapLoaded by remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()
Expand All @@ -68,7 +70,10 @@ class CustomControlsActivity : ComponentActivity() {
position = defaultCameraPosition
}

Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
) {
GoogleMap(
modifier = Modifier.matchParentSize(),
cameraPositionState = cameraPositionState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import android.location.Location
import android.os.Bundle
import android.util.Log
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
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.fillMaxSize
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -76,7 +78,7 @@ class LocationTrackingActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
var isMapLoaded by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -108,7 +110,10 @@ class LocationTrackingActivity : AppCompatActivity() {
}
}

Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
) {
GoogleMap(
modifier = Modifier.matchParentSize(),
cameraPositionState = cameraPositionState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
Expand All @@ -45,10 +47,12 @@ class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MapsComposeSampleTheme {
Surface(
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
color = MaterialTheme.colors.background
) {
val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.util.Log
import android.view.MotionEvent
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
Expand Down Expand Up @@ -47,6 +48,7 @@ class MapInColumnActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
// Observing and controlling the camera's state can be done with a CameraPositionState
val cameraPositionState = rememberCameraPositionState {
Expand All @@ -63,7 +65,8 @@ class MapInColumnActivity : ComponentActivity() {
}

MapInColumn(
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
cameraPositionState,
columnScrollingEnabled = columnScrollingEnabled,
onMapTouched = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.google.maps.android.compose
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand All @@ -17,6 +18,7 @@ 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.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
Expand Down Expand Up @@ -86,7 +88,7 @@ private val allItems = countries.mapIndexed { index, country ->
class MapsInLazyColumnActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
var showLazyColumn by rememberSaveable { mutableStateOf(true) }
var visibleItems by rememberSaveable { mutableStateOf(allItems) }
Expand All @@ -95,7 +97,10 @@ class MapsInLazyColumnActivity : ComponentActivity() {
visibleItems = allItems.take(count.coerceIn(0, allItems.size))
}

Column {
Column(
Modifier.fillMaxSize()
.systemBarsPadding(),
) {
Row(
Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand All @@ -43,11 +45,15 @@ class RecompositionActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
val cameraPositionState = rememberCameraPositionState {
position = defaultCameraPosition
}
Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
) {
MapsComposeSampleTheme {
GoogleMapView(
modifier = Modifier.matchParentSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.maps.android.compose
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.fadeOut
Expand All @@ -26,6 +27,7 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
Expand All @@ -44,7 +46,7 @@ class ScaleBarActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
var isMapLoaded by remember { mutableStateOf(false) }

Expand All @@ -56,7 +58,10 @@ class ScaleBarActivity : ComponentActivity() {
val scaleBackground = MaterialTheme.colors.background.copy(alpha = 0.4f)
val scaleBorderStroke = BorderStroke(width = 1.dp, DarkGray.copy(alpha = 0.2f))

Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
) {
GoogleMap(
modifier = Modifier.matchParentSize(),
cameraPositionState = cameraPositionState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -26,6 +27,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -59,7 +61,7 @@ class StreetViewActivity : ComponentActivity() {
@OptIn(MapsExperimentalFeature::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
var isPanningEnabled by remember { mutableStateOf(false) }
var isZoomEnabled by remember { mutableStateOf(false) }
Expand All @@ -86,7 +88,11 @@ class StreetViewActivity : ComponentActivity() {
fetchStreetViewData(singapore, BuildConfig.MAPS_API_KEY)
}
}
Box(Modifier.fillMaxSize(), Alignment.BottomStart) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
contentAlignment = Alignment.BottomStart,
) {
if (streetViewResult == Status.OK) {
StreetView(
Modifier.matchParentSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import android.util.Log
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -57,6 +59,7 @@ class AdvancedMarkersActivity : ComponentActivity(), OnMapsSdkInitializedCallbac
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MapsInitializer.initialize(applicationContext, MapsInitializer.Renderer.LATEST, this)
enableEdgeToEdge()
setContent {
// Observing and controlling the camera's state can be done with a CameraPositionState
val cameraPositionState = rememberCameraPositionState {
Expand All @@ -78,7 +81,10 @@ class AdvancedMarkersActivity : ComponentActivity(), OnMapsSdkInitializedCallbac
}
false
}
Box(Modifier.fillMaxSize()) {
Box(
modifier = Modifier.fillMaxSize()
.systemBarsPadding(),
) {
GoogleMap(
modifier = Modifier.matchParentSize(),
googleMapOptionsFactory = {
Expand Down
Loading

0 comments on commit a87a3b0

Please sign in to comment.