https://kotlinlang.org logo
a

Ahmed Elhanafy

06/19/2020, 2:24 PM
Folks is there a way to disable these selection controls when long pressing on
Text
composable?
a

Adam Powell

06/19/2020, 3:09 PM
not yet I think, @Siyamed to confirm
s

Siyamed

06/19/2020, 3:10 PM
No there is not
For this example may i ask if there is a reason to disable selection?
a

Ahmed Elhanafy

06/19/2020, 6:24 PM
@Siyamed because i want to implement my own custom highlighting behavior
s

Siyamed

06/19/2020, 6:29 PM
got it thanks.
a

Ahmed Elhanafy

06/19/2020, 8:18 PM
@Siyamed Is there any way to disable this? It's blocking a POC that I'm trying to make, maybe, disable it system wide or app wide?
s

Siyamed

06/19/2020, 8:34 PM
There is not :/
If you add a gesture modified in text though you should be able to hijacck the touch
Since it is defined on the global level
From custom highlighting what i understand is a utility such as a pdf reader where you highlight a portion of the text using touch, am i right?
Or is it something else?
@Ahmed Elhanafy
a

Ahmed Elhanafy

06/19/2020, 8:47 PM
That's exactly right. I'm implementing a labeling experience for text. Trying to replicate what we have on https://luis.ai. Could you please explain maybe with a code snippet how to implement the workaround you suggested? @Siyamed
s

Siyamed

06/19/2020, 8:48 PM
Is it possible for you to share the current code that does highlighting on the text?
Overriding the touch on text actually is not a workaround in your case
Once i see the code i can check better but Text dors not have any gesture modifier therefore a modifier that you add to Text to handle you highlighting will already override the one that is used at the very top of the tree by a composable named SelectionContainer
Sincei i am writing on the phone the code will not be accurate but
Text(modifier = Modifier.tapGestureModifier { your highlighting logic }) should not select
Please let me know if it still selects after you add the modifier
Howeever you handle touches, it should already be the case, therefore i will appreciate if you can share a code snippet
a

Ahmed Elhanafy

06/19/2020, 9:05 PM
Adding
tapGestureFilter
didn't work however adding
longPressDragGestureFilter
worked and disabled the selection effect. Thanks a lot @Siyamed I'm trying Compose as part of an internal hackathon we have, and I'm blown away by its flexibility and simple APIs, coming from React I feel like I already know a lot about the system. Keep doing awesome work! ☺️
Copy code
Modifier
                                .padding(0.dp, 40.dp, 8.dp, 40.dp)
                                .longPressDragGestureFilter(object :
                                    LongPressDragObserver {
                                    override fun onDragStart() {
                                        super.onDragStart()
                                        Log.d(ContentValues.TAG, "onDragStart: Do stuff")
                                    }
                                })
❤️ 1
s

Siyamed

06/19/2020, 9:06 PM
Correct (i took a shortcut while writing tapGestureFilter). Selection starts with long press
Thank you!
Happy that it solved your use case!
g

goku

06/21/2020, 2:43 PM
@Siyamed Is there a plan to disable the selection in the future?
Text
is used in other composables such as AppBar, Button and text on them are selectable by default.