Today, I set out to better understand IME padding....
# compose-android
t
Today, I set out to better understand IME padding. In particular, in the context of keeping scrolled content visible when the keyboard opens. I have read again through https://developer.android.com/develop/ui/compose/layouts/insets . I built a simplish example to play/experiment with, shown in the first screenshot. Its composable heirarchy looks like: LazyColumn ElevatedCard(s) Column Text, Spacer, BasicTextField, Spacer, BasicTextFieldSpacer The goal is that when I click on either text field in the card, and the keyboard appears, the entire card scrolls if necessary to stay visible. But when I click on either, I see the second screenshot. The content will slide up to make sure the BasicTextField is visible, but none of the rest of the card. I have thrown imePadding, imeNestedScrolling, and consumeWindowInsets(WindowInsets.ime) at multiple combinations of places in the hierarchy, but none seem to have any effect at all (I wonder if any effects are being hidden by the keyboard itself?) I'm curious if any form of padding is going to solve this problem? Dynamically adjusting the vertical height of something in a scrolled list will just change it's height, but not it's scrolled offset. Am I going to have employ a solution that gets into the guts more? Obviously, there's something that causes the text field itself to pull upwards to stay visible, just not sure where that is happening. I can put code in thread if needed.
l
Which
windowSoftInputMode
are you utilizing?
t
Copy code
android:windowSoftInputMode="adjustResize"
(in my manifest)
l
I am sure there is a way to manually handle the insets with raw ime insets. You can use:
Copy code
WindowInsets.ime.asPaddingValues().calculateBottomPadding()
to get the ime bottom padding, and then manually pad your content. I have never actually done what you are specifically attempting to do, but there must be a way. 🤔 You could try to programmatically scroll the lazy list and use the known ime padding and the height of the card to do some magic. Two things need to happen: 1. You need to manually size the view based on the ime. Or you need to leave it at its full size and apply padding/spacers within your lazy list such that if a user scrolls the list with the ime open, they will be able to see all content. 2. You need to manually scroll the lazy list to be as visible as you want it to be.
If I were you, I would start by attempting to get the screen to remain static when the ime opened. Then you would know that you aren’t fighting anything else. After that, I would start building out the implementation I described above.
t
I think that what I may want is BringIntoViewRequestor (https://developer.android.com/reference/kotlin/androidx/compose/foundation/relocation/BringIntoViewResponder). But I'm not having much luck getting that to work still
l
Never heard of that 👁️
Let me know how it goes!
358 Views