Skip to content
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