1.1.15 ā€¢ Published 1 year ago

easy-swipe-view v1.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

easy-swipe-view

npm.io

A simple and easy-to-use swipeable list component for React Native projects, built with Reanimated v2 and react-native-gesture-handler.

  • Smooth gesture interactions & snapping animations.
  • Compatible with Reanimated v3
  • Compatible with Expo.
  • FlatList and ScrollView support.
  • Written in TypeScript
  • Predefined Buttons components for swipe actions

Installation

First, make sure you have installed react-native-reanimated v3 and react-native-gesture-handler in your project: Then,

npm install easy-swipe-view

or

yarn add easy-swipe-view

or

pnpm add easy-swipe-view

Usage

SwipeView Component

  1. Import the SwipeView component and the EasySwipe context:
import { SwipeView, EasySwipe, LeftButton, RightButton  } from 'easy-swipe-view';
  1. Wrap your list component (e.g., ScrollView, FlatList or SectionList) with the EasySwipe.Provider:

Note šŸ’” If you are not going to use the component inside a scrollable element, skip this step.

<EasySwipe.Provider value={ref}>
  <FlatList
    ref={ref}
    ...
  />
</EasySwipe.Provider>
  1. Use the SwipeView component as a wrapper for your list items:
const MyLeftButtonComponent = () => (
  <LeftButton
    onPress={leftButtonAction}
    width={100}
    backgroundColor="#ff0015"
  >
    <Octicons name="trash" size={22} color={"#fff"} />
  </LeftButton>
);

const MyRightButtonComponent = () => (
  <RightButton
    onPress={rightButtonAction}
    width={100}
    backgroundColor="#0088ff"
  >
    <Octicons name="archive" size={22} color={"#fff"} />
  </RightButton>
);
<SwipeView
  ref={swipeRef}
  LeftButton={MyLeftButtonComponent} //If you leave it blank, it will be disabled.
  RightButton={MyRightButtonComponent} //If you leave it blank, it will be disabled.
  leftOffset={100}
  rightOffset={100}
  maxLeft={150}
  maxRight={150}
  onLeftSwipe={() => console.log("On Swipe!")}
  onRightSwipe={() => console.log("On Swipe!")}
  onSwipe={(position) => console.log(position)}
>
  <View 
    style={{
      width: '100%',
      backgroundColor: 'gray',
      paddingTop: 6,
      paddingBottom: 6,
      paddingLeft: 4,
      paddingRight: 4,
      alignItems: 'center'
    }}
  >
    <Text style={{color: "#030303"}}>Swipe me!</Text>
  </View>
</SwipeView>

If you want to reset the position by outside intervention;

<TouchableHighlight onPress={() => swipeRef.current.resetPosition()}>
  <Text>Reset</Text>
</TouchableHighlight>

SwipeList Component

  1. Import the SwipeList component:
import { SwipeList } from 'easy-swipe-view';
  1. Use the SwipeList component as a wrapper for your FlatList:
<SwipeList
  LeftButton={MyLeftButtonComponent}
  RightButton={MyRightButtonComponent}
  leftOffset={myLeftOffset}
  rightOffset={myRightOffset}
  maxLeft={150}
  maxRight={150}
  onLeftSwipe={() => console.log("On Swipe!")}
  onRightSwipe={() => console.log("On Swipe!")}
  onSwipe={(position) => console.log(position)}
  data={yourData}
  renderItem={({item}) => (
    <View 
      style={{
        width: '100%',
        backgroundColor: 'gray',
        paddingTop: 6,
        paddingBottom: 6,
        paddingLeft: 4,
        paddingRight: 4,
        alignItems: 'center'
      }}
    >
      <Text style={{color: "#030303"}}>{item.title}</Text>
    </View>
  )}
  keyExtractor={(item, index) => index.toString()}
/>

Props Documentation

This file contains the props documentation for the SwipeView, Buttons, and SwipeList components.

SwipeView Props

PropTypeDefaultDescription
LeftButtonComponentnullThe component to be rendered when swiping to the right. If not provided, left swipe will be disabled.
RightButtonComponentnullThe component to be rendered when swiping to the left. If not provided, right swipe will be disabled.
leftOffsetnumber100The offset required to trigger a left swipe action.
rightOffsetnumber100The offset required to trigger a right swipe action.
maxLeftnumber150The maximum distance the item can be swiped to the right.
maxRightnumber150The maximum distance the item can be swiped to the left.
onLeftSwipe(value: number) => voidnullA callback function to be called when a left swipe action is triggered.
onRightSwipe(value: number) => voidnullA callback function to be called when a right swipe action is triggered.
onSwipe(value: number) => voidnullA callback function to be called when the item is being swiped.
childrenReact.ReactNodenullThe content of the SwipeView component.

Buttons Props

PropTypeDefaultDescription
onPress() => void() => {}The callback function to be called when the button is pressed.
widthnumber100The width of the button component.
backgroundColorstring'#ff0015' for LeftButton, '#0088ff' for RightButtonThe background color of the button component.
underlayColorstring'#b00412' for LeftButton, '#0077ff' for RightButtonThe background color of the button component for active.
styleViewStyle{}Additional styles for the button component.
childrenReact.ReactNode<></>The content of the button component.
...propsany-Other props to be passed down to the TouchableHighlight component.

SwipeList Props

PropTypeDefaultDescription
...flatListPropsany-All other props available for the FlatList component.
LeftButtonComponentnullThe component to be rendered when swiping to the right. If not provided, left swipe will be disabled.
RightButtonComponentnullThe component to be rendered when swiping to the left. If not provided, right swipe will be disabled.
leftOffsetnumber100The offset required to trigger a left swipe action.
rightOffsetnumber100The offset required to trigger a right swipe action.
maxLeftnumber150The maximum distance the item can be swiped to the right.
maxRightnumber150The maximum distance the item can be swiped to the left.
onLeftSwipe(value: number) => voidnullA callback function to be called when a left swipe action is triggered.
onRightSwipe(value: number) => voidnullA callback function to be called when a right swipe action is triggered.
onSwipe(value: number) => voidnullA callback function to be called when the item is being swiped.
renderItem({item, index}) => JSX.ElementnullA function that returns the component to be rendered for each item in the list. Must be wrapped with SwipeView.

Please refer to the examples provided in the repository for detailed usage instructions.

Author

Aras Ors

Kahve

Lisans

MIT

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago