Skip to content

trustee-wallet/react-native-easy-swipe

 
 

Repository files navigation

react-native-easy-swipe

Swipeable component for react native powered by Reanimated 2 and Gesture Handler

alt text

Installation

yarn add react-native-easy-swipe

Also add dependencies, and follow instructions there to setup your project

yarn add react-native-reanimated react-native-gesture-handler

Usage

import {
  SwipeableItem,
  withSwipeableContext,
  useSwipeableContext,
} from 'react-native-easy-swipe';

// ...

function YourComponent() {
    const { close } = useSwipeableContext();

    ... 

    const renderLeftActions = useCallback(() => {
        return (
            <SwipeableItem.Button onPress={handlePinPress}>
                <View style={[styles.delete, { backgroundColor: 'yellow' }]}>
                    <Text>Pin</Text>
                </View>
            </SwipeableItem.Button>
        );
    }, [handlePinPress]);

    return (
        <SwipeableItem
            containerStyle={styles.container}
            renderRightActions={renderRightActions}
            renderLeftActions={renderLeftActions}
            onStartDrag={handleStartDrag}
            onOpened={handleOnOpened}
            onClosed={handleOnClosed}
            onItemPress={handleItemPress}
        >
            <View style={styles.overlay}>
            <Image source={{ uri: item.avatar }} style={styles.avatar} />
            <View style={styles.info}>
                <Text style={styles.name}>{item.name}</Text>
                <Text>
                Lorem Ipsum is simply dummy text of the printing and typesetting
                industry.
                </Text>
            </View>
            </View>
        </SwipeableItem>
    );
}

export default withSwipeableContext(YourComponent);

Check Example for the trick I did to close the item when other opened.

Hint: I used Animated.ShareValue<number> to set the current item with menu opened

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

About

High performance swipeable item

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 55.8%
  • Java 24.3%
  • Objective-C 11.6%
  • JavaScript 5.3%
  • Ruby 2.4%
  • C 0.4%
  • Swift 0.2%