diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index a4a7549f5..0b6afd18f 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -769,7 +769,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 9bf50c088..232ea3228 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -512,12 +512,7 @@ class RoomsListView extends React.Component { this.setHeader(); closeSearchHeader(); setTimeout(() => { - const offset = 0; - 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); }); }; @@ -546,9 +541,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) @@ -569,15 +562,16 @@ class RoomsListView extends React.Component { this.goRoom({ item, isMasterDetail }); }; + scrollToTop = () => { + if (this.scroll?.scrollToOffset) { + this.scroll.scrollToOffset({ offset: 0 }); + } + } + toggleSort = () => { const { toggleSortDropdown } = this.props; - const offset = 0; - 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);