-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix window insets to avoid overlapping display cutouts and system bars #1006
Changes from 2 commits
dc5bc4a
36af51b
52a3bde
173aaea
f393440
d9f22c4
173350b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.calculateEndPadding | ||
import androidx.compose.foundation.layout.calculateStartPadding | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
|
@@ -131,6 +133,11 @@ fun EventMapScreen( | |
AnimatedTextTopAppBar( | ||
title = stringResource(EventMapRes.string.eventmap), | ||
scrollBehavior = scrollBehavior, | ||
windowInsets = WindowInsets( | ||
left = contentPadding.calculateLeftPadding(layoutDirection), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the amazing PR! I'll merge it regardless. However, could you explain why the window insets of each screen's AnimatedTextTopAppBar are different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @takahirom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your explain. How about making a function like this? And can you resolve the conflict with the main branch? windowInsets = AnimatedTextTopAppBarDefaults.windowInsets(contentPadding), object AnimatedTextTopAppBarDefaults {
@Composable
fun windowInsets(contentPadding: PaddingValues): WindowInsets {
val layoutDirection = LocalLayoutDirection.current
return WindowInsets(
left = contentPadding.calculateLeftPadding(layoutDirection),
top = contentPadding.calculateTopPadding(),
right = contentPadding.calculateRightPadding(layoutDirection),
)
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes of course! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @takahirom object HogeTopAppBarDefaults {
val windowInsets = WindowInsets.displayCutout.union(WindowInsets.systemBars).only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top,
)
} |
||
top = contentPadding.calculateTopPadding(), | ||
right = contentPadding.calculateRightPadding(layoutDirection), | ||
), | ||
) | ||
}, | ||
contentWindowInsets = WindowInsets( | ||
|
@@ -143,7 +150,11 @@ fun EventMapScreen( | |
EventMap( | ||
uiState = uiState, | ||
onEventMapItemClick = onEventMapItemClick, | ||
contentPadding = PaddingValues(bottom = padding.calculateBottomPadding()), | ||
contentPadding = PaddingValues( | ||
start = padding.calculateStartPadding(layoutDirection), | ||
end = padding.calculateEndPadding(layoutDirection), | ||
bottom = padding.calculateBottomPadding(), | ||
), | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(top = padding.calculateTopPadding()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