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

Lee Chun Hoe

03/19/2023, 8:17 AM
Hi, how to set click event as not consumed so that long pressing on it will repeat click action until release? As there is no boolean return for onLongPress in detectTapGestures.
Copy code
Modifier.pointerInput(Unit) {
                detectTapGestures(
                    onPress = { onClick() },
                    onLongPress = { onClick() }
                )
            }
So I implemented this. Please let me know if there are better way.
Copy code
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()

LaunchedEffect(isPressed) {
    while (isPressed) {
        delay(100)
        onClick()
    }
}

Button(modifier = Modifier.clickable(interactionSource = interactionSource))
z

Zaki Shaikh

03/20/2023, 6:26 AM
Copy code
Modifier.pointerInteropFilter { event ->
                when(event.action) {
        MotionEvent.ACTION_DOWN -> {
            //initial state when user clicked
        }

        MotionEvent.ACTION_MOVE -> {
            //user is keeping press component
        }

        MotionEvent.ACTION_UP -> {
            //when user left press
        }
    }
                true
            }
10 Views