Skip to content

Commit

Permalink
Fix edge-to-edge on three-button nav bar (#4659)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Aug 16, 2024
1 parent 2e553f3 commit 6914b49
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
5 changes: 3 additions & 2 deletions lawnchair/src/app/lawnchair/BlankActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Handler
import android.os.Looper
import android.os.ResultReceiver
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -22,6 +21,7 @@ import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.core.os.bundleOf
import app.lawnchair.ui.theme.EdgeToEdge
import app.lawnchair.ui.theme.LawnchairTheme
import app.lawnchair.util.unsafeLazy
import kotlin.coroutines.resume
Expand All @@ -37,12 +37,13 @@ class BlankActivity : AppCompatActivity() {
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
if (!intent.hasExtra("dialogTitle")) {
startTargetActivity()
return
}
setContent {
EdgeToEdge()

LawnchairTheme {
Surface(
modifier = Modifier.fillMaxSize(),
Expand Down
37 changes: 3 additions & 34 deletions lawnchair/src/app/lawnchair/ui/preferences/PreferenceActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,23 @@ package app.lawnchair.ui.preferences

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.DisposableEffect
import androidx.core.net.toUri
import app.lawnchair.ui.theme.EdgeToEdge
import app.lawnchair.ui.theme.LawnchairTheme
import app.lawnchair.ui.theme.isSelectedThemeDark

class PreferenceActivity : AppCompatActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
val windowSizeClass = calculateWindowSizeClass(this)
val darkTheme = isSelectedThemeDark

DisposableEffect(darkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(
lightScrim,
darkScrim,
) { darkTheme },
)
onDispose {}
}
EdgeToEdge()

val windowSizeClass = calculateWindowSizeClass(this)
LawnchairTheme {
Preferences(
windowSizeClass,
Expand All @@ -70,15 +51,3 @@ class PreferenceActivity : AppCompatActivity() {
}
}
}

/**
* The default light scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val lightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)

/**
* The default dark scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val darkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
26 changes: 26 additions & 0 deletions lawnchair/src/app/lawnchair/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package app.lawnchair.ui.theme

import android.graphics.Color
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -50,6 +56,26 @@ fun LawnchairTheme(
)
}

@Composable
fun ComponentActivity.EdgeToEdge() {
val darkTheme = isSelectedThemeDark
LaunchedEffect(darkTheme) {
val barStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
detectDarkMode = { darkTheme },
)
enableEdgeToEdge(
statusBarStyle = barStyle,
navigationBarStyle = barStyle,
)

// Fix for three-button nav not properly going edge-to-edge.
// TODO: https://issuetracker.google.com/issues/298296168
window.setFlags(FLAG_LAYOUT_NO_LIMITS, FLAG_LAYOUT_NO_LIMITS)
}
}

@Composable
fun getColorScheme(darkTheme: Boolean): ColorScheme {
val context = LocalContext.current
Expand Down

0 comments on commit 6914b49

Please sign in to comment.