zahid ansari
Building scalable systems by applying mental models to code and architecture.
Website
Install this app to stay connected and in the loop.
Building meaningful experiences one pixel at a time 😉.
Made with by Zahid
views
zahid ansari
Building scalable systems by applying mental models to code and architecture.
Website
Install this app to stay connected and in the loop.
Building meaningful experiences one pixel at a time 😉.
Made with by Zahid
views

Share
Upgrade your mobile UI from static to fluid. A guide to implementing pinch, swipe, and pan gestures with Reanimated.
Static mobile apps feel boring. Users expect to swipe, drag, and pinch. To achieve 60fps animations that respond to touch, we combine React Native Gesture Handler with Reanimated.
I tried building a "swipe to delete" feature using the built-in React Native PanResponder. It was janky, blocked the JS thread, and stuttered on older Android devices. I needed a solution that ran on the UI thread.
Reanimated allows us to declare animation logic that runs entirely on the native UI thread, bypassing the React Native Javascript bridge bottleneck.
1import React from 'react';
2import { StyleSheet } from 'react-native';
3import { GestureDetector, Gesture } from 'react-native-gesture-handler';
4import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
5
6export default function DraggableCard() {
7 const translateX = useSharedValue(0);
8 const translateY = useSharedValue(0);
9
10 const gesture = Gesture.Pan()
11 .onUpdate((event) => {
12 translateX.value = event.translationX;
13 translateY.value = event.translationY;
14 })
15 .onEnd(() => {
16 // Snap back to center
17 translateX.value = withSpring(0);
18 translateY.value = withSpring(0);
19 });
20
21 const rStyle = useAnimatedStyle(() => {
22 return {
23 transform: [
24 { translateX: translateX.value },
25 { translateY: translateY.value },
26 ],
27 };
28 });
29
30 return (
31 <GestureDetector gesture={gesture}>
32 <Animated.View style={[styles.box, rStyle]} />
33 </GestureDetector>
34 );
35}
36
37const styles = StyleSheet.create({
38 box: { height: 100, width: 100, backgroundColor: '#E63946', borderRadius: 20 },
39});1GestureHandlerRootView1GestureHandlerRootView1app/_layout.tsx1withSpring1withTiming1useSharedValueFluid gestures make your app feel native and high-quality. With the declarative API of Gesture Handler 2.0, it's easier than ever.
Tech Stack: React Native, Expo, Reanimated, Gesture Handler