Skip to content

Commit 11adb43

Browse files
committed
Added onSwipe to DeckSwiper and Swiper
1 parent 80c84af commit 11adb43

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

example/src/DeckSwiperExample.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const DeckSwiperExample: React.FC = () => {
5050
infiniteSwiping
5151
visibleCardCount={2}
5252
data={sampleData}
53+
onSwipe={(index) => console.log("Swiped", index)}
5354
onSwipedDown={(index) => console.log("Swiped down", index)}
5455
onSwipedUp={(index) => console.log("Swiped up", index)}
5556
onSwipedLeft={(index) => console.log("Swiped left", index)}

example/src/SwiperExample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function SwiperExample({ theme }) {
3636
style={{ width: "100%", height: 300 }}
3737
dotColor="green"
3838
dotActiveColor="red"
39+
onSwipe={(index) => console.log("Swiped", index)}
3940
onSwipedNext={(index) => console.log("Swiped next", index)}
4041
onSwipedPrevious={(index) => console.log("Swiped previous", index)}
4142
onIndexChanged={(index) => console.log("onIndexChanged: ", index)}

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

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

55
export interface DeckSwiperProps<T> {
6+
onSwipe?: (index: number) => void;
67
onSwipedLeft?: (index: number) => void;
78
onSwipedRight?: (index: number) => void;
89
onSwipedUp?: (index: number) => void;
@@ -21,6 +22,7 @@ export interface DeckSwiperProps<T> {
2122
}
2223

2324
const DeckSwiper = <T extends object>({
25+
onSwipe,
2426
onSwipedLeft,
2527
onSwipedRight,
2628
onSwipedUp,
@@ -121,10 +123,22 @@ const DeckSwiper = <T extends object>({
121123
backgroundColor="transparent"
122124
cardVerticalMargin={0}
123125
cardHorizontalMargin={0}
124-
onSwipedLeft={onSwipedLeft}
125-
onSwipedRight={onSwipedRight}
126-
onSwipedTop={onSwipedUp}
127-
onSwipedBottom={onSwipedDown}
126+
onSwipedLeft={(index) => {
127+
onSwipedLeft?.(index);
128+
onSwipe?.(index);
129+
}}
130+
onSwipedRight={(index) => {
131+
onSwipedRight?.(index);
132+
onSwipe?.(index);
133+
}}
134+
onSwipedTop={(index) => {
135+
onSwipedUp?.(index);
136+
onSwipe?.(index);
137+
}}
138+
onSwipedBottom={(index) => {
139+
onSwipedDown?.(index);
140+
onSwipe?.(index);
141+
}}
128142
/>
129143
</View>
130144
);

packages/core/src/components/Swiper/Swiper.tsx

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

55
export interface SwiperProps<T> {
6+
onSwipe?: (index: number) => void;
67
onSwipedNext?: (index: number) => void;
78
onSwipedPrevious?: (index: number) => void;
89
vertical?: boolean;
@@ -41,6 +42,7 @@ const Swiper = ({
4142
renderItem,
4243
children,
4344
onIndexChanged: onIndexChangedProp,
45+
onSwipe,
4446
onSwipedNext,
4547
onSwipedPrevious,
4648
style,
@@ -66,6 +68,7 @@ const Swiper = ({
6668
} else if (current < previous) {
6769
onSwipedPrevious?.(previous);
6870
}
71+
onSwipe?.(previous);
6972
};
7073

7174
return (

0 commit comments

Comments
 (0)