Eric Ampire [MOD]

    Eric Ampire [MOD]

    1 year ago
    Hi, since
    Card
    and Surface have the
    onClick
    parameter how can I define an
    onLongClick
    assuming that the code below does not work
    Modifier.combinedClickable(
        onLongClick = {
          Timber.e("Long Click")
        }
    )
    Modifier.genericClickableWithoutGesture
    that support
    onLongClick
    is marked as internal
    Ravi

    Ravi

    1 year ago
    Modifier.pointerInput(Unit) {
            detectTapGestures(
                onLongPress = {
                    onLongClick()
                },
                onPress = {
                    onClick()                
                }
            )
        }
    can u try this?
    Eric Ampire [MOD]

    Eric Ampire [MOD]

    1 year ago
    I have tried this solution but it doesn't work
    Tash

    Tash

    1 year ago
    Are you trying to detect long press on a
    Card
    ?
    something like this should work
    @Composable
    fun Test() {
        var pressType by remember { mutableStateOf("none") }
        Card(
            modifier = Modifier
                .fillMaxSize(0.6f)
                .pointerInput(Unit) {
                    detectTapGestures(
                        onLongPress = {
                            pressType = "onLongPress"
                        },
                        onPress = {
                            pressType = "onPress"
                        }
                    )
                },
            backgroundColor = Color.LightGray
        ) {
            Box(modifier = Modifier.fillMaxSize(0.5f)) {
                Text("Press type = $pressType")
            }
        }
    }
    Eric Ampire [MOD]

    Eric Ampire [MOD]

    1 year ago
    It doesn't work too
    Tash

    Tash

    1 year ago
    that snippet works for me. are you able to share more about what you’re trying to do?
    p

    Pavlo Rybitskyi

    1 year ago
    Have u figured out how to do it? I'm facing similar issue.
    Eric Ampire [MOD]

    Eric Ampire [MOD]

    1 year ago
    Yes I have used the pointerInput as mentioned by @Tash, and it's work