https://kotlinlang.org logo
Title
j

james

02/12/2022, 12:16 AM
if I want to move keyboard focus to a
TextField
once my
ModalBottomSheet
is shown, is using the `ModalBottomSheetState`'s
confirmStateChange
the correct place to do that, or is there a better place? I understand it can work but it doesn't necessarily feel right.. is there a listener I can use which signals "the modal bottom sheet has finished appearing"?
1
c

Colton Idle

02/12/2022, 6:10 AM
Not an expert, but that definitely sounds like where I would put it.
j

james

02/12/2022, 10:55 AM
well that worked, but I've come across another issue now. if I have
windowSoftInputMode
set to
adjustResize
for on my Activity inside AndroidManifest.xml, I am seeing the following behavior: • open my modal, textfield gets focus • hit back button and then: ◦ keyboard closes ◦ at the same time as the keyboard closes, the modal animates onto screen again (even though it was already there) it just took me quite a while to figure out what was causing this, but I have confirmed the behavior doesn't occur if I remove
windowSoftInputMode=adjustResize
I've checked and it's not recomposing, and the only line of code in the whole screen which opens the modal (a call to
animatoTo()
) is not being hit when this occurs is there something I'm obviously doing wrong here or does this sound like a bug?
c

Colton Idle

02/12/2022, 4:43 PM
Modals reopening again after closing is a bug I know I've filed. I don't think it's fixed yet. Not saying that you're having the same issue, but in general seems like maybe you might have a case worth filing a bug about here too.
☝️ 1
j

jossiwolf

02/14/2022, 8:53 AM
Compose doesn't expose listeners per se but rather exposes snapshot state. Using
snapshotFlow
, you can create a Flow that emits whenever the state's value changes and then request focus. You wouldn't want to use
confirmStateChange
because this is called when
ModalBottomSheetState
decides which state (if any) to move to, so you'd be requesting focus too early. We use
snapshotFlow
in Accompanist to get updates for when the sheet is visible: https://github.com/google/accompanist/blob/main/navigation-material/src/main/java/com/google/accompanist/navigation/material/SheetContentHost.kt#L83
@Colton Idle, would you mind linking the issue?
c
j

jossiwolf

02/14/2022, 5:00 PM
Ah cool, thanks! I think the issue James mentioned is about Material's
ModalBottomSheetLayout
, the Accompanist one is on my mind🙂 (I imagine the underlying cause might be similar though)
c

Colton Idle

02/14/2022, 5:42 PM
id put my money on that too. lol