How do I use `Modifier.imePadding()` with `Scaffold`? (Material3) If I use both the scaffold padding...
d
How do I use
Modifier.imePadding()
with
Scaffold
? (Material3) If I use both the scaffold padding (
PaddingValues
) and
.imePadding()
in my screen the padding on the bottom is greater than it should be. If I do not use the scaffold bottom padding and only use
.imePadding()
the padding is correct when the ime is open but it is too little when it is close. What's the proper way to use these APIs? (btw why is
WindowsInsets
not named
LocalWindowsInsets
like other "Locals"?)
v
Maybe

thisβ–Ύ

will help you.
d
Hum, not really but it mentioned some API I didn't know and the doc page I didn't find so I'll look into those. Maybe the exclude API is what I'm looking for? I've a feeling the added padding isn't coming from the insets but from the NavigationBar height in my scaffold. And if that's the case and I cannot exclude it than I still don't know how to solve the issue.
No this didn't help. Because the added padding isn't coming from insets, it's the size taken by the bottom app bar that is added to the imePadding. I've found https://issuetracker.google.com/issues/243713323 Which point to https://github.com/android/nowinandroid/pull/242/files as an example... They basically made the Scaffold ignore insets and handled them in the screens... Is this the only way? Can someone confirm or refute that this is the intended way to use ime insets with the Scaffold?
As a result you end up with more space below your content than intended... how much more space? exactly the Bottom bar height
a
Hello! Have you tried using
Modifier.consumedWindowInsets(innerPadding)
, where that
innerPadding
is the one passed to the body of the
Scaffold
? If you’re applying the padding directly, it might look something like
Copy code
Modifier.padding(innerPadding).consumedWindowInsets(innerPadding)
Also, good investigation skills for that bug and the Now in Android PR πŸ˜„ Disabling the
Scaffold
’s handling by passing
WindowInsets(0, 0, 0, 0)
is another option as well. In Now in Android, I used that since we are switch between the navigation bar and navigation rail, and wanted more control over insets inside the
Scaffold
itself.
d
Thank you
consumedWindowInsets
works perfectly!!! This is the answer I was looking for! Thank you a lot for your answer! I wish I could take credit for the PR and the investigation but I'm not the person that did that eheh πŸ˜„
Unless you mean "finding the issue and the PR", in that case, I can take credit! I Did find them πŸ˜›
a
Yup, I meant finding the issue and the PR. Glad you were able to find a solution!
d
Where would have I find that information in the official doc? I couldn't find it anywhere
Btw small suggestion for API
WindowInsets(0, 0, 0, 0)
-->
WindowInsets.None
would be handy πŸ™‚
c
just wanted to say that the insets video is insanely helpful!
r
Hello from the future, @Daniele Segato thanks for asking the question and @Alex Vanyo thanks for answering this saved me some good investigation time πŸ˜„
πŸŽ‰ 2
2063 Views