From 5622d1b25d7bb4161de52cc387019014f79dce99 Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Thu, 9 Dec 2021 16:43:27 -0300 Subject: [PATCH] typing the listRef as a flatList and removing the `.getNode()` --- app/views/RoomView/List/List.tsx | 1 + app/views/RoomView/List/index.tsx | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/RoomView/List/List.tsx b/app/views/RoomView/List/List.tsx index c470eb806..6b1e9f367 100644 --- a/app/views/RoomView/List/List.tsx +++ b/app/views/RoomView/List/List.tsx @@ -19,6 +19,7 @@ const styles = StyleSheet.create({ interface IRoomListProps extends FlatListProps { listRef: React.Ref; + // listRef: React.MutableRefObject>; } const List = ({ listRef, ...props }: IRoomListProps): JSX.Element => ( diff --git a/app/views/RoomView/List/index.tsx b/app/views/RoomView/List/index.tsx index 0f2299b15..698b8d539 100644 --- a/app/views/RoomView/List/index.tsx +++ b/app/views/RoomView/List/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { RefreshControl } from 'react-native'; +import { FlatList, RefreshControl } from 'react-native'; import { Q } from '@nozbe/watermelondb'; import moment from 'moment'; import { dequal } from 'dequal'; @@ -42,7 +42,7 @@ interface IRoomListContainerProps { tmid?: string; theme: string; loading: boolean; - listRef: any; + listRef: React.RefObject; hideSystemMessages: any[]; tunread: []; ignored: []; @@ -273,7 +273,7 @@ class ListContainer extends React.Component { handleScrollToIndexFailed = (params: { highestMeasuredFrameIndex: number }) => { const { listRef } = this.props; - listRef.current.getNode().scrollToIndex({ index: params.highestMeasuredFrameIndex, animated: false }); + listRef.current?.scrollToIndex({ index: params.highestMeasuredFrameIndex, animated: false }); }; jumpToMessage = (messageId: string): Promise => @@ -283,7 +283,7 @@ class ListContainer extends React.Component { const { listRef } = this.props; const index = messages.findIndex((item: { id: string }) => item.id === messageId); if (index > -1) { - listRef.current.getNode().scrollToIndex({ index, viewPosition: 0.5, viewOffset: 100 }); + listRef.current?.scrollToIndex({ index, viewPosition: 0.5, viewOffset: 100 }); await new Promise(res => setTimeout(res, 300)); if (!this.viewableItems.map((vi: { key: string }) => vi.key).includes(messageId)) { if (!this.jumping) { @@ -299,7 +299,7 @@ class ListContainer extends React.Component { }, 10000); await setTimeout(() => resolve(), 300); } else { - listRef.current.getNode().scrollToIndex({ index: messages.length - 1, animated: false }); + listRef.current?.scrollToIndex({ index: messages.length - 1, animated: false }); if (!this.jumping) { return resolve(); } @@ -314,7 +314,7 @@ class ListContainer extends React.Component { jumpToBottom = () => { const { listRef } = this.props; - listRef.current.getNode().scrollToOffset({ offset: -100 }); + listRef.current?.scrollToOffset({ offset: -100 }); }; renderFooter = () => {