Skip to content

Commit

Permalink
Add an overload selectively applying system bar insets on all sides
Browse files Browse the repository at this point in the history
This is useful for things like landscape where you might want system bars on all sides except on
the bottom or top, for example on a top bar.
  • Loading branch information
ansman committed Aug 27, 2021
1 parent dd384f0 commit 7bc34ac
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions insets/src/main/java/com/google/accompanist/insets/Padding.kt
Expand Up @@ -53,6 +53,36 @@ inline fun Modifier.systemBarsPadding(enabled: Boolean = true): Modifier = compo
)
}

/**
* Selectively apply additional space which matches the width/height of any system bars present
* on the respective edges of the screen.
*
* @param start Whether to apply padding to the start edge, which matches the system bars 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 system bars 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 system bars 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 system bars
* height (if present) at the bottom edge of the screen. Defaults to `true`.
*/
inline fun Modifier.systemBarsPadding(
start: Boolean = true,
top: Boolean = true,
end: Boolean = true,
bottom: Boolean = true,
): Modifier = composed {
padding(
rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.systemBars,
applyStart = start,
applyTop = top,
applyEnd = end,
applyBottom = bottom
)
)
}

/**
* Apply additional space which matches the height of the status bars height along the top edge
* of the content.
Expand Down

0 comments on commit 7bc34ac

Please sign in to comment.