CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-redash

Utility library for React Native Reanimated and Gesture Handler providing mathematical functions, animations, transformations, and helper utilities for building complex gesture-driven animations.

Pending
Overview
Eval results
Files

animations.mddocs/

Animation Utilities

Advanced animation behaviors for React Native Reanimated including pausable animations and physics-based bouncing effects.

import type { Animation } from "react-native-reanimated";

Capabilities

Pausable Animations

Creates a wrapper around any animation that can be paused and resumed using a SharedValue boolean.

/**
 * Creates a pausable animation wrapper
 * @param nextAnimation - The animation to wrap (can be function or animation object)
 * @param paused - SharedValue<boolean> controlling pause state
 * @returns Animation that can be paused/resumed
 */
function withPause(
  nextAnimation: any,
  paused: Animated.SharedValue<boolean>
): number;

interface PausableAnimation extends Animation<PausableAnimation> {
  lastTimestamp: number;
  elapsed: number;
}

Usage Example:

import { withPause } from "react-native-redash";
import Animated, { 
  useSharedValue, 
  withSpring, 
  useAnimatedStyle 
} from "react-native-reanimated";

const paused = useSharedValue(false);
const progress = useSharedValue(0);

// Start pausable animation
progress.value = withPause(withSpring(1), paused);

// Pause the animation
paused.value = true;

// Resume the animation
paused.value = false;

const animatedStyle = useAnimatedStyle(() => ({
  opacity: progress.value
}));

Bouncing Physics

Adds bouncing behavior to physics-based animations when they hit specified boundaries.

/**
 * Add bouncing behavior to physics-based animations
 * @param nextAnimation - Physics animation with velocity (e.g., withDecay)
 * @param lowerBound - Lower boundary for bouncing
 * @param upperBound - Upper boundary for bouncing
 * @returns Animation that bounces between bounds
 */
function withBouncing(
  nextAnimation: any,
  lowerBound: number,
  upperBound: number
): number;

interface PhysicsAnimation extends Animation<PhysicsAnimation> {
  velocity: number;
  current: number;
}

Usage Example:

import { withBouncing } from "react-native-redash";
import Animated, { 
  useSharedValue, 
  withDecay, 
  useAnimatedGestureHandler 
} from "react-native-reanimated";
import { PanGestureHandler } from "react-native-gesture-handler";

const translateX = useSharedValue(0);

const gestureHandler = useAnimatedGestureHandler({
  onEnd: (event) => {
    // Bounce between 0 and 300 pixels
    translateX.value = withBouncing(
      withDecay({ velocity: event.velocityX }),
      0,
      300
    );
  }
});

const animatedStyle = useAnimatedStyle(() => ({
  transform: [{ translateX: translateX.value }]
}));

Types

interface PausableAnimation extends Animation<PausableAnimation> {
  /** Timestamp of the last frame before pause */
  lastTimestamp: number;
  /** Time elapsed while paused */
  elapsed: number;
}

interface PhysicsAnimation extends Animation<PhysicsAnimation> {
  /** Current velocity of the animation */
  velocity: number;
  /** Current value of the animation */
  current: number;
}

Install with Tessl CLI

npx tessl i tessl/npm-react-native-redash

docs

animations.md

colors.md

components.md

coordinates.md

index.md

math.md

matrices.md

paths.md

transforms.md

transitions.md

utilities.md

vectors.md

tile.json