Skip to content

Commit

Permalink
Added cutout padding modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptnBlubber committed Sep 6, 2021
1 parent 1b42fe0 commit 0bde24d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions insets/api/current.api
Expand Up @@ -46,6 +46,7 @@ package com.google.accompanist.insets {
}

public final class PaddingKt {
method public static inline androidx.compose.ui.Modifier cutoutPadding(androidx.compose.ui.Modifier, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom);
method public static inline androidx.compose.ui.Modifier imePadding(androidx.compose.ui.Modifier);
method public static inline androidx.compose.ui.Modifier navigationBarsPadding(androidx.compose.ui.Modifier, optional boolean bottom, optional boolean start, optional boolean end);
method public static inline androidx.compose.ui.Modifier navigationBarsWithImePadding(androidx.compose.ui.Modifier);
Expand Down
30 changes: 30 additions & 0 deletions insets/src/main/java/com/google/accompanist/insets/Padding.kt
Expand Up @@ -142,6 +142,36 @@ inline fun Modifier.imePadding(): Modifier = composed {
)
}

/**
* Selectively apply additional space which matches the width/height of any display cutout present
* on the respective edges of the screen.
*
* @param start Whether to apply padding to the start edge, which matches the display cutout width
* (if present) on the start edge of the screen. Defaults to `true`.
* @param top Whether to apply padding to the top edge, which matches the display cutout height
* (if present) at the top edge of the screen. Defaults to `true`.
* @param end Whether to apply padding to the end edge, which matches the display cutout width
* (if present) on the end edge of the screen. Defaults to `true`.
* @param bottom Whether to apply padding to the bottom edge, which matches the display cutout
* height (if present) at the bottom edge of the screen. Defaults to `true`.
*/
inline fun Modifier.cutoutPadding(
start: Boolean = true,
top: Boolean = true,
end: Boolean = true,
bottom: Boolean = true,
): Modifier = composed {
padding(
rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.displayCutout,
applyStart = start,
applyTop = top,
applyEnd = end,
applyBottom = bottom
)
)
}

/**
* Apply additional space which matches the height of the [WindowInsets.ime] (on-screen keyboard)
* height and [WindowInsets.navigationBars]. This is what apps should use to handle any insets
Expand Down
Expand Up @@ -37,6 +37,8 @@ internal fun WindowInsets.assertEqualTo(insets: WindowInsetsCompat) {

// It's difficult to create an expected value for isVisible as it depends on the system ui
// of the device.

displayCutout.assertEqualTo(insets.getInsets(WindowInsetsCompat.Type.displayCutout()))
}

internal fun WindowInsets.Type.assertEqualTo(insets: androidx.core.graphics.Insets) {
Expand Down

0 comments on commit 0bde24d

Please sign in to comment.