11package com.telefonica.tweaks.ui
22
3+ import android.content.res.Configuration
34import android.widget.Toast
45import androidx.compose.foundation.ExperimentalFoundationApi
56import androidx.compose.foundation.background
@@ -10,13 +11,19 @@ import androidx.compose.foundation.layout.ColumnScope
1011import androidx.compose.foundation.layout.Row
1112import androidx.compose.foundation.layout.Spacer
1213import androidx.compose.foundation.layout.WindowInsets
14+ import androidx.compose.foundation.layout.WindowInsetsSides
15+ import androidx.compose.foundation.layout.displayCutout
1316import androidx.compose.foundation.layout.fillMaxSize
1417import androidx.compose.foundation.layout.fillMaxWidth
1518import androidx.compose.foundation.layout.navigationBars
19+ import androidx.compose.foundation.layout.only
1620import androidx.compose.foundation.layout.padding
1721import androidx.compose.foundation.layout.size
1822import androidx.compose.foundation.layout.statusBars
23+ import androidx.compose.foundation.layout.systemGestures
24+ import androidx.compose.foundation.layout.union
1925import androidx.compose.foundation.layout.windowInsetsBottomHeight
26+ import androidx.compose.foundation.layout.windowInsetsPadding
2027import androidx.compose.foundation.layout.windowInsetsTopHeight
2128import androidx.compose.foundation.rememberScrollState
2229import androidx.compose.foundation.text.KeyboardActions
@@ -57,6 +64,7 @@ import androidx.compose.ui.focus.FocusRequester
5764import androidx.compose.ui.focus.focusRequester
5865import androidx.compose.ui.graphics.compositeOver
5966import androidx.compose.ui.platform.LocalClipboardManager
67+ import androidx.compose.ui.platform.LocalConfiguration
6068import androidx.compose.ui.platform.LocalContext
6169import androidx.compose.ui.platform.LocalSoftwareKeyboardController
6270import androidx.compose.ui.platform.SoftwareKeyboardController
@@ -99,12 +107,11 @@ fun TweaksScreen(
99107 .fillMaxSize()
100108 .background(TweaksTheme .colors.tweaksBackground)
101109 .padding(horizontal = 16 .dp)
110+ .edgeToEdgeInsetsForOrientation()
102111 .verticalScroll(scrollState),
103112 verticalArrangement = Arrangement .spacedBy(8 .dp),
104113 horizontalAlignment = Alignment .CenterHorizontally ,
105114 ) {
106- Spacer (modifier = Modifier .windowInsetsTopHeight(WindowInsets .statusBars))
107-
108115 tweaksGraph.cover?.let {
109116 TweakGroupBody (
110117 tweakGroup = it,
@@ -118,7 +125,6 @@ fun TweaksScreen(
118125 text = category.title,
119126 )
120127 }
121- Spacer (modifier = Modifier .windowInsetsBottomHeight(WindowInsets .navigationBars))
122128 }
123129}
124130
@@ -134,6 +140,7 @@ fun TweaksCategoryScreen(
134140 .fillMaxSize()
135141 .background(TweaksTheme .colors.tweaksBackground)
136142 .padding(horizontal = 16 .dp)
143+ .edgeToEdgeInsetsForOrientation()
137144 .verticalScroll(scrollState),
138145 verticalArrangement = Arrangement .spacedBy(8 .dp),
139146 horizontalAlignment = Alignment .CenterHorizontally ,
@@ -600,4 +607,22 @@ internal fun TweakButton(
600607 color = TweaksTheme .colors.tweaksOnPrimary,
601608 )
602609 }
610+ }
611+
612+ @Composable
613+ fun Modifier.edgeToEdgeInsetsForOrientation (): Modifier {
614+ val isLandscape =
615+ LocalConfiguration .current.orientation == Configuration .ORIENTATION_LANDSCAPE
616+
617+ val sides =
618+ if (isLandscape) WindowInsetsSides .Top + WindowInsetsSides .Horizontal
619+ else WindowInsetsSides .Top + WindowInsetsSides .Bottom
620+
621+ var base = WindowInsets .statusBars
622+ .union(WindowInsets .navigationBars)
623+ .union(WindowInsets .displayCutout)
624+ .union(WindowInsets .systemGestures)
625+ .only(sides)
626+
627+ return this .windowInsetsPadding(base)
603628}
0 commit comments