#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

How to Add Gesture Controls to Mobile Applications

Every major mobile toolkit has built-in gesture detection, so adding gestures means picking the right API, connecting it to an action, and giving users a visible alternative. This guide shows working code for tap, double-tap, long-press, swipe-to-delete and pinch-to-zoom in Jetpack Compose (Android), SwiftUI (iOS), Flutter and React Native, followed by the design and accessibility rules that stop gestures from becoming hidden traps.

How to Add Gesture Controls to Mobile Applications

A student builds a notes app for a final-year project. In the demo, the examiner tries to delete a note, cannot find a delete button, and gives up. The developer had added swipe-to-delete, but nothing on screen told anyone it existed. That is the most common gesture problem: the code is easy, the design is the hard part. We will cover both.

The gestures users already know

GestureTypical meaningGive users an alternative?
TapSelect, openIt is the alternative
Double-tapLike, zoom to fitYes, a like or zoom button
Long-pressContext menu, start dragYes, a "more" (⋮) menu
Swipe on a list rowDelete, archive, replyYes, an action in the row menu
DragReorder, moveYes, move up/down actions
Pinch / spreadZoomYes, zoom buttons or double-tap

Stick to these meanings. Inventing a new gesture (a three-finger swipe to share, a shake to undo as the only option) means users must be taught it, and most will never find it.

Android with Jetpack Compose

Compose handles gestures through modifiers. Simple taps use clickable; anything richer goes through pointerInput with a detector function.

Tap, double-tap and long-press

var liked by remember { mutableStateOf(false) }
var showMenu by remember { mutableStateOf(false) }

Box(
    Modifier
        .size(200.dp)
        .pointerInput(Unit) {
            detectTapGestures(
                onTap = { /* open the post */ },
                onDoubleTap = { liked = !liked },
                onLongPress = { showMenu = true }
            )
        }
)

When you supply onDoubleTap, Compose waits briefly after the first tap to see if a second one follows, so single taps feel slightly slower. Only add double-tap where it earns that delay.

Swipe a card away

@Composable
fun SwipeCard(onSwipedLeft: () -> Unit) {
    var offsetX by remember { mutableFloatStateOf(0f) }
    Box(
        Modifier
            .offset { IntOffset(offsetX.roundToInt(), 0) }
            .pointerInput(Unit) {
                detectHorizontalDragGestures(
                    onDragEnd = {
                        if (offsetX < -300f) onSwipedLeft()
                        offsetX = 0f
                    }
                ) { change, dragAmount ->
                    change.consume()
                    offsetX += dragAmount
                }
            }
            .fillMaxWidth()
            .height(96.dp)
            .background(Color.LightGray)
    )
}

The card follows the finger, and if it has moved more than 300 pixels to the left when the finger lifts, the callback fires. For list rows, Material 3 also ships a ready-made SwipeToDismissBox composable, which handles the animation and thresholds for you.

Pinch to zoom

var scale by remember { mutableFloatStateOf(1f) }
val state = rememberTransformableState { zoomChange, _, _ ->
    scale = (scale * zoomChange).coerceIn(1f, 5f)
}

Image(
    painter = painterResource(R.drawable.photo),
    contentDescription = "Product photo",
    modifier = Modifier
        .graphicsLayer(scaleX = scale, scaleY = scale)
        .transformable(state = state)
)

coerceIn(1f, 5f) stops users from shrinking the image to nothing or zooming into a blur. In the older View system the equivalents are GestureDetector and ScaleGestureDetector.

iOS with SwiftUI

struct PhotoView: View {
    @State private var scale: CGFloat = 1.0
    @GestureState private var pinch: CGFloat = 1.0
    @State private var liked = false

    var body: some View {
        Image("photo")
            .resizable()
            .scaledToFit()
            .scaleEffect(scale * pinch)
            .gesture(
                MagnifyGesture()
                    .updating($pinch) { value, state, _ in
                        state = value.magnification
                    }
                    .onEnded { value in
                        scale = min(max(scale * value.magnification, 1), 5)
                    }
            )
            .onTapGesture(count: 2) { liked.toggle() }
    }
}

@GestureState resets to 1.0 automatically when the pinch ends, so the live zoom and the saved zoom stay separate. MagnifyGesture needs iOS 17; on older targets use MagnificationGesture, whose value is the scale itself.

