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

@@ -7,10 +7,12 @@ import {
useContext,
useState,
useCallback,
useEffect,
} from 'react';
import { cn } from '@/lib/utils';
import { usePlatform } from '@/platform';
import { useBackButton } from '@/platform';
import { useTelegramSDK } from '@/hooks/useTelegramSDK';
import {
backdrop,
backdropTransition,
@@ -138,10 +140,26 @@ export const SheetContent = forwardRef<HTMLDivElement, SheetContentProps>(
const { open, onClose } = useContext(SheetContext);
const { haptic } = usePlatform();
const dragControls = useDragControls();
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
// Back button integration
useBackButton(open ? onClose : null);
// Disable Telegram vertical swipes when sheet is open (prevents conflict with drag gestures)
useEffect(() => {
if (!isTelegramWebApp) return;
if (open) {
disableVerticalSwipes();
}
return () => {
if (open) {
enableVerticalSwipes();
}
};
}, [open, isTelegramWebApp, disableVerticalSwipes, enableVerticalSwipes]);
const handleDragEnd = useCallback(
(_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
const velocity = info.velocity.y;

View File

@@ -2,6 +2,7 @@ import { useEffect, useRef, useCallback, useState, type ReactNode } from 'react'
import { createPortal } from 'react-dom';
import { useBackButton } from '@/platform';
import { useHaptic } from '@/platform';
import { useTelegramSDK } from '@/hooks/useTelegramSDK';
export interface SheetProps {
isOpen: boolean;
@@ -104,10 +105,26 @@ export function Sheet({
const [isVisible, setIsVisible] = useState(false);
const haptic = useHaptic();
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
// BackButton integration
useBackButton(isOpen ? onClose : null);
// Disable Telegram vertical swipes when sheet is open (prevents conflict with drag gestures)
useEffect(() => {
if (!isTelegramWebApp) return;
if (isOpen) {
disableVerticalSwipes();
}
return () => {
if (isOpen) {
enableVerticalSwipes();
}
};
}, [isOpen, isTelegramWebApp, disableVerticalSwipes, enableVerticalSwipes]);
// Calculate current height based on snap point
const currentHeight = `${snapPoints[currentSnapIndex] * 100}vh`;