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

louiscad

10/27/2020, 10:16 PM
It seems that since 1.0.0-alpha05,
Text
is no longer selectable by default. How can we make it selectable again?
s

Siyamed

10/27/2020, 10:17 PM
Add a SelectionContainer around the tree that you want to be selectable
l

louiscad

10/27/2020, 10:28 PM
I wrapped with
SelectionContainer(selection = null, onSelectionChange = {}) { … }
but while I can select the text, I can't do anything with it, there's no popup/toolbar appearing above… why is it not there by default and is there a way to get that popup/toolbar?
s

Siyamed

10/27/2020, 10:29 PM
The answer to why it is not enabled by default would be complicated for me. I am on the same school of thought that it should be enabled by default.
I will add a simpler api but for now you should not set selection to null
It should be like TextField etc where you get rhe selection on the callback and set the value that was passed
As long as you can add SelectionContainer to any component tree that has text, they will be selectable. (If there is not a specific bug)
l

louiscad

10/27/2020, 10:33 PM
It's unclear which value I should pass to
selection
though since I just want text from the composition to be selectable, regardless of what it is.
s

Siyamed

10/27/2020, 10:34 PM
The value you get from onSelectionChange goes into selection attribute?
z

Zach Klippenstein (he/him) [MOD]

10/27/2020, 10:36 PM
Copy code
var selection: Selection? by remember { mutableStateOf(null) }
SelectionContainer(selection = selection, onSelectionChange = { selection = it }) { … }
IIRC
l

louiscad

10/27/2020, 10:40 PM
Why don't we simply have a
EnableTextSelectionByDefault { … }
or alike wrapper if
Text
is no longer selectable by default? Having to declare a variable and configuring the thing isn't very intuitive to me
:)
🙂 2
l

louiscad

10/27/2020, 10:42 PM
Your snippet works, Zach (granted I import the getValue + setValue from compose runtime), but I see only the "Copy" option in the popup, no translate and all options… it's not invoking the text selection from the system?
Thank you Siyamed! Feel free to ping me if you're undecided about the naming 🙂
👍 1
s

Siyamed

10/27/2020, 10:44 PM
It doesn't use system
It is not integrated to smart selection
If there is nothing to paste wont show paste
l

louiscad

10/27/2020, 10:45 PM
Is there a way to integrate it to system selection to get smart selection, translate and other niceties we got since Android 6?
2
Maybe something in the
onSelection
callback for the non smart selection related things?
BTW, I see that selection can cross components, like it's possible on webpages. That's very nice!
s

Siyamed

10/27/2020, 10:48 PM
We will integrate, right now i am not aware of such away
👍 2
2 Views