react-native-swipeable-actions 0.1.7 → 0.1.9-canary.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/README.md +9 -0
- package/android/src/main/java/expo/modules/swipeable/SwipeableModule.kt +7 -0
- package/android/src/main/java/expo/modules/swipeable/SwipeableView.kt +53 -15
- package/build/Swipeable.d.ts +1 -0
- package/build/Swipeable.d.ts.map +1 -1
- package/build/Swipeable.js +20 -0
- package/build/Swipeable.js.map +1 -1
- package/build/Swipeable.types.d.ts +3 -0
- package/build/Swipeable.types.d.ts.map +1 -1
- package/build/SwipeableView.d.ts +1 -0
- package/build/SwipeableView.d.ts.map +1 -1
- package/build/SwipeableView.js.map +1 -1
- package/build/nativeModuleUtils.d.ts +1 -0
- package/build/nativeModuleUtils.d.ts.map +1 -1
- package/build/nativeModuleUtils.js +9 -0
- package/build/nativeModuleUtils.js.map +1 -1
- package/ios/SwipeableModule.swift +10 -0
- package/ios/SwipeableView.swift +32 -11
- package/jestSetup.js +5 -2
- package/package.json +1 -1
- package/src/Swipeable.tsx +22 -1
- package/src/Swipeable.types.ts +3 -0
- package/src/SwipeableView.tsx +1 -0
- package/src/nativeModuleUtils.ts +8 -0
package/README.md
CHANGED
|
@@ -133,6 +133,12 @@ swipeableRef.current?.close(false) // instant
|
|
|
133
133
|
|
|
134
134
|
// Open the row
|
|
135
135
|
swipeableRef.current?.open()
|
|
136
|
+
|
|
137
|
+
// Cancel an in-flight gesture and snap back to closed.
|
|
138
|
+
// Use from `onSwipeStart` to abort a swipe before it can complete —
|
|
139
|
+
// e.g. when the parent screen has unsaved state and wants to show a
|
|
140
|
+
// confirm dialog instead of letting the swipe-to-pop proceed.
|
|
141
|
+
swipeableRef.current?.cancel()
|
|
136
142
|
```
|
|
137
143
|
|
|
138
144
|
## Static Methods
|
|
@@ -152,6 +158,9 @@ Swipeable.close('row-1', false) // instant
|
|
|
152
158
|
// Close all open rows
|
|
153
159
|
Swipeable.closeAll() // animated
|
|
154
160
|
Swipeable.closeAll(false) // instant
|
|
161
|
+
|
|
162
|
+
// Cancel an in-flight gesture on a specific row
|
|
163
|
+
Swipeable.cancel('row-1')
|
|
155
164
|
```
|
|
156
165
|
|
|
157
166
|
## AutoClose Pattern (Swipe-to-Reply)
|
|
@@ -16,6 +16,10 @@ class SwipeableModule : Module() {
|
|
|
16
16
|
SwipeableView.closeByKey(key, animated ?: true)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
Function("cancelByKey") { key: String ->
|
|
20
|
+
SwipeableView.cancelByKey(key)
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
Function("closeAll") { animated: Boolean? ->
|
|
20
24
|
SwipeableView.closeAll(animated ?: true)
|
|
21
25
|
}
|
|
@@ -61,6 +65,9 @@ class SwipeableModule : Module() {
|
|
|
61
65
|
AsyncFunction("open") { view: SwipeableView ->
|
|
62
66
|
view.post { view.open() }
|
|
63
67
|
}
|
|
68
|
+
AsyncFunction("cancel") { view: SwipeableView ->
|
|
69
|
+
view.post { view.cancelGesture() }
|
|
70
|
+
}
|
|
64
71
|
|
|
65
72
|
AsyncFunction("handleGestureStart") { view: SwipeableView ->
|
|
66
73
|
view.handleGestureStart()
|
|
@@ -70,6 +70,12 @@ class SwipeableView(context: Context, appContext: AppContext) : ExpoView(context
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
fun cancelByKey(key: String) {
|
|
74
|
+
getView(key)?.let { view ->
|
|
75
|
+
view.post { view.cancelGesture() }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
/** Close all swipeables. When animated=true, only closes open views. When animated=false, resets all views. */
|
|
74
80
|
fun closeAll(animated: Boolean = true) {
|
|
75
81
|
getAllViews().forEach { view ->
|
|
@@ -129,27 +135,45 @@ class SwipeableView(context: Context, appContext: AppContext) : ExpoView(context
|
|
|
129
135
|
field = value
|
|
130
136
|
|
|
131
137
|
if (!value) {
|
|
132
|
-
|
|
133
|
-
isBlockingChildEvents = false
|
|
134
|
-
isIntercepting = false
|
|
135
|
-
|
|
136
|
-
if (isDragging || isGestureActivated) {
|
|
137
|
-
isDragging = false
|
|
138
|
-
isGestureActivated = false
|
|
139
|
-
gestureStartTranslation = 0f
|
|
140
|
-
cancelGestureTimeout()
|
|
141
|
-
stopProgressUpdates()
|
|
142
|
-
velocityTracker?.recycle()
|
|
143
|
-
velocityTracker = null
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Close if open or mid-translation (instant reset, no animation)
|
|
138
|
+
abortActiveGesture()
|
|
147
139
|
if (isOpen || currentTranslation != 0f) {
|
|
148
140
|
close(animated = false)
|
|
149
141
|
}
|
|
150
142
|
}
|
|
151
143
|
}
|
|
152
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Cancels an in-flight gesture and snaps the view back to closed.
|
|
147
|
+
* Use from `onSwipeStart` to abort a swipe before it can complete.
|
|
148
|
+
* The current touch sequence is suppressed until the next ACTION_DOWN
|
|
149
|
+
* so the user can't reactivate the swipe by continuing the same drag —
|
|
150
|
+
* including the case where cancel is called between ACTION_DOWN and
|
|
151
|
+
* gesture activation (before any horizontal motion is detected).
|
|
152
|
+
*/
|
|
153
|
+
fun cancelGesture() {
|
|
154
|
+
abortActiveGesture()
|
|
155
|
+
isCurrentTouchCancelled = true
|
|
156
|
+
|
|
157
|
+
if (isOpen || currentTranslation != 0f) {
|
|
158
|
+
close(animated = false)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private fun abortActiveGesture() {
|
|
163
|
+
isBlockingChildEvents = false
|
|
164
|
+
isIntercepting = false
|
|
165
|
+
|
|
166
|
+
if (isDragging || isGestureActivated) {
|
|
167
|
+
isDragging = false
|
|
168
|
+
isGestureActivated = false
|
|
169
|
+
gestureStartTranslation = 0f
|
|
170
|
+
cancelGestureTimeout()
|
|
171
|
+
stopProgressUpdates()
|
|
172
|
+
velocityTracker?.recycle()
|
|
173
|
+
velocityTracker = null
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
153
177
|
var dragOffsetFromEdge: Float = 0f
|
|
154
178
|
set(value) { field = maxOf(0f, value) }
|
|
155
179
|
|
|
@@ -233,6 +257,7 @@ class SwipeableView(context: Context, appContext: AppContext) : ExpoView(context
|
|
|
233
257
|
private var dispatchTouchStartX: Float = 0f
|
|
234
258
|
private var dispatchTouchStartY: Float = 0f
|
|
235
259
|
private var isBlockingChildEvents: Boolean = false
|
|
260
|
+
private var isCurrentTouchCancelled: Boolean = false
|
|
236
261
|
|
|
237
262
|
private var contentSpringAnimation: SpringAnimation? = null
|
|
238
263
|
private var actionsSpringAnimation: SpringAnimation? = null
|
|
@@ -419,6 +444,19 @@ class SwipeableView(context: Context, appContext: AppContext) : ExpoView(context
|
|
|
419
444
|
return super.dispatchTouchEvent(event)
|
|
420
445
|
}
|
|
421
446
|
|
|
447
|
+
// After cancelGesture(), swallow the rest of the touch sequence so the user
|
|
448
|
+
// can't reactivate the swipe by continuing to drag the same finger down.
|
|
449
|
+
if (isCurrentTouchCancelled) {
|
|
450
|
+
when (event.actionMasked) {
|
|
451
|
+
MotionEvent.ACTION_DOWN -> isCurrentTouchCancelled = false
|
|
452
|
+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
|
453
|
+
isCurrentTouchCancelled = false
|
|
454
|
+
return true
|
|
455
|
+
}
|
|
456
|
+
else -> return true
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
422
460
|
when (event.actionMasked) {
|
|
423
461
|
MotionEvent.ACTION_DOWN -> {
|
|
424
462
|
dispatchTouchStartX = event.rawX
|
package/build/Swipeable.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare const Swipeable: import("react").ForwardRefExoticComponent<Omit<Swipeabl
|
|
|
3
3
|
type SwipeableWithStatic = typeof Swipeable & {
|
|
4
4
|
open: (recyclingKey: string) => void;
|
|
5
5
|
close: (recyclingKey: string, animated?: boolean) => void;
|
|
6
|
+
cancel: (recyclingKey: string) => void;
|
|
6
7
|
closeAll: (animated?: boolean) => void;
|
|
7
8
|
};
|
|
8
9
|
declare const SwipeableExport: SwipeableWithStatic;
|
package/build/Swipeable.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swipeable.d.ts","sourceRoot":"","sources":["../src/Swipeable.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,gBAAgB,EAChB,cAAc,EAGf,MAAM,mBAAmB,CAAA;AAe1B,QAAA,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"Swipeable.d.ts","sourceRoot":"","sources":["../src/Swipeable.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,gBAAgB,EAChB,cAAc,EAGf,MAAM,mBAAmB,CAAA;AAe1B,QAAA,MAAM,SAAS,0HA6Jb,CAAA;AAgBF,KAAK,mBAAmB,GAAG,OAAO,SAAS,GAAG;IAC5C,IAAI,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACzD,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACvC,CAAA;AAED,QAAA,MAAM,eAAe,EAAgB,mBAAmB,CAAA;AA8BxD,eAAe,eAAe,CAAA"}
|
package/build/Swipeable.js
CHANGED
|
@@ -65,6 +65,19 @@ const Swipeable = (0, react_1.forwardRef)(function Swipeable({ children, actions
|
|
|
65
65
|
else if (__DEV__) {
|
|
66
66
|
console.warn('[Swipeable] open() called without recyclingKey - method has no effect');
|
|
67
67
|
}
|
|
68
|
+
},
|
|
69
|
+
cancel: () => {
|
|
70
|
+
const key = recyclingKeyRef.current;
|
|
71
|
+
if (key) {
|
|
72
|
+
(0, nativeModuleUtils_1.cancelByKey)(key);
|
|
73
|
+
// Native cancelGesture() short-circuits handlePanEnded so onSwipeEnd
|
|
74
|
+
// is never emitted. Reset the JS-side gate so the next gesture fires
|
|
75
|
+
// onSwipeStart to our consumer again.
|
|
76
|
+
swipeStartedRef.current = false;
|
|
77
|
+
}
|
|
78
|
+
else if (__DEV__) {
|
|
79
|
+
console.warn('[Swipeable] cancel() called without recyclingKey - method has no effect');
|
|
80
|
+
}
|
|
68
81
|
}
|
|
69
82
|
}), []);
|
|
70
83
|
const handleSwipeStart = (0, react_1.useCallback)(() => {
|
|
@@ -122,6 +135,13 @@ SwipeableExport.close = (recyclingKey, animated) => {
|
|
|
122
135
|
}
|
|
123
136
|
(0, nativeModuleUtils_1.closeByKey)(recyclingKey, animated);
|
|
124
137
|
};
|
|
138
|
+
SwipeableExport.cancel = (recyclingKey) => {
|
|
139
|
+
if (__DEV__ && (!recyclingKey || typeof recyclingKey !== 'string')) {
|
|
140
|
+
console.warn('[Swipeable.cancel] recyclingKey must be a non-empty string');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
(0, nativeModuleUtils_1.cancelByKey)(recyclingKey);
|
|
144
|
+
};
|
|
125
145
|
SwipeableExport.closeAll = (animated) => {
|
|
126
146
|
(0, nativeModuleUtils_1.closeAll)(animated);
|
|
127
147
|
};
|
package/build/Swipeable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swipeable.js","sourceRoot":"","sources":["../src/Swipeable.tsx"],"names":[],"mappings":";;AAAA,iCAAiG;AACjG,+CAAyD;AACzD,2CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"Swipeable.js","sourceRoot":"","sources":["../src/Swipeable.tsx"],"names":[],"mappings":";;AAAA,iCAAiG;AACjG,+CAAyD;AACzD,2CAA4C;AAC5C,2DAA+F;AAQ/F,yDAAqD;AACrD,mDAA+C;AAE/C,SAAS,qBAAqB,CAAC,GAAgC;IA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ChD,IAAI,OAAO,IAAI,CAAC,CAAC,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE,CAAC;QACnE,OAAO,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAA;QAC1E,OAAM;IACR,CAAC;IACD,IAAA,+BAAW,EAAC,YAAY,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,eAAe,CAAC,QAAQ,GAAG,CAAC,QAAkB,EAAE,EAAE;IAChD,IAAA,4BAAQ,EAAC,QAAQ,CAAC,CAAA;AACpB,CAAC,CAAA;AAED,kBAAe,eAAe,CAAA"}
|
|
@@ -14,6 +14,7 @@ export interface SwipeStateEvent {
|
|
|
14
14
|
export interface NativeSwipeableRef {
|
|
15
15
|
close: (animated?: boolean) => Promise<void>;
|
|
16
16
|
open: () => Promise<void>;
|
|
17
|
+
cancel: () => Promise<void>;
|
|
17
18
|
}
|
|
18
19
|
export interface SwipeableViewProps extends ViewProps {
|
|
19
20
|
actionsWidth: number;
|
|
@@ -57,10 +58,12 @@ export interface SwipeableProps {
|
|
|
57
58
|
export interface SwipeableMethods {
|
|
58
59
|
close: (animated?: boolean) => void;
|
|
59
60
|
open: () => void;
|
|
61
|
+
cancel: () => void;
|
|
60
62
|
}
|
|
61
63
|
export interface SwipeableStatic {
|
|
62
64
|
open: (recyclingKey: string) => void;
|
|
63
65
|
close: (recyclingKey: string, animated?: boolean) => void;
|
|
66
|
+
cancel: (recyclingKey: string) => void;
|
|
64
67
|
closeAll: (animated?: boolean) => void;
|
|
65
68
|
}
|
|
66
69
|
//# sourceMappingURL=Swipeable.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swipeable.types.d.ts","sourceRoot":"","sources":["../src/Swipeable.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAA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AAQ,KAAK,IAAI,CAAA;IACvD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,KAAK,IAAI,CAAA;IAC/C,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACnC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACzD,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACvC"}
|
package/build/SwipeableView.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { NativeSwipeableRef, SwipeableViewProps } from './Swipeable.types';
|
|
|
2
2
|
interface SwipeableNativeModule {
|
|
3
3
|
openByKey: (key: string) => void;
|
|
4
4
|
closeByKey: (key: string, animated?: boolean) => void;
|
|
5
|
+
cancelByKey: (key: string) => void;
|
|
5
6
|
closeAll: (animated?: boolean) => void;
|
|
6
7
|
isOpenByKey: (key: string) => boolean;
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeableView.d.ts","sourceRoot":"","sources":["../src/SwipeableView.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAK/E,UAAU,qBAAqB;IAC7B,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACrD,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CACtC;AAED,eAAO,MAAM,eAAe,uBAA0D,CAAA;AAEtF,eAAO,MAAM,aAAa,mHAIzB,CAAA"}
|
|
1
|
+
{"version":3,"file":"SwipeableView.d.ts","sourceRoot":"","sources":["../src/SwipeableView.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAK/E,UAAU,qBAAqB;IAC7B,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACrD,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CACtC;AAED,eAAO,MAAM,eAAe,uBAA0D,CAAA;AAEtF,eAAO,MAAM,aAAa,mHAIzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeableView.js","sourceRoot":"","sources":["../src/SwipeableView.tsx"],"names":[],"mappings":";;;AAAA,yDAAiF;AACjF,iCAAsE;AAGtE,MAAM,UAAU,GAAG,IAAA,4CAAwB,EAAqB,WAAW,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"SwipeableView.js","sourceRoot":"","sources":["../src/SwipeableView.tsx"],"names":[],"mappings":";;;AAAA,yDAAiF;AACjF,iCAAsE;AAGtE,MAAM,UAAU,GAAG,IAAA,4CAAwB,EAAqB,WAAW,CAAC,CAAA;AAW/D,QAAA,eAAe,GAAG,IAAA,uCAAmB,EAAwB,WAAW,CAAC,CAAA;AAEzE,QAAA,aAAa,GAAG,IAAA,kBAAU,EACrC,SAAS,aAAa,CAAC,KAAK,EAAE,GAAG;IAC/B,OAAO,IAAA,qBAAa,EAAC,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,EAAuC,CAAC,CAAA;AAC1F,CAAC,CACF,CAAA;AAED,qBAAa,CAAC,WAAW,GAAG,eAAe,CAAA"}
|
|
@@ -7,6 +7,7 @@ export type SwipeableErrorHandler = (error: NativeModuleError, operation: string
|
|
|
7
7
|
export declare function setGlobalErrorHandler(handler: SwipeableErrorHandler | undefined): void;
|
|
8
8
|
export declare function openByKey(key: string): void;
|
|
9
9
|
export declare function closeByKey(key: string, animated?: boolean): void;
|
|
10
|
+
export declare function cancelByKey(key: string): void;
|
|
10
11
|
export declare function closeAll(animated?: boolean): void;
|
|
11
12
|
export declare function isOpenByKey(key: string): boolean;
|
|
12
13
|
//# sourceMappingURL=nativeModuleUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeModuleUtils.d.ts","sourceRoot":"","sources":["../src/nativeModuleUtils.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,MAAM,qBAAqB,GAAG,CAClC,KAAK,EAAE,iBAAiB,EACxB,SAAS,EAAE,MAAM,EACjB,GAAG,CAAC,EAAE,MAAM,KACT,IAAI,CAAA;AAIT,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI,CAEtF;AAgBD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM3C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAMhE;AAED,wBAAgB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAMjD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMhD"}
|
|
1
|
+
{"version":3,"file":"nativeModuleUtils.d.ts","sourceRoot":"","sources":["../src/nativeModuleUtils.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,MAAM,qBAAqB,GAAG,CAClC,KAAK,EAAE,iBAAiB,EACxB,SAAS,EAAE,MAAM,EACjB,GAAG,CAAC,EAAE,MAAM,KACT,IAAI,CAAA;AAIT,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI,CAEtF;AAgBD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM3C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAMhE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7C;AAED,wBAAgB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAMjD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMhD"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setGlobalErrorHandler = setGlobalErrorHandler;
|
|
4
4
|
exports.openByKey = openByKey;
|
|
5
5
|
exports.closeByKey = closeByKey;
|
|
6
|
+
exports.cancelByKey = cancelByKey;
|
|
6
7
|
exports.closeAll = closeAll;
|
|
7
8
|
exports.isOpenByKey = isOpenByKey;
|
|
8
9
|
const SwipeableView_1 = require("./SwipeableView");
|
|
@@ -39,6 +40,14 @@ function closeByKey(key, animated) {
|
|
|
39
40
|
handleNativeError(error, 'closeByKey', key);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
function cancelByKey(key) {
|
|
44
|
+
try {
|
|
45
|
+
SwipeableView_1.SwipeableModule.cancelByKey(key);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
handleNativeError(error, 'cancelByKey', key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
42
51
|
function closeAll(animated) {
|
|
43
52
|
try {
|
|
44
53
|
SwipeableView_1.SwipeableModule.closeAll(animated);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeModuleUtils.js","sourceRoot":"","sources":["../src/nativeModuleUtils.ts"],"names":[],"mappings":";;AAgBA,sDAEC;AAgBD,8BAMC;AAED,gCAMC;AAED,4BAMC;AAED,kCAMC;
|
|
1
|
+
{"version":3,"file":"nativeModuleUtils.js","sourceRoot":"","sources":["../src/nativeModuleUtils.ts"],"names":[],"mappings":";;AAgBA,sDAEC;AAgBD,8BAMC;AAED,gCAMC;AAED,kCAMC;AAED,4BAMC;AAED,kCAMC;AAxED,mDAAiD;AAcjD,IAAI,kBAAqD,CAAA;AAEzD,SAAgB,qBAAqB,CAAC,OAA0C;IAC9E,kBAAkB,GAAG,OAAO,CAAA;AAC9B,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc,EAAE,SAAiB,EAAE,GAAY;IACxE,MAAM,WAAW,GAAsB;QACrC,IAAI,EAAE,wBAAwB;QAC9B,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CA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Q,CAAC,QAAQ,CAAC,CAAA;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC;QACH,OAAO,+BAAe,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -13,6 +13,10 @@ public class SwipeableModule: Module {
|
|
|
13
13
|
SwipeableView.closeByKey(key, animated: animated ?? true)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
Function("cancelByKey") { (key: String) in
|
|
17
|
+
SwipeableView.cancelByKey(key)
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
Function("closeAll") { (animated: Bool?) in
|
|
17
21
|
SwipeableView.closeAll(animated: animated ?? true)
|
|
18
22
|
}
|
|
@@ -75,6 +79,12 @@ public class SwipeableModule: Module {
|
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
|
|
82
|
+
AsyncFunction("cancel") { (view: SwipeableView) in
|
|
83
|
+
DispatchQueue.main.async {
|
|
84
|
+
view.cancelGesture()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
78
88
|
// Gesture handling methods (called from JS gesture handler)
|
|
79
89
|
AsyncFunction("handleGestureStart") { (view: SwipeableView) in
|
|
80
90
|
view.handleGestureStart()
|
package/ios/SwipeableView.swift
CHANGED
|
@@ -92,6 +92,12 @@ public class SwipeableView: ExpoView {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
static func cancelByKey(_ key: String) {
|
|
96
|
+
DispatchQueue.main.async {
|
|
97
|
+
getView(for: key)?.cancelGesture()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
/// Close all swipeables. When animated=true, only closes open views. When animated=false, resets all views.
|
|
96
102
|
static func closeAll(animated: Bool = true) {
|
|
97
103
|
let views = getAllViews()
|
|
@@ -159,17 +165,7 @@ public class SwipeableView: ExpoView {
|
|
|
159
165
|
guard gestureEnabled != oldValue else { return }
|
|
160
166
|
|
|
161
167
|
if !gestureEnabled {
|
|
162
|
-
|
|
163
|
-
// panGesture.isEnabled = false triggers .cancelled synchronously,
|
|
164
|
-
// which calls handlePanEnded — clearing isGestureActivated first
|
|
165
|
-
// makes that handler return early via its guard.
|
|
166
|
-
if isGestureActivated || isDragging {
|
|
167
|
-
isGestureActivated = false
|
|
168
|
-
isDragging = false
|
|
169
|
-
gestureStartTranslation = 0
|
|
170
|
-
stopProgressUpdates()
|
|
171
|
-
}
|
|
172
|
-
|
|
168
|
+
abortActiveGesture()
|
|
173
169
|
panGesture.isEnabled = false
|
|
174
170
|
|
|
175
171
|
// Close if open (instant reset, no animation)
|
|
@@ -182,6 +178,31 @@ public class SwipeableView: ExpoView {
|
|
|
182
178
|
}
|
|
183
179
|
}
|
|
184
180
|
|
|
181
|
+
/// Cancels an in-flight pan gesture and snaps the view back to closed.
|
|
182
|
+
/// Use from `onSwipeStart` to abort a swipe before it can complete.
|
|
183
|
+
func cancelGesture() {
|
|
184
|
+
guard isGestureActivated || isDragging || currentTranslation != 0 else { return }
|
|
185
|
+
|
|
186
|
+
abortActiveGesture()
|
|
187
|
+
|
|
188
|
+
// Toggle isEnabled to fire .cancelled synchronously on the recognizer,
|
|
189
|
+
// then re-enable so the next gesture can begin.
|
|
190
|
+
panGesture.isEnabled = false
|
|
191
|
+
panGesture.isEnabled = true
|
|
192
|
+
|
|
193
|
+
if isOpen || currentTranslation != 0 {
|
|
194
|
+
close(animated: false)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private func abortActiveGesture() {
|
|
199
|
+
guard isGestureActivated || isDragging else { return }
|
|
200
|
+
isGestureActivated = false
|
|
201
|
+
isDragging = false
|
|
202
|
+
gestureStartTranslation = 0
|
|
203
|
+
stopProgressUpdates()
|
|
204
|
+
}
|
|
205
|
+
|
|
185
206
|
var dragOffsetFromEdge: CGFloat = 0 {
|
|
186
207
|
didSet { dragOffsetFromEdge = max(0, dragOffsetFromEdge) }
|
|
187
208
|
}
|
package/jestSetup.js
CHANGED
|
@@ -5,7 +5,9 @@ jest.mock('./src/SwipeableView.tsx', () => {
|
|
|
5
5
|
const SwipeableModule = {
|
|
6
6
|
openByKey: jest.fn(),
|
|
7
7
|
closeByKey: jest.fn(),
|
|
8
|
-
|
|
8
|
+
cancelByKey: jest.fn(),
|
|
9
|
+
closeAll: jest.fn(),
|
|
10
|
+
isOpenByKey: jest.fn().mockReturnValue(true)
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
const SwipeableView = React.forwardRef((props, ref) => {
|
|
@@ -18,7 +20,8 @@ jest.mock('./src/SwipeableView.tsx', () => {
|
|
|
18
20
|
|
|
19
21
|
React.useImperativeHandle(ref, () => ({
|
|
20
22
|
close: jest.fn(),
|
|
21
|
-
open: jest.fn()
|
|
23
|
+
open: jest.fn(),
|
|
24
|
+
cancel: jest.fn()
|
|
22
25
|
}), [])
|
|
23
26
|
|
|
24
27
|
React.useEffect(() => {
|
package/package.json
CHANGED
package/src/Swipeable.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react'
|
|
2
2
|
import { Platform, StyleSheet, View } from 'react-native'
|
|
3
3
|
import { SWIPE_DEFAULTS } from './constants'
|
|
4
|
-
import { closeAll, closeByKey, isOpenByKey, openByKey } from './nativeModuleUtils'
|
|
4
|
+
import { cancelByKey, closeAll, closeByKey, isOpenByKey, openByKey } from './nativeModuleUtils'
|
|
5
5
|
import type {
|
|
6
6
|
NativeSwipeableRef,
|
|
7
7
|
SwipeableMethods,
|
|
@@ -97,6 +97,18 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(function Swipeabl
|
|
|
97
97
|
} else if (__DEV__) {
|
|
98
98
|
console.warn('[Swipeable] open() called without recyclingKey - method has no effect')
|
|
99
99
|
}
|
|
100
|
+
},
|
|
101
|
+
cancel: () => {
|
|
102
|
+
const key = recyclingKeyRef.current
|
|
103
|
+
if (key) {
|
|
104
|
+
cancelByKey(key)
|
|
105
|
+
// Native cancelGesture() short-circuits handlePanEnded so onSwipeEnd
|
|
106
|
+
// is never emitted. Reset the JS-side gate so the next gesture fires
|
|
107
|
+
// onSwipeStart to our consumer again.
|
|
108
|
+
swipeStartedRef.current = false
|
|
109
|
+
} else if (__DEV__) {
|
|
110
|
+
console.warn('[Swipeable] cancel() called without recyclingKey - method has no effect')
|
|
111
|
+
}
|
|
100
112
|
}
|
|
101
113
|
}),
|
|
102
114
|
[]
|
|
@@ -187,6 +199,7 @@ Swipeable.displayName = 'Swipeable'
|
|
|
187
199
|
type SwipeableWithStatic = typeof Swipeable & {
|
|
188
200
|
open: (recyclingKey: string) => void
|
|
189
201
|
close: (recyclingKey: string, animated?: boolean) => void
|
|
202
|
+
cancel: (recyclingKey: string) => void
|
|
190
203
|
closeAll: (animated?: boolean) => void
|
|
191
204
|
}
|
|
192
205
|
|
|
@@ -208,6 +221,14 @@ SwipeableExport.close = (recyclingKey: string, animated?: boolean) => {
|
|
|
208
221
|
closeByKey(recyclingKey, animated)
|
|
209
222
|
}
|
|
210
223
|
|
|
224
|
+
SwipeableExport.cancel = (recyclingKey: string) => {
|
|
225
|
+
if (__DEV__ && (!recyclingKey || typeof recyclingKey !== 'string')) {
|
|
226
|
+
console.warn('[Swipeable.cancel] recyclingKey must be a non-empty string')
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
cancelByKey(recyclingKey)
|
|
230
|
+
}
|
|
231
|
+
|
|
211
232
|
SwipeableExport.closeAll = (animated?: boolean) => {
|
|
212
233
|
closeAll(animated)
|
|
213
234
|
}
|
package/src/Swipeable.types.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface SwipeStateEvent {
|
|
|
17
17
|
export interface NativeSwipeableRef {
|
|
18
18
|
close: (animated?: boolean) => Promise<void>
|
|
19
19
|
open: () => Promise<void>
|
|
20
|
+
cancel: () => Promise<void>
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export interface SwipeableViewProps extends ViewProps {
|
|
@@ -63,10 +64,12 @@ export interface SwipeableProps {
|
|
|
63
64
|
export interface SwipeableMethods {
|
|
64
65
|
close: (animated?: boolean) => void
|
|
65
66
|
open: () => void
|
|
67
|
+
cancel: () => void
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
export interface SwipeableStatic {
|
|
69
71
|
open: (recyclingKey: string) => void
|
|
70
72
|
close: (recyclingKey: string, animated?: boolean) => void
|
|
73
|
+
cancel: (recyclingKey: string) => void
|
|
71
74
|
closeAll: (animated?: boolean) => void
|
|
72
75
|
}
|
package/src/SwipeableView.tsx
CHANGED
|
@@ -8,6 +8,7 @@ const NativeView = requireNativeViewManager<SwipeableViewProps>('Swipeable')
|
|
|
8
8
|
interface SwipeableNativeModule {
|
|
9
9
|
openByKey: (key: string) => void
|
|
10
10
|
closeByKey: (key: string, animated?: boolean) => void
|
|
11
|
+
cancelByKey: (key: string) => void
|
|
11
12
|
closeAll: (animated?: boolean) => void
|
|
12
13
|
isOpenByKey: (key: string) => boolean
|
|
13
14
|
}
|
package/src/nativeModuleUtils.ts
CHANGED
|
@@ -48,6 +48,14 @@ export function closeByKey(key: string, animated?: boolean): void {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export function cancelByKey(key: string): void {
|
|
52
|
+
try {
|
|
53
|
+
SwipeableModule.cancelByKey(key)
|
|
54
|
+
} catch (error) {
|
|
55
|
+
handleNativeError(error, 'cancelByKey', key)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
export function closeAll(animated?: boolean): void {
|
|
52
60
|
try {
|
|
53
61
|
SwipeableModule.closeAll(animated)
|