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

Vivek Sharma

02/24/2021, 8:50 PM
Previously  there was 
pressIndicatorGesture
 , I am using this to immitate that :
Copy code
Modifier.pointerInput(Unit) {
    detectTapGestures(
        onLongPress = { doingSomething }
    )
}
how can I listen when you have left/cancel the long press?
a

Alexandre Elias [G]

02/24/2021, 11:23 PM
You could add an
onPress
handler invoking
awaitRelease
, or more simply, just writing the code after
detectTapGestures
returns may work for you.
With either approach, you will probably need to add an extra variable like 
var didLongPress = false
 and set it in your long-press handler in order to distinguish long presses from other types of presses
v

Vivek Sharma

02/25/2021, 10:26 AM
Thank you @Alexandre Elias [G], I used for my usecase like this:
Copy code
Modifier.pointerInput(Unit) {
        detectTapGestures(
            onLongPress = {
                doingSomething(true)
            },
            onPress = {
                doingSomething(true)
                if (this.tryAwaitRelease()) {
                    doingSomething(false)
                }
            }
        )
    }
I used
tryAwaitRelease()
as it returned me a boolean value to check when gesture is cancelled
🙏 1
2 Views