Mark
04/27/2023, 12:45 PMModifier.navigationBarsPadding()
but only apply the bottom padding (i.e. it would do nothing if no nav bar at the bottom)? i.e. I want to force the 3 other paddings to zero.curioustechizen
04/27/2023, 12:49 PMnavigationBarsPadding()
already does?Colton Idle
04/27/2023, 12:58 PMMark
04/27/2023, 1:30 PMnavigationBarsPadding
applies the padding according to where the nav bar is, e.g. on the right/left on a phone in landscape mode.curioustechizen
04/27/2023, 1:33 PMColton Idle
04/27/2023, 1:34 PMColton Idle
04/27/2023, 1:35 PMMark
04/27/2023, 1:35 PMMark
04/27/2023, 1:36 PMcurioustechizen
04/27/2023, 1:45 PMnavigationBarsPadding()
only if LocalConfiguration.current
tells you that you are in portrait mode. But I'm curious if there is a better, more idiomatic way.Mark
04/27/2023, 1:46 PMMark
04/27/2023, 1:47 PMval insets = activity.getWindowManager().getCurrentWindowMetrics().getWindowInsets()
val navigationBarHeight = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom //in pixels
Oleksandr Balan
04/27/2023, 1:48 PMval density = LocalDensity.current
val bottomPx = WindowInsets.navigationBars.getBottom(density)
val bottom = LocalDensity.current.run { bottomPx.toDp() }
val padding = Modifier.padding(bottom = bottom)
Edit: read the real answer further in thread 👇
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1682608271225589?thread_ts=1682599551.610209&cid=CJLTWPH7SMark
04/27/2023, 1:54 PMfun Modifier.navigationBarsPaddingBottom(): Modifier = composed {
val density = LocalDensity.current
val bottomPx = WindowInsets.navigationBars.getBottom(density)
val bottom = density.run { bottomPx.toDp() }
this.padding(bottom = bottom)
}
Oleksandr Balan
04/27/2023, 1:59 PMAlbert Chang
04/27/2023, 3:11 PMModifier.windowInsetsPadding(WindowInsets.navigationBars.only(WindowInsetsSides.Bottom))
Stylianos Gakis
04/27/2023, 3:12 PMMark
04/27/2023, 3:37 PMcompose { }
)?
fun Modifier.navigationBarsPaddingBottom(): Modifier = composed {
this.windowInsetsPadding(WindowInsets.navigationBars.only(WindowInsetsSides.Bottom))
}
Alex Vanyo
04/27/2023, 4:41 PMStylianos Gakis
04/27/2023, 4:51 PMAlex Vanyo
04/28/2023, 12:55 AM