From 9361861774667321564d71061c16a42eb0a3123d Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Mon, 19 Aug 2024 09:44:31 -0400 Subject: [PATCH] Enable edge-to-edge (#5) https://developer.android.com/develop/ui/views/layout/edge-to-edge --- .../com/example/mountainmarkers/MainActivity.kt | 2 ++ .../com/example/mountainmarkers/ui/theme/Theme.kt | 14 -------------- .../com/example/mountainmarkers/MainActivity.kt | 3 ++- .../com/example/mountainmarkers/ui/theme/Theme.kt | 14 -------------- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/solution/app/src/main/java/com/example/mountainmarkers/MainActivity.kt b/solution/app/src/main/java/com/example/mountainmarkers/MainActivity.kt index 32deca0..c8d50e5 100644 --- a/solution/app/src/main/java/com/example/mountainmarkers/MainActivity.kt +++ b/solution/app/src/main/java/com/example/mountainmarkers/MainActivity.kt @@ -17,6 +17,7 @@ package com.example.mountainmarkers import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels import androidx.compose.foundation.background import androidx.compose.material3.MaterialTheme @@ -44,6 +45,7 @@ import dagger.hilt.android.AndroidEntryPoint class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + enableEdgeToEdge() setContent { val unitsConverter = if (LocalConfiguration.current.locales.get(0).country == "US") { diff --git a/solution/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt b/solution/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt index 64722d4..6b7d90e 100644 --- a/solution/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt +++ b/solution/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt @@ -1,6 +1,5 @@ package com.example.mountainmarkers.ui.theme -import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme @@ -9,11 +8,7 @@ import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect -import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalView -import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, @@ -44,15 +39,6 @@ fun MountainMarkersTheme( else -> LightColorScheme } - val view = LocalView.current - if (!view.isInEditMode) { - SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.primary.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme - } - } - MaterialTheme( colorScheme = colorScheme, typography = Typography, diff --git a/starter/app/src/main/java/com/example/mountainmarkers/MainActivity.kt b/starter/app/src/main/java/com/example/mountainmarkers/MainActivity.kt index 32deca0..719d49c 100644 --- a/starter/app/src/main/java/com/example/mountainmarkers/MainActivity.kt +++ b/starter/app/src/main/java/com/example/mountainmarkers/MainActivity.kt @@ -17,6 +17,7 @@ package com.example.mountainmarkers import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels import androidx.compose.foundation.background import androidx.compose.material3.MaterialTheme @@ -44,6 +45,7 @@ import dagger.hilt.android.AndroidEntryPoint class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + enableEdgeToEdge() setContent { val unitsConverter = if (LocalConfiguration.current.locales.get(0).country == "US") { @@ -107,4 +109,3 @@ class MainActivity : ComponentActivity() { } } } - diff --git a/starter/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt b/starter/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt index 64722d4..6b7d90e 100644 --- a/starter/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt +++ b/starter/app/src/main/java/com/example/mountainmarkers/ui/theme/Theme.kt @@ -1,6 +1,5 @@ package com.example.mountainmarkers.ui.theme -import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme @@ -9,11 +8,7 @@ import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect -import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalView -import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, @@ -44,15 +39,6 @@ fun MountainMarkersTheme( else -> LightColorScheme } - val view = LocalView.current - if (!view.isInEditMode) { - SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.primary.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme - } - } - MaterialTheme( colorScheme = colorScheme, typography = Typography,