typing the listRef as a flatList and removing the `.getNode()`
This commit is contained in:
parent
2ca5a06c5e
commit
5622d1b25d
|
@ -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 => (
|
||||||
|
|
|
@ -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 = () => {
|
||||||
|
|
Loading…
Reference in New Issue