draw the app edge to edge and test the applying of dynamic status bar colors to fix animations on top app bar

This commit is contained in:
FunkyMuse 2023-07-10 21:51:44 +02:00
parent 06ac637e50
commit 935011b7e5
4 changed files with 30 additions and 20 deletions

View File

@ -2,13 +2,14 @@ package com.simplemobiletools.calculator.activities
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.*
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.simplemobiletools.calculator.compose.extensions.TransparentSystemBars
import com.simplemobiletools.calculator.compose.screens.SettingsScreen
import com.simplemobiletools.calculator.compose.theme.AppThemeSurface
import com.simplemobiletools.calculator.compose.theme.OnLifecycleEvent
@ -28,7 +29,9 @@ class SettingsActivity : AppCompatActivity() {
@SuppressLint("NewApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
TransparentSystemBars()
AppThemeSurface {
val context = LocalContext.current
val preventPhoneFromSleeping by preferences.preventPhoneFromSleepingFlow.collectAsStateWithLifecycle(preferences.preventPhoneFromSleeping)

View File

@ -3,8 +3,23 @@ package com.simplemobiletools.calculator.compose.extensions
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import com.google.accompanist.systemuicontroller.rememberSystemUiController
fun Context.getActivity(): Activity {
if (this is Activity) return this
return if (this is ContextWrapper) baseContext.getActivity() else getActivity()
}
@Composable
fun TransparentSystemBars() {
val systemUiController = rememberSystemUiController()
val isSystemInDarkTheme = isSystemInDarkTheme()
SideEffect {
systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = isSystemInDarkTheme)
}
}

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.calculator.compose.screens
import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
@ -9,11 +10,13 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.lerp
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
@ -25,9 +28,7 @@ import com.simplemobiletools.calculator.compose.settings.SettingsCheckBoxCompone
import com.simplemobiletools.calculator.compose.settings.SettingsGroup
import com.simplemobiletools.calculator.compose.settings.SettingsPreferenceComponent
import com.simplemobiletools.calculator.compose.settings.SettingsTitleTextComponent
import com.simplemobiletools.calculator.compose.theme.AppThemeSurface
import com.simplemobiletools.calculator.compose.theme.divider_grey
import com.simplemobiletools.calculator.compose.theme.isSurfaceLitWell
import com.simplemobiletools.calculator.compose.theme.*
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.getCustomizeColorsString
import com.simplemobiletools.commons.helpers.isTiramisuPlus
@ -65,19 +66,14 @@ fun SettingsScreen(
stop = scrolledTextColor,
fraction = fraction
)
val scrolledColorStatusBar = lerp(
start = MaterialTheme.colorScheme.surface,
stop = MaterialTheme.colorScheme.primary,
fraction = fraction
)
systemUiController.setStatusBarColor(scrolledColorStatusBar, transformColorForLightContent = {
scrolledColor
})
SideEffect {
systemUiController.setStatusBarColor(Color.Transparent, darkIcons = scrolledColor.isNotLitWell())
}
Scaffold(
modifier = Modifier
.nestedScroll(scrollBehavior.nestedScrollConnection)
.fillMaxSize(),
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(
title = {
@ -102,7 +98,8 @@ fun SettingsScreen(
colors = TopAppBarDefaults.largeTopAppBarColors(
scrolledContainerColor = topBarsScrolledContainerColor
),
)
)
}
) { paddingValues ->
Box(

View File

@ -136,12 +136,8 @@ fun isSurfaceNotLitWell() = MaterialTheme.colorScheme.surface.luminance() < LUMI
@ReadOnlyComposable
fun isSurfaceLitWell() = MaterialTheme.colorScheme.surface.luminance() > LUMINANCE_THRESHOLD
@Composable
@ReadOnlyComposable
fun Color.isLitWell() = luminance() > LUMINANCE_THRESHOLD
@Composable
@ReadOnlyComposable
fun Color.isNotLitWell() = luminance() < LUMINANCE_THRESHOLD
@ -190,7 +186,6 @@ private fun Theme(
SideEffect {
systemUiController.setNavigationBarColor(colorScheme.surface, navigationBarContrastEnforced = false)
systemUiController.setSystemBarsColor(colorScheme.surface)
}
SideEffect {