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 29, 2021
1 parent 2df87ff commit 6073f6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions insets/api/current.api
Expand Up @@ -52,6 +52,7 @@ package com.google.accompanist.insets {
method @androidx.compose.runtime.Composable public static androidx.compose.foundation.layout.PaddingValues rememberInsetsPaddingValues(com.google.accompanist.insets.Insets insets, optional boolean applyStart, optional boolean applyTop, optional boolean applyEnd, optional boolean applyBottom, optional float additionalStart, optional float additionalTop, optional float additionalEnd, optional float additionalBottom);
method public static inline androidx.compose.ui.Modifier statusBarsPadding(androidx.compose.ui.Modifier);
method public static inline androidx.compose.ui.Modifier systemBarsPadding(androidx.compose.ui.Modifier, optional boolean enabled);
method public static inline androidx.compose.ui.Modifier systemBarsPadding(androidx.compose.ui.Modifier, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom);
method @Deprecated @androidx.compose.runtime.Composable public static inline androidx.compose.foundation.layout.PaddingValues toPaddingValues(com.google.accompanist.insets.WindowInsets.Type, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom, optional float additionalHorizontal, optional float additionalVertical);
method @Deprecated @androidx.compose.runtime.Composable public static inline androidx.compose.foundation.layout.PaddingValues toPaddingValues(com.google.accompanist.insets.WindowInsets.Type, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom, optional float additionalStart, optional float additionalTop, optional float additionalEnd, optional float additionalBottom);
}
Expand Down
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 6073f6a

Please sign in to comment.