Magnet Spring Animation
Monday, November 17, 2025
demos
magnet-spring
An ongoing collection of React Native animations crafted with Reanimated, Gesture Handler, and Skia.
TypeScript
3.2k
296
A physics-based magnetic snap interaction where a draggable object snaps to the nearest magnet point with spring animations. Magnets react visually as the object approaches them.
What's This About?
This component simulates magnetic attraction physics. Drag the main object around the screen, and when released, it springs to the nearest magnet point. The magnets themselves scale up and change color as the object gets closer, creating an engaging visual feedback loop.
Technical Implementation
The interaction features sophisticated physics:
Fibonacci Positioning: Magnets are placed using golden ratio spiral for aesthetic arrangement
Nearest Neighbor: Efficient distance calculation to find closest magnet
Spring Physics: Mass, damping, and stiffness tuned for metallic feel
Reactive Magnets: Scale and color interpolate based on object proximity
Velocity Preservation: Release velocity is passed to spring for natural motion
How It Works
Magnets are positioned in a Fibonacci spiral pattern plus center point
Drag the main object anywhere on screen
Object scales up slightly while being dragged
On release, nearest magnet is calculated using Euclidean distance
Object springs to nearest magnet with velocity-aware animation
Nearby magnets visually react by scaling and changing color
Spring Configuration
Mass: 0.4 for responsive feel
Damping: 15 for metallic bounce
Stiffness: 120 for rigid metallic behavior
Velocity: Preserved from drag gesture for natural motion
Usage
import { Magnets } from './magnet-spring';
// Customizable props available
<Magnets
magnets={customPositions} // Array of {x, y} positions
initialPosition={{ x: 100, y: 100 }}
magnetRadius={10}
magnetColor="#c1c1c1"
objectRadius={25}
objectColor="#3b3b3b"
/>;
Unlock the beauty of React Native animations
Learn Reanimated, Gesture Handler & Skia with Reanimate.dev
Feedback on Magnet Spring
Ideas, bugs, or anything that felt off: I read every message. For anything else, write to hello@reactiive.io.
Send feedback