Gestures: Click, Drag, Swipe and Transform

Android Development 9 min min read Updated: Nov 16, 2026 Intermediate
Gestures: Click, Drag, Swipe and Transform
Intermediate Topic 2 of 6

clickable and combinedClickable

kotlin Box( Modifier .size(120.dp) .background(Color.Blue) .combinedClickable( onClick = { println("Tap") }, onDoubleClick = { println("Double tap") }, onLongClick = { println("Long press") } ) )
Accessibility: Use Button or Modifier.clickable with role and onClickLabel for real actions, so TalkBack users can use them too.

Drag

kotlin @Composable fun DraggableCircle() { var offset by remember { mutableStateOf(Offset.Zero) } Box( Modifier .offset { IntOffset(offset.x.roundToInt(), offset.y.roundToInt()) } .size(80.dp) .background(Color(0xFF42A5F5), CircleShape) .pointerInput(Unit) { detectDragGestures { change, dragAmount -> change.consume() offset += dragAmount } } ) }

Tap Details with pointerInput

kotlin Modifier.pointerInput(Unit) { detectTapGestures( onTap = { position -> println("Tapped at $position") }, onLongPress = { println("Long press") }, onDoubleTap = { println("Double tap") } ) }

Zoom and Rotate

kotlin @Composable fun ZoomableImage() { var scale by remember { mutableFloatStateOf(1f) } var rotation by remember { mutableFloatStateOf(0f) } var offset by remember { mutableStateOf(Offset.Zero) } val state = rememberTransformableState { zoomChange, offsetChange, rotationChange -> scale = (scale * zoomChange).coerceIn(0.5f, 5f) rotation += rotationChange offset += offsetChange } Image( painter = painterResource(R.drawable.photo), contentDescription = "Photo", modifier = Modifier .graphicsLayer(scaleX = scale, scaleY = scale, rotationZ = rotation, translationX = offset.x, translationY = offset.y) .transformable(state) .fillMaxSize() ) }

Swipe a Card Away

kotlin @Composable fun SwipeCard(onDismiss: () -> Unit) { val offsetX = remember { Animatable(0f) } val scope = rememberCoroutineScope() Card( Modifier .offset { IntOffset(offsetX.value.roundToInt(), 0) } .size(260.dp, 340.dp) .pointerInput(Unit) { detectHorizontalDragGestures( onDragEnd = { scope.launch { if (abs(offsetX.value) > 300f) onDismiss() else offsetX.animateTo(0f) } } ) { _, dragAmount -> scope.launch { offsetX.snapTo(offsetX.value + dragAmount) } } } ) { /* content */ } }
Tip: For standard swipe-to-dismiss on list rows use SwipeToDismissBox. Use pointerInput for custom gestures.

Conclusion

Compose offers simple modifiers for common gestures and pointerInput for custom ones. Combine them with state and Animatable.

Quick Summary: clickable and combinedClickable for taps, detectDragGestures for dragging, transformable for zoom and rotate.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators