Shopify Jan 20, 2023

Making React Native Gestures Feel Natural

Article Summary

Andrew Lo from Shopify reveals why your React Native gestures feel clunky. The fix? Two simple physics principles most developers ignore.

Shopify's Staff Front End Developer breaks down how the Shop app's draggable Sheet component went from frustrating to delightful. Using real examples with code, he shows how velocity tracking and spring animations transform basic gesture handlers into interactions that feel natural.

Key Takeaways

Critical Insight

Incorporating velocity tracking and spring-based animations makes draggable components respond naturally to user intent instead of just finger position.

The article includes the complete gesture handler code showing exactly how Shopify implements elasticity to teach users UI boundaries without words.

About This Article

Problem

Shopify's Sheet component used a fixed 600ms animation to reach its destination, no matter how far it traveled. This made small movements feel slow and large movements feel rushed.

Solution

Andrew Lo switched from the fixed-duration Easing.out(Easing.exp) animation to withSpring. The spring animation calculates speed based on distance and velocity using physics parameters, with damping set to 5.

Impact

The Sheet now animates based on what actually happens. Closer positions finish quickly while momentum from fast flicks carries through to the end. It feels responsive to what the user does instead of following a preset timer.

Recent from Shopify

Related Articles