mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
fix: disable Telegram swipe-to-close globally to prevent accidental app closures
This commit is contained in:
@@ -1,50 +1,25 @@
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { useCallback } 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
|
||||
* }}
|
||||
* >
|
||||
* ```
|
||||
* Hook for drag-and-drop operations in Telegram Mini App.
|
||||
* Note: Vertical swipes are now globally disabled at app init,
|
||||
* so this hook just provides no-op callbacks for compatibility.
|
||||
*/
|
||||
export function useTelegramDnd() {
|
||||
const { disableVerticalSwipes, enableVerticalSwipes, isTelegramWebApp } = useTelegramSDK();
|
||||
const isDraggingRef = useRef(false);
|
||||
const { isTelegramWebApp } = useTelegramSDK();
|
||||
|
||||
const onDragStart = useCallback(() => {
|
||||
if (isTelegramWebApp && !isDraggingRef.current) {
|
||||
isDraggingRef.current = true;
|
||||
disableVerticalSwipes();
|
||||
}
|
||||
}, [isTelegramWebApp, disableVerticalSwipes]);
|
||||
// No-op: swipes are globally disabled
|
||||
}, []);
|
||||
|
||||
const onDragEnd = useCallback(() => {
|
||||
if (isTelegramWebApp && isDraggingRef.current) {
|
||||
isDraggingRef.current = false;
|
||||
enableVerticalSwipes();
|
||||
}
|
||||
}, [isTelegramWebApp, enableVerticalSwipes]);
|
||||
// No-op: swipes are globally disabled
|
||||
}, []);
|
||||
|
||||
const onDragCancel = useCallback(() => {
|
||||
if (isTelegramWebApp && isDraggingRef.current) {
|
||||
isDraggingRef.current = false;
|
||||
enableVerticalSwipes();
|
||||
}
|
||||
}, [isTelegramWebApp, enableVerticalSwipes]);
|
||||
// No-op: swipes are globally disabled
|
||||
}, []);
|
||||
|
||||
return {
|
||||
onDragStart,
|
||||
|
||||
@@ -67,6 +67,9 @@ export function initTelegramSDK() {
|
||||
// Disable closing confirmation by default
|
||||
tg.disableClosingConfirmation?.();
|
||||
|
||||
// Disable vertical swipes to prevent accidental closures
|
||||
tg.disableVerticalSwipes?.();
|
||||
|
||||
// Auto-enter fullscreen if enabled in settings (mobile only)
|
||||
const fullscreenEnabled = getCachedFullscreenEnabled();
|
||||
if (fullscreenEnabled && isTelegramMobile() && tg.requestFullscreen) {
|
||||
|
||||
Reference in New Issue
Block a user