a

    Ahmed Elhanafy

    2 years ago
    Folks is there a way to disable these selection controls when long pressing on
    Text
    composable?
    Adam Powell

    Adam Powell

    2 years ago
    not yet I think, @Siyamed to confirm
    Siyamed

    Siyamed

    2 years ago
    No there is not
    For this example may i ask if there is a reason to disable selection?
    a

    Ahmed Elhanafy

    2 years ago
    @Siyamed because i want to implement my own custom highlighting behavior
    Siyamed

    Siyamed

    2 years ago
    got it thanks.
    a

    Ahmed Elhanafy

    2 years ago
    @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?
    Siyamed

    Siyamed

    2 years ago
    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

    2 years ago
    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
    Siyamed

    Siyamed

    2 years ago
    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

    2 years ago
    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! ☺️
    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")
                                        }
                                    })
    Siyamed

    Siyamed

    2 years ago
    Correct (i took a shortcut while writing tapGestureFilter). Selection starts with long press
    Thank you!
    Happy that it solved your use case!
    goku

    goku

    2 years ago
    @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.