why `onFocusChanged` is not getting triggered ever...
# compose
h
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
This should be default behavior. Could it be that your theme is bad and that focused and unfocused is the same color?
h
@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
Generally you should use
MutableInteractionSource
to observe focused state.
Copy code
val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState
TextField(interactionSource = interactionSource)
h
@Albert Chang works like a charm thank you very much
z
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.
646 Views