I have a `TextField` inside `ModalBottomSheet`. Wh...
# compose
a
I have a
TextField
inside
ModalBottomSheet
. What I'm seeking to do is set focus on the TextField when opening the sheet, so I used:
Copy code
LaunchedEffect(Unit) {
   focusRequester.requestFocus()
}
But as you can see, the sheet shown under the keyboard when opening the sheet for some time, is there a way to ensure the sheet shown above the keyboard always?
j
It looks like the TextField is focused in the video. What are you looking for?
a
@Jonathan I think the problem is not about having the focus, but about keyboard/modal animation running in two times: first keyboard overlaps the modal and then the modal is pushed on top of it. Which seems a bit junky yes.
👌 1
j
You can prevent the TextField from getting focused until the sheet is fully expanded. Also does the TextField have the Modifier.imePadding() modifier attached so that it "dodged" the keyboard?
a
As @Anthony Mamode said, I just want to git red of the overlapping between sheet and keyboard, preventing focus on TextField until fully expanded will delay showing the keyboard. I want to push the sheet while showing the keyboard as happens when clicks on TextField
j
I’m not sure what you want is possible due to how bottom sheet animates its content into view, not sure. I was able to achieve the following fairly easily by waiting to focus the keyboard until the sheet is expanded. It doesn’t look terrible to me.
👍 2
h
@Jonathan sorry to revive a year old thread, I attempted to wait for the modal to appear, but in mine the delay is way longer from opening to keyboard showing. Do you happen to remember what code you used? I used
Copy code
if (sheetState.isVisible) {
    focusRequester.requestFocus()
}
j
Unfortunately, I don’t remember what code I used but I’m sure it’s not dissimilar to the what you have above. Maybe trying using a
LaunchedEffect
with the
key
equal to
sheetState.currentValue
.
With that being said the delay could very based on recomposition times due to various reasons.
h
I changed my compose library version to june 2025 and the animation is faster on the older version, so it looks like something was updated between then and now. Thanks for the help.
j
Interesting UX regression. I wonder if it was intentional. Might be worth filing a Compose issue.