Sign in to Reactiive

Use your Google or Apple account.
Signing in subscribes you to the newsletter: new content and the occasional promotion. Unsubscribe at any time.
Skip to content

Balance Slider with Reanimated

Sunday, January 21, 2024
enzomanuelmangano
demos
balance-slider
An ongoing collection of React Native animations crafted with Reanimated, Gesture Handler, and Skia.
TypeScript
3.2k
296
A dual-sided slider component that allows users to balance between two options. Perfect for scenarios where users need to adjust relative proportions, like mixing coffee and milk or balancing audio channels.

What's This About?

This component creates an interactive slider where both sides respond to user input, maintaining a total of 100% between them. As one side increases, the other decreases proportionally, with smooth animations and visual feedback showing the current balance.

Technical Implementation

The component uses gesture handling for precise control and features smart shrinking behavior when values reach certain thresholds. It supports custom colors, labels, and percentage limits for optimal visual presentation.

Usage

type BalanceSliderProps = { width: number; height: number; onChange: (values: { leftPercentage: number; rightPercentage: number; }) => void; leftLabel: string; rightLabel: string; colors: { left: { box: string; label: string; percentage: string; }; right: { box: string; label: string; percentage: string; }; }; leftPercentageLimitBeforeShift: number; rightPercentageLimitBeforeShift: number; }; // Example usage <BalanceSlider width={300} height={50} leftLabel="Coffee" rightLabel="Milk" onChange={({ leftPercentage, rightPercentage }) => { console.log(leftPercentage, rightPercentage); }} />;

Unlock the beauty of React Native animations

Learn Reanimated, Gesture Handler & Skia with Reanimate.dev

Feedback on Balance Slider

Ideas, bugs, or anything that felt off: I read every message. For anything else, write to hello@reactiive.io.
Send feedback