For list rows, do not hand-build swipes. SwiftUI gives you the native behaviour, including the full-swipe shortcut:

List(messages) { message in
    Text(message.text)
        .swipeActions(edge: .trailing) {
            Button(role: .destructive) {
                delete(message)
            } label: {
                Label("Delete", systemImage: "trash")
            }
        }
}

In UIKit, the same ideas live in UITapGestureRecognizer, UIPanGestureRecognizer and UIPinchGestureRecognizer.

Flutter

Flutter wraps any widget in GestureDetector and ships higher-level widgets for the common cases.

Dismissible(
  key: ValueKey(message.id),
  direction: DismissDirection.endToStart,
  background: Container(
    color: Colors.red,
    alignment: Alignment.centerRight,
    padding: const EdgeInsets.only(right: 20),
    child: const Icon(Icons.delete, color: Colors.white),
  ),
  onDismissed: (_) => setState(() => messages.remove(message)),
  child: ListTile(title: Text(message.text)),
)

The key must be unique and stable, such as a database id, or Flutter may remove the wrong row. For zoom, InteractiveViewer(minScale: 1, maxScale: 5, child: Image.asset('assets/photo.jpg')) gives pinch and pan with no extra code, and GestureDetector(onDoubleTap: ..., onLongPress: ...) covers the rest.

React Native

The built-in touchables handle taps. For drags and pinches, most projects use react-native-gesture-handler with react-native-reanimated, so gestures run smoothly on the UI thread.

import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';

export function DraggableCard() {
  const offset = useSharedValue(0);

  const pan = Gesture.Pan()
    .onUpdate((e) => { offset.value = e.translationX; })
    .onEnd(() => { offset.value = withSpring(0); });

  const style = useAnimatedStyle(() => ({
    transform: [{ translateX: offset.value }],
  }));

  return (
    <GestureDetector gesture={pan}>
      <Animated.View style={[{ height: 96, backgroundColor: '#ddd' }, style]} />
    </GestureDetector>
  );
}

Wrap your app's root in GestureHandlerRootView, or gestures will not register. Gesture.Pinch() and Gesture.Tap().numberOfTaps(2) follow the same pattern, and Gesture.Simultaneous() lets pinch and pan work together.

Design rules that save you from bug reports

  • Make it discoverable. Show a hint the first time (a row that nudges left to reveal the delete action), and keep a visible button or menu item for the same action.
  • Respect system gestures. Android's gesture navigation uses edge swipes for Back, and iOS uses an edge swipe to go back in a navigation stack. Do not place your own horizontal swipe right at the screen edge.
  • Use proper target sizes. Material Design recommends touch targets of at least 48dp; Apple's guidelines suggest at least 44 by 44 points.
  • Confirm or undo destructive gestures. A snackbar with "Undo" after swipe-to-delete is friendlier than a dialog.
  • Give feedback. The item should move with the finger, and a light haptic tick when an action triggers helps users know it worked.

Accessibility

WCAG 2.2 success criterion 2.5.1 says that features using multi-point or path-based gestures (pinch, swipe patterns) must also work with a single pointer, and 2.5.7 asks for an alternative to dragging. Screen-reader users also navigate with swipes, so your custom swipe may never reach your code when TalkBack or VoiceOver is on. Expose the same actions as accessibility actions: Modifier.semantics { customActions = ... } in Compose, .accessibilityAction(named:) in SwiftUI, and Semantics in Flutter.

Testing gestures

  • Test on real devices, including a budget Android phone; emulators with a mouse hide many problems.
  • Try fast flicks, slow drags, and a drag that starts as a vertical scroll, inside scrolling lists.
  • Automate the critical ones: Compose UI tests have performTouchInput { swipeLeft() }, XCUITest has swipeLeft() and pinch(withScale:velocity:), and Flutter's WidgetTester has drag and fling.

If you work in Flutter, these Flutter widget examples show where GestureDetector fits in a widget tree; React Native developers should also read about React Native navigation, because stack navigators add their own swipe-back gesture. Smooth gestures depend on a fast UI thread, so keep mobile app performance in mind, and avoid the mistakes beginners make in Android development. For a final-year project, one well-designed gesture beats five hidden ones. If you want guided practice, Uncodemy's Android app development training covers Compose UI work.

Placed Students

Our Clients

Partners

...