Fix horizontal scroll for Windows (#1995)
This commit is contained in:
parent
c4168aa441
commit
a016223f08
@ -1,6 +1,6 @@
|
|||||||
import type { FC } from '../../../lib/teact/teact';
|
import type { FC } from '../../../lib/teact/teact';
|
||||||
import React, {
|
import React, {
|
||||||
memo, useCallback, useMemo, useState,
|
memo, useCallback, useMemo, useRef, useState,
|
||||||
} from '../../../lib/teact/teact';
|
} from '../../../lib/teact/teact';
|
||||||
import { getActions, getGlobal, withGlobal } from '../../../global';
|
import { getActions, getGlobal, withGlobal } from '../../../global';
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ import { MEMO_EMPTY_ARRAY } from '../../../util/memo';
|
|||||||
import { throttle } from '../../../util/schedulers';
|
import { throttle } from '../../../util/schedulers';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
import { renderMessageSummary } from '../../common/helpers/renderMessageText';
|
import { renderMessageSummary } from '../../common/helpers/renderMessageText';
|
||||||
|
import useHorizontalScroll from '../../../hooks/useHorizontalScroll';
|
||||||
|
|
||||||
import InfiniteScroll from '../../ui/InfiniteScroll';
|
import InfiniteScroll from '../../ui/InfiniteScroll';
|
||||||
import LeftSearchResultChat from './LeftSearchResultChat';
|
import LeftSearchResultChat from './LeftSearchResultChat';
|
||||||
@ -64,6 +65,11 @@ const ChatResults: FC<OwnProps & StateProps> = ({
|
|||||||
openChat, addRecentlyFoundChatId, searchMessagesGlobal, setGlobalSearchChatId,
|
openChat, addRecentlyFoundChatId, searchMessagesGlobal, setGlobalSearchChatId,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-null/no-null
|
||||||
|
const chatSelectionRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useHorizontalScroll(chatSelectionRef.current, undefined, true);
|
||||||
|
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
|
|
||||||
const [shouldShowMoreLocal, setShouldShowMoreLocal] = useState<boolean>(false);
|
const [shouldShowMoreLocal, setShouldShowMoreLocal] = useState<boolean>(false);
|
||||||
@ -206,7 +212,11 @@ const ChatResults: FC<OwnProps & StateProps> = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{Boolean(localResults.length) && (
|
{Boolean(localResults.length) && (
|
||||||
<div className="chat-selection no-selection no-scrollbar" dir={lang.isRtl ? 'rtl' : undefined}>
|
<div
|
||||||
|
className="chat-selection no-selection no-scrollbar"
|
||||||
|
dir={lang.isRtl ? 'rtl' : undefined}
|
||||||
|
ref={chatSelectionRef}
|
||||||
|
>
|
||||||
{localResults.map((id) => (
|
{localResults.map((id) => (
|
||||||
<PickerSelectedItem
|
<PickerSelectedItem
|
||||||
chatOrUserId={id}
|
chatOrUserId={id}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ const TabList: FC<OwnProps> = ({
|
|||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const previousActiveTab = usePrevious(activeTab);
|
const previousActiveTab = usePrevious(activeTab);
|
||||||
|
|
||||||
useHorizontalScroll(containerRef.current);
|
useHorizontalScroll(containerRef.current, undefined, true);
|
||||||
|
|
||||||
// Scroll container to place active tab in the center
|
// Scroll container to place active tab in the center
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from '../lib/teact/teact';
|
import { useEffect } from '../lib/teact/teact';
|
||||||
|
|
||||||
const useHorizontalScroll = (container: HTMLElement | null, isDisabled?: boolean) => {
|
const useHorizontalScroll = (container: HTMLElement | null, isDisabled?: boolean, shouldPreventDefault = false) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!container || isDisabled) {
|
if (!container || isDisabled) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -10,15 +10,16 @@ const useHorizontalScroll = (container: HTMLElement | null, isDisabled?: boolean
|
|||||||
// Ignore horizontal scroll and let it work natively (e.g. on touchpad)
|
// Ignore horizontal scroll and let it work natively (e.g. on touchpad)
|
||||||
if (!e.deltaX) {
|
if (!e.deltaX) {
|
||||||
container!.scrollLeft += e.deltaY / 4;
|
container!.scrollLeft += e.deltaY / 4;
|
||||||
|
if (shouldPreventDefault) e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
container.addEventListener('wheel', handleScroll, { passive: true });
|
container.addEventListener('wheel', handleScroll, { passive: !shouldPreventDefault });
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
container.removeEventListener('wheel', handleScroll);
|
container.removeEventListener('wheel', handleScroll);
|
||||||
};
|
};
|
||||||
}, [container, isDisabled]);
|
}, [container, isDisabled, shouldPreventDefault]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useHorizontalScroll;
|
export default useHorizontalScroll;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user