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 InfiniteScroll from '../../ui/InfiniteScroll';
import ChatMessage from './ChatMessage';
import NothingFound from '../../common/NothingFound';
import ChatMessage from './ChatMessage';
import DateSuggest from './DateSuggest';
export type OwnProps = {

View File

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