https://kotlinlang.org logo
#compose
Title
# compose
r

rophuine

06/19/2020, 1:47 PM
One of the most painful UX issues to get right (for me at least, maybe it's just because I'm bad at building mobile apps!) is making sure my layout reacts to whether the keyboard is visible or not. In React Native we have the KeyboardAvoidingView (which works, kind of, if you poke it just right). Is there anything similar for Compose yet? If not, has anyone found a good solution for building a layout which resizes based on whether the keyboard is visible or not? My use-case is basically a chat-style interface: I'm trying to build a chat history (inside a
VerticalScroller
) which takes up most of the screen, with a
Column
wrapping the
VerticalScroller
and a
TextField
element below it, but have the whole thing take up the entire view port that isn't covered by the keyboard (e.g. if the keyboard is hidden, it'll take up the whole height - if the keyboard is shown, it'll reduce in height to take up all the available height except what the keyboard is covering).
g

grandstaish

06/19/2020, 2:10 PM
Not compose-specific, but could you just have the activity resize when the soft input is shown using
android:windowSoftInputMode="adjustResize"
? See https://developer.android.com/training/keyboard-input/visibility#Respond
a

Adam Powell

06/19/2020, 2:18 PM
@cb and I have been playing with some inset API shapes that end up looking something like
Modifier.insetsPadding(bottom = true)
and similar, which you can apply to whatever content you'd like. It works really well in my experience with it so far.
Which you could apply to a container that you want to resize, a
Spacer
if that makes more sense in your layout, or whatever else.
c

cb

06/19/2020, 2:22 PM
z

Zach Klippenstein (he/him) [MOD]

06/19/2020, 3:26 PM
It would be cool to have a
VerticalScroller
-like composable that works with the new IME controller APIs in android 11. I think it would be pretty straightforward to build
r

rophuine

06/20/2020, 5:38 AM
Thanks for the suggestions - I've gone with the adjustResize suggestion. It's not quite perfect but I'll tinker further once I get to the polishing stage 🙂
5 Views