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

chansek

03/12/2022, 5:07 PM
My TextField gets hidden behind Keyboard. How do I avoid it? I am able to solve it by below snippet added to my activity.
Copy code
android:windowSoftInputMode="adjustResize"
But if my
TextField
is inside a
ModalBottomSheet
, then this doesn't work. What should be the fix for this?
s

ste

03/12/2022, 5:43 PM
Did you try the following?
Copy code
val coroutineScope = rememberCoroutineScope()
val bringIntoViewRequester = remember { BringIntoViewRequester() }

BasicTextField(
    modifier = Modifier
        .bringIntoViewRequester(bringIntoViewRequester)
        .onFocusEvent { state ->
              if (state.hasFocus || state.isFocused) {
                  coroutineScope.launch {
                      delay(300) // important!
                      bringIntoViewRequester.bringIntoView()
                  }
              }
          }
)
K 1
c

chansek

03/12/2022, 6:18 PM
It works if you click on a
TextField
and keyboard pops up. But ones keybaord is already up and you start clicking on
ImeAction.Next
button, the `TextField`s present behind the keyboard stays there and doesn't come to visible window.
s

ste

03/12/2022, 6:19 PM
Uhm I was in this exact scenario, but it worked; are you using accompanist insets by chance?
z

Zach Klippenstein (he/him) [MOD]

03/12/2022, 9:17 PM
This should be fixed in the next release, unless your text field is in a lazy list
💯 1
🦜 1
K 1
c

chansek

03/13/2022, 3:30 AM
Thanks for the update @Zach Klippenstein (he/him) [MOD] Will wait for the next release.
8 Views