Skip to content

Commit aada2bf

Browse files
authored
Merge pull request #1299 from utkarshdalal/remove-status-bar
Made layouts for appscreen and libraryscreen cutout/notch aware
2 parents 03d7145 + 82f7360 commit aada2bf

3 files changed

Lines changed: 45 additions & 13 deletions

File tree

app/src/main/java/app/gamenative/ui/screen/library/LibraryAppScreen.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ import androidx.compose.foundation.layout.Box
2323
import androidx.compose.foundation.layout.Column
2424
import androidx.compose.foundation.layout.Row
2525
import androidx.compose.foundation.layout.Spacer
26+
import androidx.compose.foundation.layout.WindowInsets
27+
import androidx.compose.foundation.layout.WindowInsetsSides
28+
import androidx.compose.foundation.layout.displayCutout
2629
import androidx.compose.foundation.layout.fillMaxSize
2730
import androidx.compose.foundation.layout.fillMaxWidth
2831
import androidx.compose.foundation.layout.heightIn
2932
import androidx.compose.foundation.layout.height
33+
import androidx.compose.foundation.layout.only
3034
import androidx.compose.foundation.layout.padding
3135
import androidx.compose.foundation.layout.size
36+
import androidx.compose.foundation.layout.statusBars
37+
import androidx.compose.foundation.layout.union
3238
import androidx.compose.foundation.layout.width
39+
import androidx.compose.foundation.layout.windowInsetsPadding
3340
import androidx.compose.foundation.relocation.BringIntoViewRequester
3441
import androidx.compose.foundation.relocation.bringIntoViewRequester
3542
import androidx.compose.foundation.rememberScrollState
@@ -739,12 +746,23 @@ internal fun AppScreenContent(
739746
),
740747
)
741748

742-
// Back button (top left)
749+
// Back button (top left).
750+
// The hero image is intentionally drawn full-bleed through the status bar
751+
// and any display cutout (notch / hole-punch / side cutout). The button
752+
// itself, however, has to stay tappable, so it's pushed inwards by whichever
753+
// is larger of the status bar inset or the cutout inset on each affected
754+
// edge before the visual 16dp padding is applied.
743755
ActionIconButton(
744756
icon = Icons.AutoMirrored.Filled.ArrowBack,
745757
contentDescription = stringResource(R.string.back),
746758
onClick = onBack,
747-
modifier = Modifier.padding(16.dp),
759+
modifier = Modifier
760+
.windowInsetsPadding(
761+
WindowInsets.statusBars
762+
.union(WindowInsets.displayCutout)
763+
.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
764+
)
765+
.padding(16.dp),
748766
)
749767

750768
// Bottom overlay with title and action bar

app/src/main/java/app/gamenative/ui/screen/library/LibraryScreen.kt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ import androidx.compose.foundation.layout.Row
1515
import androidx.compose.foundation.layout.Spacer
1616
import androidx.compose.foundation.layout.WindowInsets
1717
import androidx.compose.foundation.layout.asPaddingValues
18+
import androidx.compose.foundation.layout.displayCutout
1819
import androidx.compose.foundation.layout.displayCutoutPadding
1920
import androidx.compose.foundation.layout.fillMaxSize
2021
import androidx.compose.foundation.layout.fillMaxWidth
22+
import androidx.compose.foundation.layout.only
2123
import androidx.compose.foundation.layout.padding
2224
import androidx.compose.foundation.layout.statusBars
25+
import androidx.compose.foundation.layout.union
26+
import androidx.compose.foundation.layout.windowInsetsPadding
27+
import androidx.compose.foundation.layout.WindowInsetsSides
2328
import androidx.compose.foundation.layout.width
2429
import androidx.compose.foundation.lazy.LazyListState
2530
import androidx.compose.foundation.lazy.rememberLazyListState
@@ -459,17 +464,25 @@ private fun LibraryScreenContent(
459464
}
460465

461466

462-
// Apply top padding differently for list vs game detail pages.
463-
// On the game page we want to hide the top padding when the status bar is hidden.
464-
val safePaddingModifier = if (selectedLibraryItem != null) {
465-
// Detail (game) page: use actual status bar height when status bar is visible,
466-
// or 0.dp when status bar is hidden
467-
val topPadding = if (PrefManager.hideStatusBarWhenNotInGame) {
468-
0.dp
469-
} else {
470-
WindowInsets.statusBars.asPaddingValues().calculateTopPadding()
471-
}
472-
Modifier.padding(top = topPadding)
467+
// Padding for the library *list* view (tab bar, grid, search bar) so content
468+
// never draws behind the display cutout. The window now opts in to
469+
// LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES via Theme.Pluvia, so:
470+
// * Status bar visible (portrait): statusBars insets already cover the top notch.
471+
// * Status bar hidden (portrait): statusBars insets are 0; displayCutout supplies
472+
// the notch height so content isn't behind the notch.
473+
// * Landscape (cutout on a side): statusBars is top-only; displayCutout supplies
474+
// the side inset so the tab bar isn't clipped.
475+
// Bottom is intentionally excluded so scroll content can reach the bottom edge.
476+
//
477+
// The detail (game) page deliberately does NOT use this — the hero image is meant
478+
// to bleed through the cutout, so AppScreenContent insets only the elements that
479+
// need to stay tappable (e.g. the back button) instead.
480+
val safePaddingModifier = if (selectedLibraryItem == null) {
481+
Modifier.windowInsetsPadding(
482+
WindowInsets.statusBars
483+
.union(WindowInsets.displayCutout)
484+
.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
485+
)
473486
} else {
474487
Modifier
475488
}

app/src/main/res/values/themes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<item name="android:navigationBarColor">@android:color/transparent</item>
66
<item name="android:windowLightStatusBar">false</item>
77
<item name="android:windowLightNavigationBar">false</item>
8+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
89
</style>
910
</resources>

0 commit comments

Comments
 (0)