I have a couple questions about BasicTextField2: -...
# compose
t
I have a couple questions about BasicTextField2: • It looks like this is pretty rudimentary in 1.16 (no TextState.selectAll for example). Is it difficult to switch to use 1.17? I've just been using the latest stable bom. If I try to switch, is it going to unravel in a train wreck of mismatched dependencies? Will it help fix either of the other 2 issues below? • I cannot seem to get the field to select all the text when it takes focus (when the user touches it to edit). I added
Copy code
modifier.onFocusChanged { state ->
    if (state.isFocused) {
       textState.setTextAndSelectAll(textState.text.toString())
    }}
but that has no avail. Is there something I should do differently to do this? (I have the same issue with just normal BasicTextField)
z
The most powerful way to modify selection is to use the
edit
method.
Copy code
state.edit { selectAll() }
A top-level
selectAll
on TFS seems like a reasonable addition to me though. I filed a feature request since we can no longer do this until 1.8
h
Btf2 requests focus immediately after the first tap event. That request is handled sequentially so all focus listeners get an update after the
requestFocus
call, including your listener. The problem is that after the listeners finish executing, Btf2 continues processing the tap event. This includes changing the selection to a cursor where the tap happened. So if you call selectAll in a focus listener, it immediately gets overridden by Btf2. I believe this is something we can fix by requesting focus after setting the selection.
t
Hmmm... I have no idea how reliable the following is, but it appears to work:
Copy code
if (state.isFocused) {
    scope.launch {
       textState.edit { selectAll() }
    }
}
(aside, @Zach Klippenstein (he/him) [MOD]’s comments confused me. Until I realized it was I who had gotten confused. I must have seen selectAll() as I was clicking through links on TextFieldBuffer and assumed it was on TextFieldState. I top level would be nice, but having to do the edit wrapper is fine. The issue @Halil Ozercan sounds like the real issue for now.
h
anything that can defer the selection change would work in your case. I'm not sure how it would behave for initial long press though.
t
Anyway to make the hanging cursor bubbles not be there on this initial selection?
If I want to restrict my input to a positive integer (e.g. >0), am I understanding correctly that the Text2 way to do that is with the
inputTransformation
?
z
Yes