Has anyone run into an issue where their TextField...
# compose
c
Has anyone run into an issue where their TextField won't get focus from a DisposableEffect in beta-08? I'm trying to focus the TextField on fragment start but when I check the focus it says it's not focused. I'm using a FocusRequester and made sure nothing should be interfering in it receiving focus. It pops the keyboard up but the cursor isn't there which means its not active. It works fine if requested from a button click or some event firing... but on initial composition it seems there's a bug with this
Copy code
DisposableEffect(Unit) {
    focusRequester.requestFocus()
    onDispose { }
}
t
Did you try
LaunchedEffect
?
c
Hmn... I haven't.
requestFocus()
isn't a suspend function so I don't think it would make a difference, but I'll try it anyways since I'm out of ideas 😅
Wow it worked... @tad could you explain your reasoning why you thought it would work? Is it just that requestingFocus during composition needs to be in a blocking context?
t
I figured since
LaunchedEffect
dispatches on the composable's coroutine scope, it wouldn't dispatch immediately and the layout would have time to be set up before the focus event makes it through
👍 1
c
I'm not sure if that's intended since everybody in previous versions was using DisposableEffect. Maybe a change in implementation of focus caused it. I'm going to start reading more on LaunchedEffects now, thanks! UI feels a bit laggy with it in there so I might need to clean it up / cancel when I'm done with it
Also, Thank you! 😄
t
Yep, I bet it's a bug in any case. I would file it.
👍 1
a
👍 1