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

Hasan Nagizade

01/04/2023, 12:37 PM
why
onFocusChanged
is not getting triggered every time user clicks on
InputField
? how to make
InputField
get focus every time user clicks on it?
z

Zun

01/04/2023, 1:02 PM
This should be default behavior. Could it be that your theme is bad and that focused and unfocused is the same color?
h

Hasan Nagizade

01/04/2023, 1:07 PM
@Zun it's not about the theme. I want to trigger
onFocusChanged
even if the
InputField
have it. I could do that by using
clickable
modifier but that modifier doesn't work when I have
onFocusChanged
modifier.
a

Albert Chang

01/04/2023, 4:26 PM
Generally you should use
MutableInteractionSource
to observe focused state.
Copy code
val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState
TextField(interactionSource = interactionSource)
h

Hasan Nagizade

01/04/2023, 8:03 PM
@Albert Chang works like a charm thank you very much
z

Zach Klippenstein (he/him) [MOD]

01/04/2023, 9:28 PM
or
onFocusEvent
. The
onFocusChanged
docs say this:
Copy code
Note: If you want to be notified every time the internal focus state is written to (even if it hasn't changed), use [onFocusEvent] instead.
335 Views