Optimize SafeDrawing fullscreen - android
This commit is contained in:
parent
203c14c457
commit
1bbf91e29c
3 changed files with 35 additions and 44 deletions
|
|
@ -59,33 +59,25 @@ class MainActivity : ComponentActivity() {
|
|||
fun updateSystemBarsVisibility(isFullScreen: Boolean) {
|
||||
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
|
||||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
if (isFullScreen) {
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars())
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.statusBars())
|
||||
windowInsetsController.systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
|
||||
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||
if (isFullScreen && (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars())
|
||||
}
|
||||
}
|
||||
// Empêcher de rétablir la StatusBar quand le clavier s'ouvre
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, insets ->
|
||||
if (isFullScreen) {
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars())
|
||||
}
|
||||
ViewCompat.onApplyWindowInsets(view, insets)
|
||||
}
|
||||
window.statusBarColor = android.graphics.Color.TRANSPARENT
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
window.attributes.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
} else {
|
||||
window.decorView.setOnSystemUiVisibilityChangeListener(null)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView, null)
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_DEFAULT
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars())
|
||||
|
||||
val isNightMode = (resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
windowInsetsController.isAppearanceLightStatusBars = !isNightMode
|
||||
windowInsetsController.isAppearanceLightNavigationBars = !isNightMode
|
||||
}
|
||||
}
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import androidx.compose.foundation.rememberScrollState
|
|||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Code
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconToggleButton
|
||||
|
|
@ -93,21 +94,19 @@ object ScreenSolfa : Screen {
|
|||
},
|
||||
solfaScrollState = scrollState
|
||||
) { paddingValues ->
|
||||
val partitionInsets = if (isFullScreenEnabled) {
|
||||
WindowInsets(0, 0, 0, 0)
|
||||
} else {
|
||||
WindowInsets.ime
|
||||
}
|
||||
Box(
|
||||
Modifier.fillMaxSize()
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.consumeWindowInsets(paddingValues)
|
||||
.windowInsetsPadding(partitionInsets)
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Column(
|
||||
Modifier
|
||||
.verticalScroll(scrollState)
|
||||
.windowInsetsPadding(
|
||||
if (isFullScreenEnabled) WindowInsets(0)
|
||||
else WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
||||
)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(
|
||||
onDoubleTap = { offset ->
|
||||
|
|
@ -181,7 +180,7 @@ object ScreenSolfa : Screen {
|
|||
modifier = Modifier.size(40.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (isEditMode) Icons.Filled.Check else Icons.Filled.Edit,
|
||||
imageVector = if (isEditMode) Icons.Filled.Check else Icons.Filled.Code,
|
||||
contentDescription = "Mode édition",
|
||||
tint = if (isEditMode) ColorPrefixB else Color.Gray
|
||||
)
|
||||
|
|
|
|||
|
|
@ -111,9 +111,7 @@ fun MainScreenWithDrawer(
|
|||
val fullscreenController = LocalFullscreenController.current
|
||||
|
||||
LaunchedEffect(isFullScreenEnabled, isSearchActive) {
|
||||
if(isFullScreenEnabled) {
|
||||
fullscreenController(true)
|
||||
}
|
||||
fullscreenController(isFullScreenEnabled)
|
||||
}
|
||||
val isImeVisible = WindowInsets.ime.asPaddingValues().calculateBottomPadding() > 0.dp
|
||||
LaunchedEffect(isImeVisible) {
|
||||
|
|
@ -252,8 +250,9 @@ fun MainScreenWithDrawer(
|
|||
}
|
||||
val favoritePaths by sharedScreenModel.playlistItems.collectAsState()
|
||||
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
|
||||
val isLandscape = maxWidth > maxHeight
|
||||
val topAppBarHeight = if (isAndroid) {
|
||||
if(maxWidth > maxHeight) {
|
||||
if(isLandscape) {
|
||||
55.dp
|
||||
} else {
|
||||
if (isFullScreenEnabled) 70.dp else 80.dp
|
||||
|
|
@ -261,23 +260,26 @@ fun MainScreenWithDrawer(
|
|||
} else {
|
||||
50.dp
|
||||
}
|
||||
val isLandscape = maxWidth > maxHeight
|
||||
|
||||
Scaffold(
|
||||
contentWindowInsets = if (isAndroid && !isFullScreenEnabled && !isLandscape) {
|
||||
WindowInsets.safeDrawing.union(WindowInsets.displayCutout)
|
||||
} else {
|
||||
contentWindowInsets = if (isFullScreenEnabled) {
|
||||
WindowInsets(0, 0, 0, 0)
|
||||
} else {
|
||||
if(!isLandscape) {
|
||||
WindowInsets.safeDrawing
|
||||
} else {
|
||||
WindowInsets(0, 0, 0, 0)
|
||||
}
|
||||
},
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
modifier = Modifier.height(topAppBarHeight)
|
||||
.windowInsetsPadding(
|
||||
if (isAndroid && !isFullScreenEnabled && !isLandscape) {
|
||||
WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
|
||||
} else {
|
||||
WindowInsets(0, 0, 0, 0)
|
||||
}
|
||||
),
|
||||
modifier = Modifier.height(topAppBarHeight),
|
||||
windowInsets = if(!isLandscape) {
|
||||
WindowInsets.safeDrawing.only(
|
||||
WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
|
||||
} else {
|
||||
WindowInsets(0, 0, 0, 0)
|
||||
},
|
||||
title = {
|
||||
AnimatedContent(
|
||||
targetState = isSearchActive,
|
||||
|
|
@ -758,8 +760,6 @@ fun MainScreenWithDrawer(
|
|||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.consumeWindowInsets(paddingValues)
|
||||
/*.windowInsetsPadding(currentInsets.union(WindowInsets.ime))*/
|
||||
) {
|
||||
content(PaddingValues(0.dp))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue