diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 62553d368..bb7fe3e4d 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -755,7 +755,7 @@ class RoomView extends React.Component { if (handleCommandScroll(event)) { const offset = input === 'UIKeyInputUpArrow' ? 100 : -100; this.offset += offset; - this.flatList.scrollToOffset({ offset: this.offset }); + this.flatList?.scrollToOffset({ offset: this.offset }); } else if (handleCommandRoomActions(event)) { this.goRoomActionsView(); } else if (handleCommandSearchMessages(event)) { diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index 5b1d396d3..3fd5c7386 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -504,12 +504,7 @@ class RoomsListView extends React.Component { closeSearchHeader(); } setTimeout(() => { - const offset = isAndroid ? 0 : SCROLL_OFFSET; - if (this.scroll.scrollTo) { - this.scroll.scrollTo({ x: 0, y: offset, animated: true }); - } else if (this.scroll.scrollToOffset) { - this.scroll.scrollToOffset({ offset }); - } + this.scrollToTop(); }, 200); }); }; @@ -538,9 +533,7 @@ class RoomsListView extends React.Component { search: result, searching: true }); - if (this.scroll && this.scroll.scrollTo) { - this.scroll.scrollTo({ x: 0, y: 0, animated: true }); - } + this.scrollToTop(); }, 300); getRoomTitle = item => RocketChat.getRoomTitle(item) @@ -561,15 +554,17 @@ class RoomsListView extends React.Component { this.goRoom({ item, isMasterDetail }); }; + scrollToTop = () => { + const offset = isAndroid ? 0 : SCROLL_OFFSET; + if (this.scroll?.scrollToOffset) { + this.scroll.scrollToOffset({ offset }); + } + } + toggleSort = () => { const { toggleSortDropdown } = this.props; - const offset = isAndroid ? 0 : SCROLL_OFFSET; - if (this.scroll.scrollTo) { - this.scroll.scrollTo({ x: 0, y: offset, animated: true }); - } else if (this.scroll.scrollToOffset) { - this.scroll.scrollToOffset({ offset }); - } + this.scrollToTop(); setTimeout(() => { toggleSortDropdown(); }, 100);