From 1bbf91e29c8b7453dac3b40210aa18bb9cb587fa Mon Sep 17 00:00:00 2001 From: Hasinjato Date: Wed, 22 Jul 2026 14:00:59 +0300 Subject: [PATCH] Optimize SafeDrawing fullscreen - android --- .../kotlin/mg/dot/feufaro/MainActivity.kt | 26 +++++--------- .../kotlin/mg/dot/feufaro/ScreenSolfa.kt | 17 +++++---- .../kotlin/mg/dot/feufaro/ui/DrawerUI.kt | 36 +++++++++---------- 3 files changed, 35 insertions(+), 44 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt index ffb36e6..a5e4fe2 100644 --- a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt @@ -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") diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt index 7cb0c5d..0bfedb6 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ScreenSolfa.kt @@ -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 ) diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt index 9b1bba3..bd6f501 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt @@ -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))