Skip to content

Commit 9f93f80

Browse files
committed
Added 'onSwipedX' callbacks to DeckSwiper
1 parent 503b801 commit 9f93f80

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

example/src/DeckSwiperExample.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,23 @@ const DeckSwiperExample: React.FC = () => {
4545
</DeckSwiperCard>
4646
</DeckSwiper>
4747
</Section>
48-
48+
<Section title="Lazy Rendering (renderItem)" style={{}}>
49+
<DeckSwiper
50+
infiniteSwiping
51+
visibleCardCount={2}
52+
data={sampleData}
53+
onSwipedDown={(index) => console.log("Swiped down", index)}
54+
onSwipedUp={(index) => console.log("Swiped up", index)}
55+
onSwipedLeft={(index) => console.log("Swiped left", index)}
56+
onSwipedRight={(index) => console.log("Swiped right", index)}
57+
renderItem={({ item }) => (
58+
<DeckSwiperCard>
59+
<Text>{item.fullName}</Text>
60+
</DeckSwiperCard>
61+
)}
62+
keyExtractor={(item) => item.id.toString()}
63+
/>
64+
</Section>
4965
<Section title="Infinite swiper with images" style={{}}>
5066
<DeckSwiper infiniteSwiping visibleCardCount={2}>
5167
<DeckSwiperCard>
@@ -68,20 +84,6 @@ const DeckSwiperExample: React.FC = () => {
6884
</DeckSwiperCard>
6985
</DeckSwiper>
7086
</Section>
71-
72-
<Section title="Lazy Rendering (renderItem)" style={{}}>
73-
<DeckSwiper
74-
infiniteSwiping
75-
visibleCardCount={2}
76-
data={sampleData}
77-
renderItem={({ item }) => (
78-
<DeckSwiperCard>
79-
<Text>{item.fullName}</Text>
80-
</DeckSwiperCard>
81-
)}
82-
keyExtractor={(item) => item.id.toString()}
83-
/>
84-
</Section>
8587
</Container>
8688
);
8789
};

packages/core/src/components/DeckSwiper/DeckSwiper.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { StyleProp, ViewStyle, StyleSheet, View } from "react-native";
33
import DeckSwiperComponent from "react-native-deck-swiper";
44

55
export interface DeckSwiperProps<T> {
6+
onSwipedLeft?: (index: number) => void;
7+
onSwipedRight?: (index: number) => void;
8+
onSwipedUp?: (index: number) => void;
9+
onSwipedDown?: (index: number) => void;
610
onIndexChanged?: (index: number) => void;
711
onEndReached?: () => void;
812
startCardIndex?: number;
@@ -17,6 +21,10 @@ export interface DeckSwiperProps<T> {
1721
}
1822

1923
const DeckSwiper = <T extends object>({
24+
onSwipedLeft,
25+
onSwipedRight,
26+
onSwipedUp,
27+
onSwipedDown,
2028
onIndexChanged,
2129
onEndReached,
2230
startCardIndex = 0,
@@ -113,6 +121,10 @@ const DeckSwiper = <T extends object>({
113121
backgroundColor="transparent"
114122
cardVerticalMargin={0}
115123
cardHorizontalMargin={0}
124+
onSwipedLeft={onSwipedLeft}
125+
onSwipedRight={onSwipedRight}
126+
onSwipedTop={onSwipedUp}
127+
onSwipedBottom={onSwipedDown}
116128
/>
117129
</View>
118130
);

0 commit comments

Comments
 (0)