Skip to content

fix: add missing ref typing on BidirectionalFlatList and add that to … #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions example/src/MessageListExample.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { useEffect, useState } from 'react';
import { SafeAreaView, StyleSheet, Text, View } from 'react-native';
import React, { useEffect, useRef, useState } from 'react';
import {
SafeAreaView,
StyleSheet,
Text,
View,
FlatList as FlatListType,
} from 'react-native';

import { FlatList } from 'react-native-bidirectional-infinite-scroll';
import { MessageBubble } from './MessageBubble';
import { Message, queryMoreMessages } from './utils';

const App = () => {
const [messages, setMessages] = useState<Array<Message>>([]);
const listRef = useRef<FlatListType>(null);

useEffect(() => {
const initChat = async () => {
const initialMessages = await queryMoreMessages(50);
Expand Down Expand Up @@ -42,6 +50,7 @@ const App = () => {
<Text style={styles.headerTitle}>Chat between two users</Text>
</View>
<FlatList
ref={listRef}
data={messages}
inverted
onEndReached={loadMoreOlderMessages}
Expand Down
4 changes: 4 additions & 0 deletions src/BidirectionalFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export type Props<T> = Omit<
ListHeaderComponent?: React.ComponentType;
/** Custom UI component for footer indicator of FlatList. Only used when `showDefaultLoadingIndicators` is false */
ListFooterComponent?: React.ComponentType;
ref?:
| ((instance: FlatListType<T> | null) => void)
| MutableRefObject<FlatListType<T> | null>
| null;
};
/**
* Note:
Expand Down