You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Window insets are behaving differently across android versions. Use case- We want to show app content in full screen, so we hide the navigation bar and status bar using the following snippet.
After this, to reposition some of the UI elements below the status bar, we are using Modifier.statusBarsPadding().
This is working fine in Android SDK version 28 (Android 9).
But this is not working in Android SDK version 30 (Android 11).
If we log the LocalWindowInsets.current.statusBars.top, then it starts from its original value, and linearly decreases to 0. This can be seen in the screen-shots below.
As you can see in the above image, the emulator having Android SDK version 28 is working fine, but the emulator on the right having Android SDK version 30 is displaying both the texts at the same place. Modifier.statusBarsPadding() is not working in Android SDK version 30.
Code snippet for the Texts:
Text(modifier = Modifier, text = "Hello 1 $name!")
Text(modifier = Modifier.statusBarsPadding(), text = "Hello 2 $name!")
To solve this, we are storing the max value of LocalWindowInsets.current.statusBars.top, and keeping its max value in a local variable. See the following snippet,
val topBarPadding: Dp
@Composable
get() {
var _topBarPadding by remember {
mutableStateOf(0)
}
_topBarPadding = max(_topBarPadding, LocalWindowInsets.current.statusBars.top)
return with(LocalDensity.current) { _topBarPadding.toDp() }
}
This fixes the issue, now we can see the UI elements which have been given the padding of topBarPadding below the status bar.
Modifier.padding(top = topBarPadding)
Now both the emulators are having the same behaviour. Code snippet for both the emulators:
Text(modifier = Modifier, text = "Hello 1 $name!")
Text(modifier = Modifier.padding(top = topBarPadding), text = "Hello 2 $name!")
Please check this issue, keeping this hack in production is not an option.
I was looking at something similar recently. Because you are animating out the status bar, I believe this is working as intended. I think you will need Modifier.cutoutPadding() which was only recently added in #696
Bug description
Window insets are behaving differently across android versions.
Use case- We want to show app content in full screen, so we hide the navigation bar and status bar using the following snippet.
After this, to reposition some of the UI elements below the status bar, we are using
Modifier.statusBarsPadding()
.This is working fine in Android SDK version 28 (Android 9).
But this is not working in Android SDK version 30 (Android 11).
If we log the
LocalWindowInsets.current.statusBars.top
, then it starts from its original value, and linearly decreases to 0. This can be seen in the screen-shots below.As you can see in the above image, the emulator having Android SDK version 28 is working fine, but the emulator on the right having Android SDK version 30 is displaying both the texts at the same place.
Modifier.statusBarsPadding()
is not working in Android SDK version 30.Code snippet for the
Text
s:To solve this, we are storing the max value of
LocalWindowInsets.current.statusBars.top
, and keeping its max value in a local variable. See the following snippet,This fixes the issue, now we can see the UI elements which have been given the padding of
topBarPadding
below the status bar.Now both the emulators are having the same behaviour. Code snippet for both the emulators:
Please check this issue, keeping this hack in production is not an option.
Please find the activity code attached here.
Thanks.
Expected behaviour
On all Android versions, we should be able to set the status bar padding using
Modifier.statusBarsPadding()
The text was updated successfully, but these errors were encountered: