Mobile Search: Fix jumping scroll on mobile
This commit is contained in:
parent
2e135c997b
commit
8ed75455de
@ -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 = {
|
||||
|
||||
@ -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]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user