To implement a Long Press feature on a button or a composable in general the way is to use the Tap Gestures detected in the modifier pointerinput
the code seems pretty straightforward and it works.
Box(modifier = modifier.pointerInput(Unit) {
detectTapGestures(
onPress = {
//Do something
},
onDoubleTap = {
},
onLongPress = {
onLongClick()
},
onTap = {
}
)
}
But what I need is to modify the timeout in milliseconds before a longpress event is detected (if the box is pressed for a time of tomeoutMillisec then a longPress event is fired)
The pointerInput scope has the 'val viewConfiguration' (ViewConfiguration is an Interface) that contains the val 'longPressTimeoutMillis'. But I cannot reassign those values (not the longPressTimeoutMillis, not reassign the class viewConfiguration) because they are val and not var
Box(modifier = modifier.pointerInput(Unit) {
//this gives an error
this.viewConfiguration.longPressTimeoutMillis = 200L
detectTapGestures(
onPress = {
},
onDoubleTap = {
},
onLongPress = {
onLongClick()
},
onTap = {
}
)
},
Anyone knows how to do it?