长按,也能用detectDragGesturesAfterLongPress
@Composable
fun ClickableSample(){
val count = remember { mutableStateOf(0) }
var isLong : Boolean = false
//var isLong by remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()
Text(
text = count.value.toString(),
textAlign = TextAlign.Center,
modifier = Modifier
.pointerInput(Unit) {
detectDragGesturesAfterLongPress(
onDrag = {change, dragAmount ->
},
onDragStart = {
Log.d("senl", "onDragStart")
isLong = true
count.value += 1
coroutineScope.launch {
while (isLong) {
delay(100)
count.value++
}
}
},
onDragEnd = {
isLong = false
Log.d("senl", "onDragEnd")
},
onDragCancel = {
isLong = false
Log.d("senl", "onDragEnd")
}
)
}
.wrapContentSize()
.background(Color.Cyan)
.padding(horizontal = 50.dp, vertical = 40.dp)
)
}
长按,也能用detectDragGesturesAfterLongPress