does `TextField` expose anything related to focus?...
# compose
a
does
TextField
expose anything related to focus? In other words, how can one be notified of something like
isFocused
?
f
TextFieldValue
holds the focus state
a
Thanks
f
Actually, it only has
selection
, so i'm not sure if it's possible to check with it if its focused in all cases
a
yeah
I’m not sure if this gives out the selection or not
f
Copy code
val isFocused = interactionSource.collectIsFocusedAsState().value
a
I tried going with interaction source
and casting it as Focus
but doesn’t help
f
why would you cast it as focus? do like I showed above, that's how the implementation does it
a
how do you know if it’s focused or not?
interaction source is not a boolean, it’s an interface
which has multiple implementations
f
InteractionSource
is a flow-like object
you can convert it to state like i showed above
a
I know. the state’s value is not a boolean is what I’m saying
f
it is a boolean
a
Oh
I didn’t see your
isFocused
there is another function which converts the whole thing as a state
and gives the actual interaction source as the value
thanks again
m
Copy code
Modifier.onFocusChanged {
                if (!it.isFocused) {
                    if (hasFocus.value) {
                        hasFocus.value = false
                        onFocusChanged()
                    }
                } else {
                    hasFocus.value = it.isFocused
                }
Copy code
val hasFocus = remember { mutableStateOf(false) }
d
I have just updated to rc01 and looks like there is a change in
FocusState.Active
. Is there something new in its place ?