Top Related Projects
React Native's Animated library reimplemented
Declarative API exposing platform native touch and gesture system to React Native.
Standard set of easy to use animations and declarative transitions for React Native
Experimental implementation of high performance interactable views in React Native
🦉 Simple and complete React Native testing utilities that encourage good testing practices.
Quick Overview
React Native Redash is a utility library for React Native that provides a set of helper functions and hooks to simplify common tasks in React Native development. It focuses on animations, gestures, and other frequently used operations, making it easier for developers to create smooth and interactive mobile applications.
Pros
- Simplifies complex animations and gestures in React Native
- Provides a wide range of utility functions for common tasks
- Integrates well with React Native Reanimated and React Native Gesture Handler
- Regularly updated and maintained
Cons
- Adds an additional dependency to your project
- Some functions may have a learning curve for beginners
- Requires React Native Reanimated and React Native Gesture Handler as peer dependencies
- May introduce unnecessary overhead for simple projects
Code Examples
- Using the
useVector
hook for 2D animations:
import { useVector } from 'react-native-redash';
const MyComponent = () => {
const translation = useVector();
return (
<Animated.View
style={{
transform: [{ translateX: translation.x }, { translateY: translation.y }],
}}
/>
);
};
- Implementing a circular progress indicator:
import { polar2Canvas } from 'react-native-redash';
const CircularProgress = ({ progress }) => {
const { x, y } = polar2Canvas(
{ theta: progress * 2 * Math.PI, radius: 50 },
{ x: 50, y: 50 }
);
return (
<Svg width={100} height={100}>
<Circle cx={50} cy={50} r={45} stroke="gray" strokeWidth={10} />
<Line x1={50} y1={50} x2={x} y2={y} stroke="blue" strokeWidth={10} strokeLinecap="round" />
</Svg>
);
};
- Using the
useScrollHandler
hook for scroll animations:
import { useScrollHandler } from 'react-native-redash';
const ScrollComponent = () => {
const { scrollHandler, x } = useScrollHandler();
return (
<Animated.ScrollView
horizontal
onScroll={scrollHandler}
scrollEventThrottle={16}
>
{/* Scroll content */}
</Animated.ScrollView>
);
};
Getting Started
To start using React Native Redash, first install it along with its peer dependencies:
npm install react-native-redash react-native-reanimated react-native-gesture-handler
Then, import the desired functions or hooks in your React Native components:
import { useVector, polar2Canvas, useScrollHandler } from 'react-native-redash';
// Use the imported functions in your components
Make sure to follow the installation instructions for React Native Reanimated and React Native Gesture Handler as well, as they are required for Redash to work properly.
Competitor Comparisons
React Native's Animated library reimplemented
Pros of react-native-reanimated
- More powerful and flexible animation system
- Better performance for complex animations
- Supports worklets for running animations on the UI thread
Cons of react-native-reanimated
- Steeper learning curve
- Requires additional setup and configuration
- Larger package size
Code Comparison
react-native-reanimated:
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
const offset = useSharedValue(0);
const animatedStyles = useAnimatedStyle(() => {
return { transform: [{ translateX: withSpring(offset.value) }] };
});
react-native-redash:
import { useSpring } from 'react-native-redash';
import Animated from 'react-native-reanimated';
const offset = useSpring(0);
const animatedStyles = { transform: [{ translateX: offset }] };
react-native-reanimated offers more granular control over animations and better performance for complex scenarios, but comes with a steeper learning curve. react-native-redash provides a simpler API built on top of react-native-reanimated, making it easier to use for basic animations but potentially limiting for more advanced use cases. The choice between the two depends on the complexity of your animations and your familiarity with the React Native animation ecosystem.
Declarative API exposing platform native touch and gesture system to React Native.
Pros of react-native-gesture-handler
- More comprehensive gesture handling system
- Better performance due to native implementation
- Wider range of supported gestures and interactions
Cons of react-native-gesture-handler
- Steeper learning curve
- Requires additional setup and configuration
- May be overkill for simpler projects
Code Comparison
react-native-gesture-handler:
import { PanGestureHandler, State } from 'react-native-gesture-handler';
<PanGestureHandler
onGestureEvent={this._onPanGestureEvent}
onHandlerStateChange={this._onPanHandlerStateChange}>
<Animated.View style={styles.box} />
</PanGestureHandler>
react-native-redash:
import { useValues, usePanGestureHandler } from 'react-native-redash';
const { gestureHandler, translation, state } = usePanGestureHandler();
<Animated.View {...gestureHandler} style={[styles.box, style]} />
react-native-gesture-handler provides a more granular control over gestures but requires more setup. react-native-redash offers a simpler API with hooks, making it easier to use for basic gesture handling. The choice between the two depends on the project's complexity and specific gesture requirements.
Standard set of easy to use animations and declarative transitions for React Native
Pros of react-native-animatable
- Easier to use for beginners with pre-defined animations
- Supports both imperative and declarative animation styles
- Larger community and more established project (higher star count)
Cons of react-native-animatable
- Less flexible for complex, custom animations
- May have performance limitations for intricate animations
- Not as well-integrated with React Native's Animated API
Code Comparison
react-native-animatable:
import * as Animatable from 'react-native-animatable';
<Animatable.View animation="fadeIn" duration={1000}>
<Text>Fading in</Text>
</Animatable.View>
react-native-redash:
import { useTimingTransition } from 'react-native-redash';
import Animated, { interpolate } from 'react-native-reanimated';
const progress = useTimingTransition(isVisible);
const opacity = interpolate(progress, {
inputRange: [0, 1],
outputRange: [0, 1],
});
react-native-animatable offers a more straightforward approach for simple animations, while react-native-redash provides greater control and integration with React Native's animation system for complex scenarios. The choice between the two depends on the project's specific animation requirements and the developer's familiarity with React Native's animation concepts.
Experimental implementation of high performance interactable views in React Native
Pros of react-native-interactable
- Provides high-performance interactive views for React Native
- Offers smooth animations and gestures with native drivers
- Includes ready-to-use components like drawer and swipeable card
Cons of react-native-interactable
- Less actively maintained compared to react-native-redash
- Limited to specific interactive components, while redash offers a broader utility set
- May require more setup and configuration for complex interactions
Code Comparison
react-native-interactable:
<Interactable.View
snapPoints={[{x: 0}, {x: 200}]}
dragEnabled={true}
>
<View style={styles.card} />
</Interactable.View>
react-native-redash:
const translateX = useSharedValue(0);
const gestureHandler = useAnimatedGestureHandler({
onActive: (event) => {
translateX.value = event.translationX;
},
});
react-native-interactable focuses on providing pre-built interactive components with native performance, while react-native-redash offers a set of utilities and hooks for building custom animations and gestures. The choice between them depends on the specific needs of your project and the level of customization required.
🦉 Simple and complete React Native testing utilities that encourage good testing practices.
Pros of react-native-testing-library
- Focused on testing React Native components, providing a more specialized toolset
- Encourages writing tests that closely resemble how users interact with the app
- Offers a wide range of query methods to find elements in the rendered component tree
Cons of react-native-testing-library
- Limited to testing React Native components, while redash offers utility functions for various aspects of React Native development
- May require additional setup and configuration compared to redash's out-of-the-box utility functions
- Learning curve for developers new to testing React Native applications
Code Comparison
react-native-testing-library:
import { render, fireEvent } from '@testing-library/react-native';
test('button press increments counter', () => {
const { getByText } = render(<Counter />);
const button = getByText('Increment');
fireEvent.press(button);
expect(getByText('Count: 1')).toBeTruthy();
});
react-native-redash:
import { useVector } from 'react-native-redash';
const MyComponent = () => {
const translation = useVector();
return <Animated.View style={{ transform: [{ translateX: translation.x }] }} />;
};
This comparison highlights the different focus areas of the two libraries. react-native-testing-library is specifically designed for testing React Native components, while react-native-redash provides utility functions for animations and gestures in React Native development.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
redash
The React Native Reanimated and Gesture Handler Toolbelt. As seen on the âCan it be done in React Native?â YouTube series.
Installation
yarn add react-native-redash
Documentation
https://wcandillon.gitbook.io/redash/
â ï¸ Reanimated v1 â ï¸
Please use v14.2.2
v1 documentation: https://wcandillon.github.io/react-native-redash-v1-docs/
Top Related Projects
React Native's Animated library reimplemented
Declarative API exposing platform native touch and gesture system to React Native.
Standard set of easy to use animations and declarative transitions for React Native
Experimental implementation of high performance interactable views in React Native
🦉 Simple and complete React Native testing utilities that encourage good testing practices.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot