Mobile Search: Fix jumping scroll on mobile

This commit is contained in:
Alexander Zinchuk 2022-02-02 22:48:51 +01:00
parent 2e135c997b
commit 8ed75455de
2 changed files with 6 additions and 6 deletions

View File

@ -12,8 +12,8 @@ import useLang from '../../../hooks/useLang';
import { renderMessageSummary } from '../../common/helpers/renderMessageText'; import { renderMessageSummary } from '../../common/helpers/renderMessageText';
import InfiniteScroll from '../../ui/InfiniteScroll'; import InfiniteScroll from '../../ui/InfiniteScroll';
import ChatMessage from './ChatMessage';
import NothingFound from '../../common/NothingFound'; import NothingFound from '../../common/NothingFound';
import ChatMessage from './ChatMessage';
import DateSuggest from './DateSuggest'; import DateSuggest from './DateSuggest';
export type OwnProps = { export type OwnProps = {

View File

@ -79,13 +79,13 @@ const MobileSearchFooter: FC<StateProps> = ({
// Focus message // Focus message
useEffect(() => { useEffect(() => {
if (chat && foundIds && foundIds.length) { if (chat?.id && foundIds?.length) {
focusMessage({ chatId: chat.id, messageId: foundIds[foundIds.length - 1] }); focusMessage({ chatId: chat.id, messageId: foundIds[0] });
setFocusedIndex(0); setFocusedIndex(0);
} else { } else {
setFocusedIndex(-1); setFocusedIndex(-1);
} }
}, [chat, focusMessage, foundIds]); }, [chat?.id, focusMessage, foundIds]);
// Disable native up/down buttons on iOS // Disable native up/down buttons on iOS
useEffect(() => { useEffect(() => {
@ -121,7 +121,7 @@ const MobileSearchFooter: FC<StateProps> = ({
const handleUp = useCallback(() => { const handleUp = useCallback(() => {
if (chat && foundIds) { if (chat && foundIds) {
const newFocusIndex = focusedIndex + 1; const newFocusIndex = focusedIndex + 1;
focusMessage({ chatId: chat.id, messageId: foundIds[foundIds.length - 1 - newFocusIndex] }); focusMessage({ chatId: chat.id, messageId: foundIds[newFocusIndex] });
setFocusedIndex(newFocusIndex); setFocusedIndex(newFocusIndex);
} }
}, [chat, focusedIndex, focusMessage, foundIds]); }, [chat, focusedIndex, focusMessage, foundIds]);
@ -129,7 +129,7 @@ const MobileSearchFooter: FC<StateProps> = ({
const handleDown = useCallback(() => { const handleDown = useCallback(() => {
if (chat && foundIds) { if (chat && foundIds) {
const newFocusIndex = focusedIndex - 1; const newFocusIndex = focusedIndex - 1;
focusMessage({ chatId: chat.id, messageId: foundIds[foundIds.length - 1 - newFocusIndex] }); focusMessage({ chatId: chat.id, messageId: foundIds[newFocusIndex] });
setFocusedIndex(newFocusIndex); setFocusedIndex(newFocusIndex);
} }
}, [chat, focusedIndex, focusMessage, foundIds]); }, [chat, focusedIndex, focusMessage, foundIds]);