Skip to content

API Reference

SwipeableStack

The main component for rendering a stack of swipeable cards.

tsx
import { SwipeableStack } from 'react-native-swipeable-stack';

Required Props

PropTypeDescription
dataT[]Array of items to display
renderCard(item: T, index: number) => ReactNodeRender function for each card
keyExtractor(item: T) => stringUnique key for each item

Callbacks

PropTypeDescription
onSwipeLeft(item: T, index: number) => voidCalled when card swiped left
onSwipeRight(item: T, index: number) => voidCalled when card swiped right
onSwipeStart(direction: SwipeDirection) => voidCalled when swipe gesture starts
onSwipeComplete(direction: SwipeDirection, item: T, index: number) => voidCalled when swipe animation completes
onEmpty() => voidCalled when all cards are swiped
onIndexChange(index: number) => voidCalled when current index changes

Configuration

PropTypeDefaultDescription
swipeThresholdnumberscreenWidth * 0.3Distance to trigger swipe
velocityThresholdnumber800Velocity to trigger swipe
visibleCardsnumber2Number of visible cards in stack
maxRotationnumber15Max rotation angle in degrees
verticalSwipeFrictionnumber0.2Dampens vertical movement
disabledbooleanfalseDisable gestures
initialIndexnumber0Starting card index
animationConfigAnimationConfigSee belowAnimation physics settings

Overlays

PropTypeDescription
renderLeftOverlay() => ReactNodeCustom "NOPE" overlay
renderRightOverlay() => ReactNodeCustom "LIKE" overlay
overlayConfigOverlayConfigOverlay opacity settings

Styling

PropTypeDescription
containerStyleViewStyleContainer style
cardWrapperStyleViewStyleCard wrapper style

SwipeableStackRef

Ref handle for imperative control of the stack.

tsx
const stackRef = useRef<SwipeableStackRef>(null);

Methods

MethodTypeDescription
swipeLeft()() => voidProgrammatically swipe left
swipeRight()() => voidProgrammatically swipe right
undo()() => voidUndo last swipe
getCurrentIndex()() => numberGet current card index

Example

tsx
// Trigger swipes from buttons
<Button title="Nope" onPress={() => stackRef.current?.swipeLeft()} />
<Button title="Like" onPress={() => stackRef.current?.swipeRight()} />
<Button title="Undo" onPress={() => stackRef.current?.undo()} />

AnimationConfig

Configuration for various animation states.

tsx
interface AnimationConfig {
  swipeSpring?: SpringConfig;    // Swipe-out animation
  returnSpring?: SpringConfig;   // Return-to-center animation
  programmaticTiming?: TimingConfig; // Button-triggered swipes
  nextCardSpring?: SpringConfig; // Next card reveal animation
}

SpringConfig

tsx
interface SpringConfig {
  stiffness?: number;  // Default: 200 (swipe), 300 (return), 100 (next)
  damping?: number;    // Default: 20 (swipe), 30 (return), 15 (next)
  mass?: number;       // Default: 0.5
  velocity?: number;   // Usually from gesture
}

TimingConfig

tsx
interface TimingConfig {
  duration?: number;   // Default: 200ms
}

Example

tsx
<SwipeableStack
  animationConfig={{
    swipeSpring: {
      stiffness: 250,
      damping: 25,
      mass: 0.6,
    },
    returnSpring: {
      stiffness: 400,
      damping: 35,
    },
    programmaticTiming: {
      duration: 300,
    },
  }}
/>

OverlayConfig

Configuration for overlay opacity animation.

tsx
interface OverlayConfig {
  inputRange?: [number, number];   // Default: [0, 0.2]
  outputRange?: [number, number];  // Default: [0, 1]
}
PropertyDefaultDescription
inputRange[0, 0.2]Percentage of screen width
outputRange[0, 1]Opacity values (0 to 1)

Types

All types are exported for TypeScript usage:

tsx
import type {
  SwipeDirection,
  SwipeableStackProps,
  SwipeableStackRef,
  AnimationConfig,
  SpringConfig,
  TimingConfig,
  OverlayConfig,
} from 'react-native-swipeable-stack';

SwipeDirection

tsx
type SwipeDirection = 'left' | 'right';

Released under the MIT License.