mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 10:27:49 +00:00
fix: disable Telegram swipe-to-close globally to prevent accidental app closures
This commit is contained in:
@@ -7,12 +7,10 @@ import {
|
|||||||
useContext,
|
useContext,
|
||||||
useState,
|
useState,
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { usePlatform } from '@/platform';
|
import { usePlatform } from '@/platform';
|
||||||
import { useBackButton } from '@/platform';
|
import { useBackButton } from '@/platform';
|
||||||
import { useTelegramSDK } from '@/hooks/useTelegramSDK';
|
|
||||||
import {
|
import {
|
||||||
backdrop,
|
backdrop,
|
||||||
backdropTransition,
|
backdropTransition,
|
||||||
@@ -140,26 +138,9 @@ export const SheetContent = forwardRef<HTMLDivElement, SheetContentProps>(
|
|||||||
const { open, onClose } = useContext(SheetContext);
|
const { open, onClose } = useContext(SheetContext);
|
||||||
const { haptic } = usePlatform();
|
const { haptic } = usePlatform();
|
||||||
const dragControls = useDragControls();
|
const dragControls = useDragControls();
|
||||||
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
|
|
||||||
|
|
||||||
// Back button integration
|
// Back button integration
|
||||||
useBackButton(open ? onClose : null);
|
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(
|
const handleDragEnd = useCallback(
|
||||||
(_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
|
(_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
|
||||||
const velocity = info.velocity.y;
|
const velocity = info.velocity.y;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { useEffect, useRef, useCallback, useState, type ReactNode } from 'react'
|
|||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { useBackButton } from '@/platform';
|
import { useBackButton } from '@/platform';
|
||||||
import { useHaptic } from '@/platform';
|
import { useHaptic } from '@/platform';
|
||||||
import { useTelegramSDK } from '@/hooks/useTelegramSDK';
|
|
||||||
|
|
||||||
export interface SheetProps {
|
export interface SheetProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -105,26 +104,10 @@ export function Sheet({
|
|||||||
const [isVisible, setIsVisible] = useState(false);
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
|
||||||
const haptic = useHaptic();
|
const haptic = useHaptic();
|
||||||
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
|
|
||||||
|
|
||||||
// BackButton integration
|
// BackButton integration
|
||||||
useBackButton(isOpen ? onClose : null);
|
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
|
// Calculate current height based on snap point
|
||||||
const currentHeight = `${snapPoints[currentSnapIndex] * 100}vh`;
|
const currentHeight = `${snapPoints[currentSnapIndex] * 100}vh`;
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,25 @@
|
|||||||
import { useCallback, useRef } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useTelegramSDK } from './useTelegramSDK';
|
import { useTelegramSDK } from './useTelegramSDK';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to manage Telegram vertical swipes during drag-and-drop operations.
|
* Hook for drag-and-drop operations in Telegram Mini App.
|
||||||
* Disables Telegram's swipe-to-close gesture while dragging to prevent conflicts.
|
* Note: Vertical swipes are now globally disabled at app init,
|
||||||
*
|
* so this hook just provides no-op callbacks for compatibility.
|
||||||
* 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() {
|
export function useTelegramDnd() {
|
||||||
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
|
const { isTelegramWebApp } = useTelegramSDK();
|
||||||
const isDraggingRef = useRef(false);
|
|
||||||
|
|
||||||
const onDragStart = useCallback(() => {
|
const onDragStart = useCallback(() => {
|
||||||
if (isTelegramWebApp && !isDraggingRef.current) {
|
// No-op: swipes are globally disabled
|
||||||
isDraggingRef.current = true;
|
}, []);
|
||||||
disableVerticalSwipes();
|
|
||||||
}
|
|
||||||
}, [isTelegramWebApp, disableVerticalSwipes]);
|
|
||||||
|
|
||||||
const onDragEnd = useCallback(() => {
|
const onDragEnd = useCallback(() => {
|
||||||
if (isTelegramWebApp && isDraggingRef.current) {
|
// No-op: swipes are globally disabled
|
||||||
isDraggingRef.current = false;
|
}, []);
|
||||||
enableVerticalSwipes();
|
|
||||||
}
|
|
||||||
}, [isTelegramWebApp, enableVerticalSwipes]);
|
|
||||||
|
|
||||||
const onDragCancel = useCallback(() => {
|
const onDragCancel = useCallback(() => {
|
||||||
if (isTelegramWebApp && isDraggingRef.current) {
|
// No-op: swipes are globally disabled
|
||||||
isDraggingRef.current = false;
|
}, []);
|
||||||
enableVerticalSwipes();
|
|
||||||
}
|
|
||||||
}, [isTelegramWebApp, enableVerticalSwipes]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onDragStart,
|
onDragStart,
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ export function initTelegramSDK() {
|
|||||||
// Disable closing confirmation by default
|
// Disable closing confirmation by default
|
||||||
tg.disableClosingConfirmation?.();
|
tg.disableClosingConfirmation?.();
|
||||||
|
|
||||||
|
// Disable vertical swipes to prevent accidental closures
|
||||||
|
tg.disableVerticalSwipes?.();
|
||||||
|
|
||||||
// Auto-enter fullscreen if enabled in settings (mobile only)
|
// Auto-enter fullscreen if enabled in settings (mobile only)
|
||||||
const fullscreenEnabled = getCachedFullscreenEnabled();
|
const fullscreenEnabled = getCachedFullscreenEnabled();
|
||||||
if (fullscreenEnabled && isTelegramMobile() && tg.requestFullscreen) {
|
if (fullscreenEnabled && isTelegramMobile() && tg.requestFullscreen) {
|
||||||
|
|||||||
Reference in New Issue
Block a user