From f039f69331e76abe16e28e2cad092f57128981c6 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 20 Aug 2021 23:46:54 +0300 Subject: [PATCH] Folder List, Message: Fix conflicts with swipe-to-back gesture on iOS --- src/components/left/main/ChatFolders.tsx | 6 +++++- src/util/captureEvents.ts | 20 +++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/left/main/ChatFolders.tsx b/src/components/left/main/ChatFolders.tsx index d2f6e641..3fcf4dd2 100644 --- a/src/components/left/main/ChatFolders.tsx +++ b/src/components/left/main/ChatFolders.tsx @@ -39,6 +39,7 @@ type StateProps = { activeChatFolder: number; currentUserId?: number; lastSyncTime?: number; + shouldSkipHistoryAnimations?: boolean; }; type DispatchProps = Pick; @@ -56,6 +57,7 @@ const ChatFolders: FC = ({ activeChatFolder, currentUserId, lastSyncTime, + shouldSkipHistoryAnimations, foldersDispatch, onScreenSelect, loadChatFolders, @@ -220,7 +222,7 @@ const ChatFolders: FC = ({ ) : undefined} @@ -242,6 +244,7 @@ export default memo(withGlobal( }, currentUserId, lastSyncTime, + shouldSkipHistoryAnimations, } = global; return { @@ -254,6 +257,7 @@ export default memo(withGlobal( notifyExceptions: selectNotifyExceptions(global), activeChatFolder, currentUserId, + shouldSkipHistoryAnimations, }; }, (setGlobal, actions): DispatchProps => pick(actions, [ diff --git a/src/util/captureEvents.ts b/src/util/captureEvents.ts index f0c42ec1..2614be10 100644 --- a/src/util/captureEvents.ts +++ b/src/util/captureEvents.ts @@ -1,3 +1,5 @@ +import { IS_IOS } from './environment'; + export enum SwipeDirection { Up, Down, @@ -29,8 +31,12 @@ export interface RealTouchEvent extends TouchEvent { pageY?: number; } -type TSwipeAxis = 'x' | 'y' | undefined; +type TSwipeAxis = + 'x' + | 'y' + | undefined; +const IOS_SCREEN_EDGE_THRESHOLD = 20; const MOVED_THRESHOLD = 15; const SWIPE_THRESHOLD = 50; @@ -136,7 +142,15 @@ export function captureEvents(element: HTMLElement, options: CaptureOptions) { } } - function onSwipe(e: Event, dragOffsetX: number, dragOffsetY: number) { + function onSwipe(e: MouseEvent | RealTouchEvent, dragOffsetX: number, dragOffsetY: number) { + // Avoid conflicts with swipe-to-back gestures + if (IS_IOS) { + const x = (e as RealTouchEvent).touches[0].pageX; + if (x <= IOS_SCREEN_EDGE_THRESHOLD || x >= window.innerWidth - IOS_SCREEN_EDGE_THRESHOLD) { + return; + } + } + if (!currentSwipeAxis) { const xAbs = Math.abs(dragOffsetX); const yAbs = Math.abs(dragOffsetY); @@ -170,7 +184,7 @@ export function captureEvents(element: HTMLElement, options: CaptureOptions) { function processSwipe( e: Event, - currentSwipeAxis:TSwipeAxis, + currentSwipeAxis: TSwipeAxis, dragOffsetX: number, dragOffsetY: number, onSwipe: (e: Event, direction: SwipeDirection) => void,