API 레퍼런스

주요 export

export {
  SwipeDeckActionMotion,
  SwipeDeckMotion,
  createSwipeDeck,
  SwipeDeck,
  SwipeDeckUndoMotion,
} from '@react-native-motion-kit/swipe-deck';

Source 보기

createSwipeDeck<T>(config?)

Typed deck family를 만듭니다.

const ProfileDeck = createSwipeDeck<Profile>({
  motion: SwipeDeckMotion.tinder(),
});

반환되는 instance는 다음을 포함합니다.

  • Root
  • Card
  • useDeckState
  • useDeckActions
  • useDeckInteraction
  • useDeckEvent
  • useDeckEventListener

SwipeDeck.Root props

Source 보기

PropType설명
idstringFactory-scoped deck namespace입니다.
datareadonly T[]Deck이 렌더링할 ordered item입니다.
getKey(item: T, index: number) => string필수 stable item key입니다.
initialIndexnumber초기 active item index입니다.
disabledbooleanaccepted action과 gesture를 비활성화합니다.
allowedDirectionsAllowedDirections허용할 dismiss direction을 제한합니다.
swipeThresholdSwipeThresholdRoot-level dismiss threshold override입니다.
velocityThresholdnumberRoot-level flick threshold override입니다.
motionSwipeDeckMotionPresetGesture-driven motion preset입니다.
actionMotionSwipeDeckActionMotionRecipeProgrammatic swipe motion recipe입니다.
undoMotionSwipeDeckUndoMotionRecipeProgrammatic undo restore motion recipe입니다.
undoEnabledbooleanUndo history tracking을 활성화합니다.
visibleCardCountnumberForward mounted card의 최대 budget입니다.
containerStyleStyleProp<ViewStyle>Deck container에 적용할 style입니다.
childrenReactNodeMatching SwipeDeck.Card를 포함해야 합니다.
type AllowedDirections = readonly ('left' | 'right')[];
type SwipeThreshold = number | ((layout: SwipeDeckLayout) => number);

Static SwipeDeck.Rootid를 제외한 같은 props를 받습니다.

SwipeDeck.Card props

PropType설명
styleStyleProp<ViewStyle>Absolute card container에 적용됩니다.
children(info: SwipeRenderInfo<T>) => ReactNodeBounded window의 item 하나를 렌더링합니다.

SwipeRenderInfo<T>item, index, offset, role, isActive를 포함합니다.

State와 Actions

type SwipeDeckState = {
  activeIndex: number;
  count: number;
  isCompleted: boolean;
  canSwipe: boolean;
  canUndo: boolean;
};

type SwipeDeckActions = {
  swipeLeft: SwipeDeckAction;
  swipeRight: SwipeDeckAction;
  undo: SwipeDeckUndoAction;
};

Programmatic action은 action이 받아들여졌는지 알려주는 boolean을 반환합니다.

Interaction

type SwipeDeckInteractionPhase = 'idle' | 'dragging' | 'dismissing' | 'undoing';

useDeckInteraction()progress, signedProgress, direction, dismissDirection, translationX, translationY, isDragging, phase Reanimated shared value를 반환합니다.

Events

type SwipeDeckEventMap<T> = {
  swipe: SwipeEvent<T>;
  undo: UndoEvent<T>;
  indexChange: { index: number };
  endReached: true;
};

최신 event snapshot에는 useDeckEvent를, imperative subscription에는 useDeckEventListener를 사용하세요.

Motion Helpers

  • SwipeDeckMotion.tinder(options?)
  • SwipeDeckActionMotion.direct(options?)
  • SwipeDeckActionMotion.springboard(options?)
  • SwipeDeckUndoMotion.spring(options?)
  • SwipeDeckUndoMotion.timing(options?)

동작 세부 사항은 이 reference보다 guide page를 먼저 참고하는 것을 권장합니다.