anyswipe-swipedeck 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/SwipeDeck.d.ts +16 -0
- package/dist/SwipeDeck.d.ts.map +1 -0
- package/dist/SwipeDeck.js +38 -0
- package/dist/SwipeDeck.js.map +1 -0
- package/dist/SwipeableWrapper.d.ts +16 -0
- package/dist/SwipeableWrapper.d.ts.map +1 -0
- package/dist/SwipeableWrapper.js +161 -0
- package/dist/SwipeableWrapper.js.map +1 -0
- package/dist/hooks/useSwipeDeck.d.ts +11 -0
- package/dist/hooks/useSwipeDeck.d.ts.map +1 -0
- package/dist/hooks/useSwipeDeck.js +14 -0
- package/dist/hooks/useSwipeDeck.js.map +1 -0
- package/dist/hooks/useSwipeState.d.ts +21 -0
- package/dist/hooks/useSwipeState.d.ts.map +1 -0
- package/dist/hooks/useSwipeState.js +117 -0
- package/dist/hooks/useSwipeState.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/SwipeDeck.styles.d.ts +9 -0
- package/dist/styles/SwipeDeck.styles.d.ts.map +1 -0
- package/dist/styles/SwipeDeck.styles.js +10 -0
- package/dist/styles/SwipeDeck.styles.js.map +1 -0
- package/dist/styles/SwipeableWrapper.styles.d.ts +12 -0
- package/dist/styles/SwipeableWrapper.styles.d.ts.map +1 -0
- package/dist/styles/SwipeableWrapper.styles.js +9 -0
- package/dist/styles/SwipeableWrapper.styles.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wissi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# AnySwipe SwipeDeck
|
|
2
|
+
|
|
3
|
+
A headless, four-direction swipe deck library for React Native.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install anyswipe-swipedeck
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer dependencies
|
|
12
|
+
|
|
13
|
+
You must already have these installed in your app:
|
|
14
|
+
|
|
15
|
+
- `react`
|
|
16
|
+
- `react-native`
|
|
17
|
+
- `react-native-gesture-handler`
|
|
18
|
+
- `react-native-reanimated`
|
|
19
|
+
- `react-native-worklets`
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
See the project root README for the full API reference, demo app instructions, and examples.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SwipeDeckRef } from "./types";
|
|
3
|
+
interface SwipeDeckProps<T extends object> {
|
|
4
|
+
ItemComponent: React.ComponentType<T>;
|
|
5
|
+
onSwipeLeft?: (item: T) => void;
|
|
6
|
+
onSwipeRight?: (item: T) => void;
|
|
7
|
+
onSwipeUp?: (item: T) => void;
|
|
8
|
+
onSwipeDown?: (item: T) => void;
|
|
9
|
+
onRemainingChange?: (count: number) => void;
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const SwipeDeck: <T extends object>(props: SwipeDeckProps<T> & {
|
|
13
|
+
ref?: React.ForwardedRef<SwipeDeckRef<T>>;
|
|
14
|
+
}) => React.ReactElement;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=SwipeDeck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeDeck.d.ts","sourceRoot":"","sources":["../SwipeDeck.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAK/D,OAAO,EAAiB,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtD,UAAU,cAAc,CAAC,CAAC,SAAS,MAAM;IACvC,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACtC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAChC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA8DD,eAAO,MAAM,SAAS,EAAiC,CAAC,CAAC,SAAS,MAAM,EACtE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;CAAE,KACrE,KAAK,CAAC,YAAY,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useImperativeHandle } from "react";
|
|
3
|
+
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
4
|
+
import { SwipeableWrapper } from "./SwipeableWrapper";
|
|
5
|
+
import { useSwipeState } from "./hooks/useSwipeState";
|
|
6
|
+
import { styles } from "./styles/SwipeDeck.styles";
|
|
7
|
+
const SwipeDeckInner = ({ ItemComponent, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onRemainingChange, debug = false }, ref) => {
|
|
8
|
+
const { swipeablesArray, swipeablesToRender, topSwipeableId, appendData, setStatusAndRelaySwipe, setSwipeableStatusToDoneAnimating, setSwipeableStatusToIdle, undoFromHistory, } = useSwipeState({ onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onRemainingChange, debug });
|
|
9
|
+
useImperativeHandle(ref, () => ({
|
|
10
|
+
swipeLeft: () => {
|
|
11
|
+
const top = swipeablesArray.find((s) => s.status === "idle");
|
|
12
|
+
if (top)
|
|
13
|
+
setStatusAndRelaySwipe(top, "left");
|
|
14
|
+
},
|
|
15
|
+
swipeRight: () => {
|
|
16
|
+
const top = swipeablesArray.find((s) => s.status === "idle");
|
|
17
|
+
if (top)
|
|
18
|
+
setStatusAndRelaySwipe(top, "right");
|
|
19
|
+
},
|
|
20
|
+
swipeUp: () => {
|
|
21
|
+
const top = swipeablesArray.find((s) => s.status === "idle");
|
|
22
|
+
if (top)
|
|
23
|
+
setStatusAndRelaySwipe(top, "up");
|
|
24
|
+
},
|
|
25
|
+
swipeDown: () => {
|
|
26
|
+
const top = swipeablesArray.find((s) => s.status === "idle");
|
|
27
|
+
if (top)
|
|
28
|
+
setStatusAndRelaySwipe(top, "down");
|
|
29
|
+
},
|
|
30
|
+
undo: undoFromHistory,
|
|
31
|
+
appendData: (items) => appendData(items),
|
|
32
|
+
}));
|
|
33
|
+
return (_jsx(GestureHandlerRootView, { style: styles.deckContainer, children: swipeablesToRender
|
|
34
|
+
.map((swipeable) => (_jsx(SwipeableWrapper, { status: swipeable.status, direction: swipeable.direction, isTopSwipeable: swipeable.id === topSwipeableId, onSwipeLeft: () => setStatusAndRelaySwipe(swipeable, "left"), onSwipeRight: () => setStatusAndRelaySwipe(swipeable, "right"), onSwipeUp: () => setStatusAndRelaySwipe(swipeable, "up"), onSwipeDown: () => setStatusAndRelaySwipe(swipeable, "down"), onAnimationOutComplete: () => setSwipeableStatusToDoneAnimating(swipeable.id), onAnimationInComplete: () => setSwipeableStatusToIdle(swipeable.id), children: _jsx(ItemComponent, { ...swipeable.data }) }, swipeable.id)))
|
|
35
|
+
.reverse() }));
|
|
36
|
+
};
|
|
37
|
+
export const SwipeDeck = forwardRef(SwipeDeckInner);
|
|
38
|
+
//# sourceMappingURL=SwipeDeck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeDeck.js","sourceRoot":"","sources":["../SwipeDeck.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAanD,MAAM,cAAc,GAAG,CACrB,EAAE,aAAa,E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
import { SwipeDirection, SwipeStatus } from './types';
|
|
3
|
+
export interface SwipeableWrapperProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
status?: SwipeStatus;
|
|
6
|
+
direction?: SwipeDirection;
|
|
7
|
+
isTopSwipeable: boolean;
|
|
8
|
+
onSwipeLeft?: () => void;
|
|
9
|
+
onSwipeRight?: () => void;
|
|
10
|
+
onSwipeUp?: () => void;
|
|
11
|
+
onSwipeDown?: () => void;
|
|
12
|
+
onAnimationOutComplete?: () => void;
|
|
13
|
+
onAnimationInComplete?: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const SwipeableWrapper: React.FC<SwipeableWrapperProps>;
|
|
16
|
+
//# sourceMappingURL=SwipeableWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.d.ts","sourceRoot":"","sources":["../SwipeableWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAWzC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItD,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;IACpC,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;CACtC;AAKD,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAwK5D,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { Dimensions, View } from 'react-native';
|
|
4
|
+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
5
|
+
import Animated, { Easing, runOnJS, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { styles } from './styles/SwipeableWrapper.styles';
|
|
7
|
+
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
|
|
8
|
+
const SWIPE_THRESHOLD = SCREEN_WIDTH * 0.35;
|
|
9
|
+
const VELOCITY_THRESHOLD = 800;
|
|
10
|
+
export const SwipeableWrapper = ({ children, status = 'idle', direction, isTopSwipeable, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onAnimationOutComplete, onAnimationInComplete }) => {
|
|
11
|
+
// Initialize positions based on status to prevent the (0,0) flash on mount
|
|
12
|
+
const getInitialX = () => {
|
|
13
|
+
if (status !== 'animating-in')
|
|
14
|
+
return 0;
|
|
15
|
+
if (direction === 'left')
|
|
16
|
+
return -SCREEN_WIDTH;
|
|
17
|
+
if (direction === 'right')
|
|
18
|
+
return SCREEN_WIDTH;
|
|
19
|
+
return 0;
|
|
20
|
+
};
|
|
21
|
+
const getInitialY = () => {
|
|
22
|
+
if (status !== 'animating-in')
|
|
23
|
+
return 0;
|
|
24
|
+
if (direction === 'up')
|
|
25
|
+
return -SCREEN_HEIGHT;
|
|
26
|
+
if (direction === 'down')
|
|
27
|
+
return SCREEN_HEIGHT;
|
|
28
|
+
return 0;
|
|
29
|
+
};
|
|
30
|
+
const translateX = useSharedValue(getInitialX());
|
|
31
|
+
const translateY = useSharedValue(getInitialY());
|
|
32
|
+
// Using SharedValues for these allows the UI thread to access the
|
|
33
|
+
// measurements instantly for animations without waiting for React re-renders.
|
|
34
|
+
const swipeableWidth = useSharedValue(0);
|
|
35
|
+
const swipeableHeight = useSharedValue(0);
|
|
36
|
+
// Store velocities onEnd for use in the animation effect
|
|
37
|
+
const velocityX = useSharedValue(0);
|
|
38
|
+
const velocityY = useSharedValue(0);
|
|
39
|
+
const gesture = Gesture.Pan()
|
|
40
|
+
.enabled(isTopSwipeable)
|
|
41
|
+
.onUpdate((event) => {
|
|
42
|
+
translateX.value = event.translationX;
|
|
43
|
+
translateY.value = event.translationY;
|
|
44
|
+
})
|
|
45
|
+
.onEnd((event) => {
|
|
46
|
+
velocityX.value = event.velocityX;
|
|
47
|
+
velocityY.value = event.velocityY;
|
|
48
|
+
const shouldSwipeRight = translateX.value > SWIPE_THRESHOLD || (event.velocityX > VELOCITY_THRESHOLD && translateX.value > 0);
|
|
49
|
+
const shouldSwipeLeft = translateX.value < -SWIPE_THRESHOLD || (event.velocityX < -VELOCITY_THRESHOLD && translateX.value < 0);
|
|
50
|
+
const shouldSwipeUp = translateY.value < -SWIPE_THRESHOLD || (event.velocityY < -VELOCITY_THRESHOLD && translateY.value < 0);
|
|
51
|
+
const shouldSwipeDown = translateY.value > SWIPE_THRESHOLD || (event.velocityY > VELOCITY_THRESHOLD && translateY.value > 0);
|
|
52
|
+
const absX = Math.abs(translateX.value);
|
|
53
|
+
const absY = Math.abs(translateY.value);
|
|
54
|
+
const isHorizontalDominant = absX > absY;
|
|
55
|
+
if (isHorizontalDominant && shouldSwipeRight) {
|
|
56
|
+
if (onSwipeRight)
|
|
57
|
+
runOnJS(onSwipeRight)();
|
|
58
|
+
}
|
|
59
|
+
else if (isHorizontalDominant && shouldSwipeLeft) {
|
|
60
|
+
if (onSwipeLeft)
|
|
61
|
+
runOnJS(onSwipeLeft)();
|
|
62
|
+
}
|
|
63
|
+
else if (!isHorizontalDominant && shouldSwipeUp) {
|
|
64
|
+
if (onSwipeUp)
|
|
65
|
+
runOnJS(onSwipeUp)();
|
|
66
|
+
}
|
|
67
|
+
else if (!isHorizontalDominant && shouldSwipeDown) {
|
|
68
|
+
if (onSwipeDown)
|
|
69
|
+
runOnJS(onSwipeDown)();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
translateX.value = withTiming(0, { duration: 300 });
|
|
73
|
+
translateY.value = withTiming(0, { duration: 300 });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// ----------------------------- SWIPE ANIMATION -----------------------------
|
|
77
|
+
const calculateDuration = (target, translate, velocity) => {
|
|
78
|
+
let duration = 300;
|
|
79
|
+
const absDistance = Math.abs(target - translate);
|
|
80
|
+
const absVelocity = Math.abs(velocity);
|
|
81
|
+
if (absVelocity > 50) {
|
|
82
|
+
duration = Math.min(300, Math.max(100, (absDistance / absVelocity) * 1000));
|
|
83
|
+
}
|
|
84
|
+
return duration;
|
|
85
|
+
};
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
// Calculate exact exit/start targets based on measured size
|
|
88
|
+
// Fallback to constants if onLayout hasn't fired yet (common on mount)
|
|
89
|
+
const currentWidth = swipeableWidth.value || SCREEN_WIDTH;
|
|
90
|
+
const currentHeight = swipeableHeight.value || SCREEN_HEIGHT;
|
|
91
|
+
const horizontalExit = (SCREEN_WIDTH / 2) + (currentWidth / 2) + 100;
|
|
92
|
+
const verticalExit = (SCREEN_HEIGHT / 2) + (currentHeight / 2) + 100;
|
|
93
|
+
if (status === 'animating-out') {
|
|
94
|
+
let targetX;
|
|
95
|
+
let targetY;
|
|
96
|
+
switch (direction) {
|
|
97
|
+
case 'left':
|
|
98
|
+
targetX = -horizontalExit;
|
|
99
|
+
targetY = 0;
|
|
100
|
+
break;
|
|
101
|
+
case 'right':
|
|
102
|
+
targetX = horizontalExit;
|
|
103
|
+
targetY = 0;
|
|
104
|
+
break;
|
|
105
|
+
case 'up':
|
|
106
|
+
targetX = 0;
|
|
107
|
+
targetY = -verticalExit;
|
|
108
|
+
break;
|
|
109
|
+
case 'down':
|
|
110
|
+
targetX = 0;
|
|
111
|
+
targetY = verticalExit;
|
|
112
|
+
break;
|
|
113
|
+
default: throw new Error(`Swipeable: direction must be provided when animating. Current: ${direction}`);
|
|
114
|
+
}
|
|
115
|
+
let duration = 300;
|
|
116
|
+
if (direction === 'left' || direction === 'right') {
|
|
117
|
+
duration = calculateDuration(targetX, translateX.value, velocityX.value);
|
|
118
|
+
translateY.value = withTiming(targetY, { duration, easing: Easing.in(Easing.quad) });
|
|
119
|
+
translateX.value = withTiming(targetX, { duration, easing: Easing.in(Easing.quad) }, (finished) => {
|
|
120
|
+
if (finished && onAnimationOutComplete) {
|
|
121
|
+
runOnJS(onAnimationOutComplete)();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else if (direction === 'up' || direction === 'down') {
|
|
126
|
+
duration = calculateDuration(targetY, translateY.value, velocityY.value);
|
|
127
|
+
translateX.value = withTiming(targetX, { duration, easing: Easing.in(Easing.quad) });
|
|
128
|
+
translateY.value = withTiming(targetY, { duration, easing: Easing.in(Easing.quad) }, (finished) => {
|
|
129
|
+
if (finished && onAnimationOutComplete) {
|
|
130
|
+
runOnJS(onAnimationOutComplete)();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (status === 'animating-in') {
|
|
136
|
+
// Animate back to center
|
|
137
|
+
translateX.value = withTiming(0, { duration: 300, easing: Easing.out(Easing.quad) });
|
|
138
|
+
translateY.value = withTiming(0, { duration: 300, easing: Easing.out(Easing.quad) }, (finished) => {
|
|
139
|
+
if (finished && onAnimationInComplete) {
|
|
140
|
+
runOnJS(onAnimationInComplete)();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else if (status === 'idle') {
|
|
145
|
+
translateX.value = withTiming(0, { duration: 300 });
|
|
146
|
+
translateY.value = withTiming(0, { duration: 300 });
|
|
147
|
+
}
|
|
148
|
+
}, [status, direction, onAnimationOutComplete, onAnimationInComplete]);
|
|
149
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
150
|
+
transform: [
|
|
151
|
+
{ translateX: translateX.value },
|
|
152
|
+
{ translateY: translateY.value },
|
|
153
|
+
{ rotate: `${translateX.value / 25}deg` },
|
|
154
|
+
],
|
|
155
|
+
}));
|
|
156
|
+
return (_jsx(View, { pointerEvents: (status === 'animating-out' || status === 'animating-in') ? 'none' : 'auto', style: styles.container, children: _jsx(GestureDetector, { gesture: gesture, children: _jsx(Animated.View, { style: animatedStyle, onLayout: (event) => {
|
|
157
|
+
swipeableWidth.value = event.nativeEvent.layout.width;
|
|
158
|
+
swipeableHeight.value = event.nativeEvent.layout.height;
|
|
159
|
+
}, children: children }) }) }));
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=SwipeableWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.js","sourceRoot":"","sources":["../SwipeableWrapper.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,QAAQ,EAAE,EACb,MAAM,EACN,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,UAAU,EACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG1D,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAehF,MAAM,eAAe,GAAG,YAAY,GAAG,IAAI,CAAC;AAC5C,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAC9D,QAAQ,EACR,MAAM,GAAG,MAAM,EACf,SAAS,EACT,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACxB,EAAE,EAAE;IACD,2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f,CACV,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SwipeableData, SwipeDeckRef } from '../types';
|
|
2
|
+
export declare const useSwipeDeck: <T extends object>() => {
|
|
3
|
+
deckRef: import("react").RefObject<SwipeDeckRef<T> | null>;
|
|
4
|
+
swipeLeft: () => void | undefined;
|
|
5
|
+
swipeRight: () => void | undefined;
|
|
6
|
+
swipeUp: () => void | undefined;
|
|
7
|
+
swipeDown: () => void | undefined;
|
|
8
|
+
undo: () => void | undefined;
|
|
9
|
+
appendData: (items: SwipeableData<T>[]) => void | undefined;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useSwipeDeck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSwipeDeck.d.ts","sourceRoot":"","sources":["../../hooks/useSwipeDeck.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvD,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM;;;;;;;wBAShB,aAAa,CAAC,CAAC,CAAC,EAAE;CAE9C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
export const useSwipeDeck = () => {
|
|
3
|
+
const ref = useRef(null);
|
|
4
|
+
return {
|
|
5
|
+
deckRef: ref,
|
|
6
|
+
swipeLeft: () => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.swipeLeft(); },
|
|
7
|
+
swipeRight: () => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.swipeRight(); },
|
|
8
|
+
swipeUp: () => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.swipeUp(); },
|
|
9
|
+
swipeDown: () => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.swipeDown(); },
|
|
10
|
+
undo: () => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.undo(); },
|
|
11
|
+
appendData: (items) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.appendData(items); },
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useSwipeDeck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSwipeDeck.js","sourceRoot":"","sources":["../../hooks/useSwipeDeck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAqB,EAAE;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;IAC1C,OAAO;QACH,OAAO,EAAE,GAAG;QACZ,SAAS,EAAI,GAAG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,SAAS,EAAE,CAAA,EAAA;QAC3C,UAAU,EAAG,GAAG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,UAAU,EAAE,CAAA,EAAA;QAC5C,OAAO,EAAM,GAAG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAA,EAAA;QACzC,SAAS,EAAI,GAAG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,SAAS,EAAE,CAAA,EAAA;QAC3C,IAAI,EAAS,GAAG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,IAAI,EAAE,CAAA,EAAA;QACtC,UAAU,EAAG,CAAC,KAAyB,EAAE,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,UAAU,CAAC,KAAK,CAAC,CAAA,EAAA;KAC7E,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SwipeableData, SwipeDirection } from "../types";
|
|
2
|
+
interface SwipeStateCallbacks<T> {
|
|
3
|
+
onSwipeLeft?: (item: T) => void;
|
|
4
|
+
onSwipeRight?: (item: T) => void;
|
|
5
|
+
onSwipeUp?: (item: T) => void;
|
|
6
|
+
onSwipeDown?: (item: T) => void;
|
|
7
|
+
onRemainingChange?: (count: number) => void;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const useSwipeState: <T extends object>(callbacks: SwipeStateCallbacks<T>) => {
|
|
11
|
+
swipeablesArray: SwipeableData<T>[];
|
|
12
|
+
swipeablesToRender: SwipeableData<T>[];
|
|
13
|
+
topSwipeableId: number | undefined;
|
|
14
|
+
appendData: (items: SwipeableData<T>[]) => void;
|
|
15
|
+
setStatusAndRelaySwipe: (swipeable: SwipeableData<T>, direction: SwipeDirection) => void;
|
|
16
|
+
setSwipeableStatusToDoneAnimating: (id: number) => void;
|
|
17
|
+
setSwipeableStatusToIdle: (id: number) => void;
|
|
18
|
+
undoFromHistory: () => void;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=useSwipeState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSwipeState.d.ts","sourceRoot":"","sources":["../../hooks/useSwipeState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEzD,UAAU,mBAAmB,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAChC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,EAAE,WAAW,mBAAmB,CAAC,CAAC,CAAC;;;;wBA6BpD,aAAa,CAAC,CAAC,CAAC,EAAE;wCAsBF,aAAa,CAAC,CAAC,CAAC,aAAa,cAAc;4CA4BvC,MAAM;mCAIf,MAAM;;CAyC7C,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
export const useSwipeState = (callbacks) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const { onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onRemainingChange, debug = false } = callbacks;
|
|
5
|
+
const log = (...args) => {
|
|
6
|
+
if (debug)
|
|
7
|
+
console.log(...args);
|
|
8
|
+
};
|
|
9
|
+
const warn = (...args) => {
|
|
10
|
+
if (debug)
|
|
11
|
+
console.warn(...args);
|
|
12
|
+
};
|
|
13
|
+
const [swipeablesArray, setSwipeablesArray] = useState([]);
|
|
14
|
+
const swipedStackRef = useRef([]);
|
|
15
|
+
const idleCount = swipeablesArray.filter((s) => s.status === "idle").length;
|
|
16
|
+
// Load more trigger, always fires on first mount (causes fetching of initial batch)
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
onRemainingChange === null || onRemainingChange === void 0 ? void 0 : onRemainingChange(idleCount);
|
|
19
|
+
}, [idleCount]);
|
|
20
|
+
const deckLog = swipeablesArray
|
|
21
|
+
.map((s) => {
|
|
22
|
+
const statusLabel = s.status === "animating-out" ? "OUT" : s.status === "animating-in" ? "IN" : "idle";
|
|
23
|
+
return `#${s.id}(${statusLabel})`;
|
|
24
|
+
})
|
|
25
|
+
.join(" ");
|
|
26
|
+
log("SWIPEABLE_ARRAY:", `[ ${deckLog} ]`);
|
|
27
|
+
const appendData = (items) => {
|
|
28
|
+
setSwipeablesArray((prev) => [...prev, ...items]);
|
|
29
|
+
};
|
|
30
|
+
const setSwipeableStatusToAnimatingOut = (id, direction) => {
|
|
31
|
+
setSwipeablesArray((prev) => prev.map((s) => (s.id === id ? { ...s, status: "animating-out", direction } : s)));
|
|
32
|
+
log(`ARRAY_UPDATE: Card ${id} set to animating-out`);
|
|
33
|
+
};
|
|
34
|
+
const setLastAnimatingOutStatusToAnimatingIn = () => {
|
|
35
|
+
setSwipeablesArray((prev) => {
|
|
36
|
+
const lastAnimatingOut = prev.findLast((s) => s.status === "animating-out");
|
|
37
|
+
if (lastAnimatingOut) {
|
|
38
|
+
return prev.map((s) => (s.id === lastAnimatingOut.id ? { ...s, status: "animating-in" } : s));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
warn(`ARRAY_UPDATE: No animating-out card found`);
|
|
42
|
+
return prev;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
log(`ARRAY_UPDATE: Last animating-out card set to animating-in`);
|
|
46
|
+
};
|
|
47
|
+
const setStatusAndRelaySwipe = (swipeable, direction) => {
|
|
48
|
+
switch (direction) {
|
|
49
|
+
case "left":
|
|
50
|
+
onSwipeLeft === null || onSwipeLeft === void 0 ? void 0 : onSwipeLeft(swipeable.data);
|
|
51
|
+
break;
|
|
52
|
+
case "right":
|
|
53
|
+
onSwipeRight === null || onSwipeRight === void 0 ? void 0 : onSwipeRight(swipeable.data);
|
|
54
|
+
break;
|
|
55
|
+
case "up":
|
|
56
|
+
onSwipeUp === null || onSwipeUp === void 0 ? void 0 : onSwipeUp(swipeable.data);
|
|
57
|
+
break;
|
|
58
|
+
case "down":
|
|
59
|
+
onSwipeDown === null || onSwipeDown === void 0 ? void 0 : onSwipeDown(swipeable.data);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
setSwipeableStatusToAnimatingOut(swipeable.id, direction);
|
|
63
|
+
};
|
|
64
|
+
// When a card finishes animating out, we consider it "removed" and push it to the swiped history stack.
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (swipeablesArray.length > 0 && swipeablesArray[0].status === "done-animating") {
|
|
67
|
+
const topCard = swipeablesArray[0];
|
|
68
|
+
log(`GATEKEEPER: Card ${topCard.id} released to history.`);
|
|
69
|
+
swipedStackRef.current.push(topCard);
|
|
70
|
+
setSwipeablesArray((prev) => prev.slice(1));
|
|
71
|
+
}
|
|
72
|
+
}, [swipeablesArray]);
|
|
73
|
+
const setSwipeableStatusToDoneAnimating = (id) => {
|
|
74
|
+
setSwipeablesArray((prev) => prev.map((s) => (s.id === id ? { ...s, status: "done-animating" } : s)));
|
|
75
|
+
};
|
|
76
|
+
const setSwipeableStatusToIdle = (id) => {
|
|
77
|
+
setSwipeablesArray((prev) => prev.map((s) => (s.id === id ? { ...s, status: "idle" } : s)));
|
|
78
|
+
log(`SET_IDLE: Card ${id} reset to idle`);
|
|
79
|
+
};
|
|
80
|
+
const undoFromHistory = () => {
|
|
81
|
+
if (swipeablesArray.some((s) => s.status === "animating-out")) {
|
|
82
|
+
setLastAnimatingOutStatusToAnimatingIn();
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const item = swipedStackRef.current.pop();
|
|
86
|
+
if (item) {
|
|
87
|
+
setSwipeablesArray((prev) => [{ ...item, status: "animating-in" }, ...prev]);
|
|
88
|
+
log(`UNDO: Item restored from history`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
warn(`UNDO: No item in history`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
let idleRenderCount = 0;
|
|
96
|
+
const swipeablesToRender = swipeablesArray.filter((s) => {
|
|
97
|
+
if (s.status === "animating-out" || s.status === "animating-in")
|
|
98
|
+
return true;
|
|
99
|
+
if (s.status === "idle" && idleRenderCount < 3) {
|
|
100
|
+
idleRenderCount++;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
});
|
|
105
|
+
const topSwipeableId = (_a = swipeablesArray.find((s) => s.status === "idle")) === null || _a === void 0 ? void 0 : _a.id;
|
|
106
|
+
return {
|
|
107
|
+
swipeablesArray,
|
|
108
|
+
swipeablesToRender,
|
|
109
|
+
topSwipeableId,
|
|
110
|
+
appendData,
|
|
111
|
+
setStatusAndRelaySwipe,
|
|
112
|
+
setSwipeableStatusToDoneAnimating,
|
|
113
|
+
setSwipeableStatusToIdle,
|
|
114
|
+
undoFromHistory,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=useSwipeState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSwipeState.js","sourceRoot":"","sources":["../../hooks/useSwipeState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAYpD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAmB,SAAiC,EAAE,EAAE;;IACnF,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,SAAS,CAAC;IAE1G,MAAM,GAAG,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;QACjC,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;QAClC,IAAI,KAAK;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAqB,EAAE,CAAC,CAAC;IAC/E,MAAM,cAAc,GAAG,MAAM,CAAqB,EAAE,CAAC,CAAC;IAEtD,MAAM,SAAS,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IAE5E,oFAAoF;IACpF,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,aAAjB,iBAAiB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{ SwipeDeck } from './SwipeDeck';
|
|
3
|
+
export { createSwipeableData } from './types';
|
|
4
|
+
export type { SwipeableData, SwipeDeckRef, SwipeDirection, SwipeStatus } from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeDeck.styles.d.ts","sourceRoot":"","sources":["../../styles/SwipeDeck.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;;;;;;CAOjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeDeck.styles.js","sourceRoot":"","sources":["../../styles/SwipeDeck.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,aAAa,EAAE;QACX,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;KAC3B;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.styles.d.ts","sourceRoot":"","sources":["../../styles/SwipeableWrapper.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;;;;;;;;;CAMjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.styles.js","sourceRoot":"","sources":["../../styles/SwipeableWrapper.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,SAAS,EAAE;QACP,GAAG,UAAU,CAAC,kBAAkB;QAChC,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;KAC3B;CACJ,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SwipeDirection = 'left' | 'right' | 'up' | 'down';
|
|
2
|
+
export type SwipeStatus = 'idle' | 'animating-in' | 'animating-out' | 'done-animating';
|
|
3
|
+
export type SwipeableData<T> = {
|
|
4
|
+
id: number;
|
|
5
|
+
status: SwipeStatus;
|
|
6
|
+
direction?: SwipeDirection;
|
|
7
|
+
data: T;
|
|
8
|
+
};
|
|
9
|
+
export interface SwipeDeckRef<T extends object> {
|
|
10
|
+
swipeLeft: () => void;
|
|
11
|
+
swipeRight: () => void;
|
|
12
|
+
swipeUp: () => void;
|
|
13
|
+
swipeDown: () => void;
|
|
14
|
+
undo: () => void;
|
|
15
|
+
appendData: (items: SwipeableData<T>[]) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const createSwipeableData: <T extends object>(data: T) => SwipeableData<T>;
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,cAAc,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAEvF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC;CACX,CAAC;AAEF,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM;IAC1C,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,UAAU,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC;CACnD;AAGD,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC,KAAG,aAAa,CAAC,CAAC,CAE7E,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAoBA,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAmB,IAAO,EAAoB,EAAE,CAAC,CAAC;IACjF,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI;CACtC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "anyswipe-swipedeck",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "A headless, four-direction swipe deck library for React Native.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Wissi",
|
|
8
|
+
"homepage": "https://github.com/Wissi00/AnySwipe-SwipeDeck#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Wissi00/AnySwipe-SwipeDeck.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Wissi00/AnySwipe-SwipeDeck/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react-native",
|
|
18
|
+
"expo",
|
|
19
|
+
"swipe",
|
|
20
|
+
"deck",
|
|
21
|
+
"gesture-handler",
|
|
22
|
+
"reanimated",
|
|
23
|
+
"tinder"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"react-native": "./dist/index.js",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -p tsconfig.build.json",
|
|
46
|
+
"clean": "rm -rf dist",
|
|
47
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"typescript": "~5.9.2"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": "19.1.0",
|
|
54
|
+
"react-native": "0.81.5",
|
|
55
|
+
"react-native-gesture-handler": "~2.28.0",
|
|
56
|
+
"react-native-reanimated": "~4.1.1",
|
|
57
|
+
"react-native-worklets": "0.5.1"
|
|
58
|
+
}
|
|
59
|
+
}
|