fix: disable Telegram vertical swipes during drag operations

- Add useTelegramDnd hook for @dnd-kit integration
- Update Sheet components to disable swipes when open
- Update AdminPaymentMethods to use the new hook
- Prevents conflict between app drag gestures and Telegram swipe-to-close
This commit is contained in:
c0mrade
2026-02-01 22:46:16 +03:00
parent 0773afdf6e
commit 8deca2fa5b
4 changed files with 132 additions and 13 deletions

View File

@@ -0,0 +1,55 @@
import { useCallback, useRef } from 'react';
import { useTelegramSDK } from './useTelegramSDK';
/**
* Hook to manage Telegram vertical swipes during drag-and-drop operations.
* Disables Telegram's swipe-to-close gesture while dragging to prevent conflicts.
*
* Usage with @dnd-kit:
* ```tsx
* const { onDragStart, onDragEnd } = useTelegramDnd();
*
* <DndContext
* onDragStart={(e) => {
* onDragStart();
* // your drag start logic
* }}
* onDragEnd={(e) => {
* onDragEnd();
* // your drag end logic
* }}
* >
* ```
*/
export function useTelegramDnd() {
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
const isDraggingRef = useRef(false);
const onDragStart = useCallback(() => {
if (isTelegramWebApp && !isDraggingRef.current) {
isDraggingRef.current = true;
disableVerticalSwipes();
}
}, [isTelegramWebApp, disableVerticalSwipes]);
const onDragEnd = useCallback(() => {
if (isTelegramWebApp && isDraggingRef.current) {
isDraggingRef.current = false;
enableVerticalSwipes();
}
}, [isTelegramWebApp, enableVerticalSwipes]);
const onDragCancel = useCallback(() => {
if (isTelegramWebApp && isDraggingRef.current) {
isDraggingRef.current = false;
enableVerticalSwipes();
}
}, [isTelegramWebApp, enableVerticalSwipes]);
return {
onDragStart,
onDragEnd,
onDragCancel,
isTelegramWebApp,
};
}