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) {
|
fun updateSystemBarsVisibility(isFullScreen: Boolean) {
|
||||||
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
|
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
|
||||||
|
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
if (isFullScreen) {
|
if (isFullScreen) {
|
||||||
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars())
|
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
|
||||||
|
windowInsetsController.show(WindowInsetsCompat.Type.statusBars())
|
||||||
windowInsetsController.systemBarsBehavior =
|
windowInsetsController.systemBarsBehavior =
|
||||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
window.statusBarColor = android.graphics.Color.TRANSPARENT
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
window.attributes.layoutInDisplayCutoutMode =
|
window.attributes.layoutInDisplayCutoutMode =
|
||||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.decorView.setOnSystemUiVisibilityChangeListener(null)
|
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView, null)
|
|
||||||
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_DEFAULT
|
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")
|
@Suppress("OVERRIDE_DEPRECATION")
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.Check
|
||||||
|
import androidx.compose.material.icons.filled.Code
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconToggleButton
|
import androidx.compose.material3.IconToggleButton
|
||||||
|
|
@ -93,21 +94,19 @@ object ScreenSolfa : Screen {
|
||||||
},
|
},
|
||||||
solfaScrollState = scrollState
|
solfaScrollState = scrollState
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
val partitionInsets = if (isFullScreenEnabled) {
|
|
||||||
WindowInsets(0, 0, 0, 0)
|
|
||||||
} else {
|
|
||||||
WindowInsets.ime
|
|
||||||
}
|
|
||||||
Box(
|
Box(
|
||||||
Modifier.fillMaxSize()
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.consumeWindowInsets(paddingValues)
|
|
||||||
.windowInsetsPadding(partitionInsets)
|
|
||||||
.padding(horizontal = 16.dp)
|
.padding(horizontal = 16.dp)
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.verticalScroll(scrollState)
|
.verticalScroll(scrollState)
|
||||||
|
.windowInsetsPadding(
|
||||||
|
if (isFullScreenEnabled) WindowInsets(0)
|
||||||
|
else WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
||||||
|
)
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
onDoubleTap = { offset ->
|
onDoubleTap = { offset ->
|
||||||
|
|
@ -181,7 +180,7 @@ object ScreenSolfa : Screen {
|
||||||
modifier = Modifier.size(40.dp)
|
modifier = Modifier.size(40.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = if (isEditMode) Icons.Filled.Check else Icons.Filled.Edit,
|
imageVector = if (isEditMode) Icons.Filled.Check else Icons.Filled.Code,
|
||||||
contentDescription = "Mode édition",
|
contentDescription = "Mode édition",
|
||||||
tint = if (isEditMode) ColorPrefixB else Color.Gray
|
tint = if (isEditMode) ColorPrefixB else Color.Gray
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,7 @@ fun MainScreenWithDrawer(
|
||||||
val fullscreenController = LocalFullscreenController.current
|
val fullscreenController = LocalFullscreenController.current
|
||||||
|
|
||||||
LaunchedEffect(isFullScreenEnabled, isSearchActive) {
|
LaunchedEffect(isFullScreenEnabled, isSearchActive) {
|
||||||
if(isFullScreenEnabled) {
|
fullscreenController(isFullScreenEnabled)
|
||||||
fullscreenController(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val isImeVisible = WindowInsets.ime.asPaddingValues().calculateBottomPadding() > 0.dp
|
val isImeVisible = WindowInsets.ime.asPaddingValues().calculateBottomPadding() > 0.dp
|
||||||
LaunchedEffect(isImeVisible) {
|
LaunchedEffect(isImeVisible) {
|
||||||
|
|
@ -252,8 +250,9 @@ fun MainScreenWithDrawer(
|
||||||
}
|
}
|
||||||
val favoritePaths by sharedScreenModel.playlistItems.collectAsState()
|
val favoritePaths by sharedScreenModel.playlistItems.collectAsState()
|
||||||
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
|
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
|
||||||
|
val isLandscape = maxWidth > maxHeight
|
||||||
val topAppBarHeight = if (isAndroid) {
|
val topAppBarHeight = if (isAndroid) {
|
||||||
if(maxWidth > maxHeight) {
|
if(isLandscape) {
|
||||||
55.dp
|
55.dp
|
||||||
} else {
|
} else {
|
||||||
if (isFullScreenEnabled) 70.dp else 80.dp
|
if (isFullScreenEnabled) 70.dp else 80.dp
|
||||||
|
|
@ -261,23 +260,26 @@ fun MainScreenWithDrawer(
|
||||||
} else {
|
} else {
|
||||||
50.dp
|
50.dp
|
||||||
}
|
}
|
||||||
val isLandscape = maxWidth > maxHeight
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
contentWindowInsets = if (isAndroid && !isFullScreenEnabled && !isLandscape) {
|
contentWindowInsets = if (isFullScreenEnabled) {
|
||||||
WindowInsets.safeDrawing.union(WindowInsets.displayCutout)
|
|
||||||
} else {
|
|
||||||
WindowInsets(0, 0, 0, 0)
|
WindowInsets(0, 0, 0, 0)
|
||||||
},
|
} else {
|
||||||
topBar = {
|
if(!isLandscape) {
|
||||||
TopAppBar(
|
WindowInsets.safeDrawing
|
||||||
modifier = Modifier.height(topAppBarHeight)
|
|
||||||
.windowInsetsPadding(
|
|
||||||
if (isAndroid && !isFullScreenEnabled && !isLandscape) {
|
|
||||||
WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
|
|
||||||
} else {
|
} else {
|
||||||
WindowInsets(0, 0, 0, 0)
|
WindowInsets(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
),
|
},
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
modifier = Modifier.height(topAppBarHeight),
|
||||||
|
windowInsets = if(!isLandscape) {
|
||||||
|
WindowInsets.safeDrawing.only(
|
||||||
|
WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
|
||||||
|
} else {
|
||||||
|
WindowInsets(0, 0, 0, 0)
|
||||||
|
},
|
||||||
title = {
|
title = {
|
||||||
AnimatedContent(
|
AnimatedContent(
|
||||||
targetState = isSearchActive,
|
targetState = isSearchActive,
|
||||||
|
|
@ -758,8 +760,6 @@ fun MainScreenWithDrawer(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.consumeWindowInsets(paddingValues)
|
|
||||||
/*.windowInsetsPadding(currentInsets.union(WindowInsets.ime))*/
|
|
||||||
) {
|
) {
|
||||||
content(PaddingValues(0.dp))
|
content(PaddingValues(0.dp))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue