https://kotlinlang.org logo
Title
t

Tolriq

01/07/2022, 3:19 PM
Got a small issue with TextField and keyboard overlap. When I click on TextField the content is properly moved above the keyboard. But if if I use imeAction = ImeAction.Next to move to that TextField the content is not moved and stay under the keyboard. Is there some trick to fix this ?
z

Zach Klippenstein (he/him) [MOD]

01/07/2022, 5:48 PM
Is your activity's adjust resize mode
resize
or
pan
?
m

mattinger

01/07/2022, 6:15 PM
I believe there’s a bug related to this (i’ve asked this question before). One would think that when you focus on an element the resize of the screen would keep the focused element in the visible area. But this is not working on compose for some reason, and there’s a few hacks around it, provided your TextField is a direct child of the Column you are scrolling.
t

Tolriq

01/07/2022, 6:17 PM
@Zach Klippenstein (he/him) [MOD] It's the default value, when I force resize it does not move at all in all the cases.
@mattinger do you have links for the hacks ?
m

mattinger

01/07/2022, 6:21 PM
I don’t think so, but here’s what i did:
val coroutineScope = rememberCoroutineScope()
    val bringIntoViewRequester = RelocationRequester()

    BasicTextField(
        modifier = modifier
            .onFocusEvent { state ->
                if (state.hasFocus || state.isFocused) {
                    coroutineScope.launch {
                        delay(250L)
                        bringIntoViewRequester.bringIntoView()
                    }
                }
            },
But as i said, it’s not perfect, and when i things like nest the textfield inside a card, it just doesn’t work.
t

Tolriq

01/07/2022, 6:24 PM
Hum yes don't like delay based stuff 😞
So found https://issuetracker.google.com/issues/192043120 and I also have the different behavior between first and second click on textfield. Total mess 😞
c

Colton Idle

01/08/2022, 12:41 PM
I actually was having this issue way back when. and I went to try to "fix" it now, and it basically worked without me needing to do anything crazy. maybe compose 1.1.0-rc01 fixed it? See my comment here: https://issuetracker.google.com/issues/192043120
t

Tolriq

01/08/2022, 1:35 PM
Hum will try with lazycolumns using column with scrollable.
c

Colton Idle

01/08/2022, 7:06 PM
Spoke too soon. Worked on my emulator. not on my pixel 6. dang. let me know if you find a fix. i will unfortunately start tryinging some of those solutions with "delays" built in 😭