typing the listRef as a flatList and removing the `.getNode()`

This commit is contained in:
AlexAlexandre 2021-12-09 16:43:27 -03:00
parent 2ca5a06c5e
commit 5622d1b25d
2 changed files with 7 additions and 6 deletions

View File

@ -19,6 +19,7 @@ const styles = StyleSheet.create({
interface IRoomListProps extends FlatListProps<IRoomItem> { interface IRoomListProps extends FlatListProps<IRoomItem> {
listRef: React.Ref<FlatList>; listRef: React.Ref<FlatList>;
// listRef: React.MutableRefObject<AnimatedComponent<typeof FlatList>>;
} }
const List = ({ listRef, ...props }: IRoomListProps): JSX.Element => ( const List = ({ listRef, ...props }: IRoomListProps): JSX.Element => (

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { RefreshControl } from 'react-native'; import { FlatList, RefreshControl } from 'react-native';
import { Q } from '@nozbe/watermelondb'; import { Q } from '@nozbe/watermelondb';
import moment from 'moment'; import moment from 'moment';
import { dequal } from 'dequal'; import { dequal } from 'dequal';
@ -42,7 +42,7 @@ interface IRoomListContainerProps {
tmid?: string; tmid?: string;
theme: string; theme: string;
loading: boolean; loading: boolean;
listRef: any; listRef: React.RefObject<FlatList>;
hideSystemMessages: any[]; hideSystemMessages: any[];
tunread: []; tunread: [];
ignored: []; ignored: [];
@ -273,7 +273,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
handleScrollToIndexFailed = (params: { highestMeasuredFrameIndex: number }) => { handleScrollToIndexFailed = (params: { highestMeasuredFrameIndex: number }) => {
const { listRef } = this.props; 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<void> => jumpToMessage = (messageId: string): Promise<void> =>
@ -283,7 +283,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
const { listRef } = this.props; const { listRef } = this.props;
const index = messages.findIndex((item: { id: string }) => item.id === messageId); const index = messages.findIndex((item: { id: string }) => item.id === messageId);
if (index > -1) { 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)); await new Promise(res => setTimeout(res, 300));
if (!this.viewableItems.map((vi: { key: string }) => vi.key).includes(messageId)) { if (!this.viewableItems.map((vi: { key: string }) => vi.key).includes(messageId)) {
if (!this.jumping) { if (!this.jumping) {
@ -299,7 +299,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
}, 10000); }, 10000);
await setTimeout(() => resolve(), 300); await setTimeout(() => resolve(), 300);
} else { } else {
listRef.current.getNode().scrollToIndex({ index: messages.length - 1, animated: false }); listRef.current?.scrollToIndex({ index: messages.length - 1, animated: false });
if (!this.jumping) { if (!this.jumping) {
return resolve(); return resolve();
} }
@ -314,7 +314,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
jumpToBottom = () => { jumpToBottom = () => {
const { listRef } = this.props; const { listRef } = this.props;
listRef.current.getNode().scrollToOffset({ offset: -100 }); listRef.current?.scrollToOffset({ offset: -100 });
}; };
renderFooter = () => { renderFooter = () => {