Command palette

@yasinsensoy/native

React Native · Components

Swipeable

A container that reveals actions when the row is swiped sideways (like iOS Mail, Android Gmail).

5 exports

Import

import { Swipeable } from "@yasinsensoy/native";

Swipeable

component

A container that reveals actions when the row is swiped sideways (like iOS Mail, Android Gmail). In lists, swipe left to delete/archive, right to pin/mark read.

  • Horizontal pulls belong to the row, vertical ones to the list: the list does not scroll while the row is pulled and the row does not open while the list scrolls (@yasinsensoy/native/gesture, decided on the native side). A pull towards a direction without actions goes to the outer gesture (e.g. navigation's "back" swipe).
  • Only one row stays open at a time; it closes when the list scrolls or the open row's content is tapped.
  • fullSwipe: pulling all the way and releasing runs the outermost action.
  • Screen readers: actions are offered as the row's accessibility actions (swipe up/down in VoiceOver, the actions menu in TalkBack).
  • Edges swap in right-to-left languages.
Swipeable({ ref, children, startActions, endActions, fullSwipe, actionWidth, disabled, closeOnScroll, onOpenChange, style, contentStyle, }: SwipeableProps): JSX.Element

Examples

<VirtualList
  items={messages}
  getKey={(m) => m.id}
  renderItem={(m) => (
    <Swipeable
      startActions={[{ key: "read", label: "Read", icon: "check", tone: "primary", onPress: () => markRead(m) }]}
      endActions={[
        { key: "delete", label: "Delete", icon: "trash", tone: "danger", onPress: () => remove(m) },
        { key: "archive", label: "Archive", icon: "inbox", onPress: () => archive(m) },
      ]}
      fullSwipe="end"
    >
      <MessageRow message={m} />
    </Swipeable>
  )}
/>

Row edge: start is the left one (the right one in right-to-left languages), end the opposite.

type SwipeSide = "start" | "end"

SwipeAction

interface

Action revealed when the row is swiped sideways.

NameTypeDefaultDescription
keystringUnique key (also the name of the screen reader action).
labelstringButton text; screen readers read it too.
icon?IconPropIcon above the text (e.g. "trash", "pin", "inbox").
tone?Tone"neutral"Color.
onPress() => voidThe action was chosen (button pressed or triggered by a full swipe).
keepOpen?booleanfalseThe row stays open on press (e.g. a button that opens a "More" menu).

Methods of a Swipeable instance.

NameTypeDescription
open(side: SwipeSide): voidOpens the actions of one edge.
close(): voidCloses the row.

Swipeable props.

NameTypeDefaultDescription
ref?Ref<SwipeableHandle>Methods: open, close.
childrenReactNodeRow content.
startActions?readonly SwipeAction[]Actions on the start edge (when the finger pulls right; left in right-to-left languages). The first item is the outermost; a full swipe triggers it.
endActions?readonly SwipeAction[]Actions on the end edge (when the finger pulls left). The first item is the outermost.
fullSwipe?boolean | SwipeSidefalseFull swipe: pulling most of the row width and releasing runs the outermost action without pressing the button (e.g. "Delete", "Archive"). true for both edges.
actionWidth?number76Width of one button (dp).
disabled?booleanCannot be swiped while disabled.
closeOnScroll?booleantrueThe open row closes when the list starts scrolling (it always closes when another drag starts).
onOpenChange?(side: SwipeSide | null) => voidThe open edge changed (null: closed).
style?StyleProp<ViewStyle>Outer container style (e.g. margin, corner radius).
contentStyle?StyleProp<ViewStyle>Style of the sliding content. The content background defaults to the theme background color: actions only show when pulled.