|
1 | 1 | import React, { useEffect, useMemo, useRef, useState } from 'react'; |
2 | 2 | import { |
3 | | - ActivityIndicator, |
4 | 3 | FlatListProps, |
5 | 4 | FlatList as FlatListType, |
6 | 5 | Platform, |
@@ -64,12 +63,12 @@ import type { |
64 | 63 | DefaultUserType, |
65 | 64 | UnknownType, |
66 | 65 | } from '../../types/types'; |
| 66 | +import { |
| 67 | + InlineLoadingIndicator, |
| 68 | + InlineLoadingIndicatorProps, |
| 69 | +} from './InlineLoadingIndicator'; |
67 | 70 |
|
68 | 71 | const styles = StyleSheet.create({ |
69 | | - activityIndicatorContainer: { |
70 | | - padding: 10, |
71 | | - width: '100%', |
72 | | - }, |
73 | 72 | container: { |
74 | 73 | alignItems: 'center', |
75 | 74 | flex: 1, |
@@ -180,19 +179,23 @@ type MessageListPropsWithContext< |
180 | 179 | FlatListProps<MessageType<At, Ch, Co, Ev, Me, Re, Us>> |
181 | 180 | >; |
182 | 181 | /** |
183 | | - * UI component for footer of message list. By default message list doesn't have any footer. |
| 182 | + * UI component for footer of message list. By default message list will use `InlineLoadingIndicator` |
| 183 | + * as FooterComponent. You have access to prop `loadingMore` on this component, |
| 184 | + * if you want to implement your own inline loading indicator. |
| 185 | + * |
184 | 186 | * This is a [ListHeaderComponent](https://facebook.github.io/react-native/docs/flatlist#listheadercomponent) of FlatList |
185 | 187 | * used in MessageList. Should be used for header by default if inverted is true or defaulted |
186 | | - * |
187 | 188 | */ |
188 | | - FooterComponent?: React.ReactElement; |
| 189 | + FooterComponent?: React.ComponentType<InlineLoadingIndicatorProps>; |
189 | 190 | /** |
190 | | - * UI component for header of message list. By default message list doesn't have any header. |
| 191 | + * UI component for header of message list. By default message list will use `InlineLoadingIndicator` |
| 192 | + * as HeaderComponent. You have access to prop `loadingMore` on this component, |
| 193 | + * if you want to implement your own inline loading indicator. |
| 194 | + * |
191 | 195 | * This is a [ListFooterComponent](https://facebook.github.io/react-native/docs/flatlist#listheadercomponent) of FlatList |
192 | 196 | * used in MessageList. Should be used for header if inverted is false |
193 | | - * |
194 | 197 | */ |
195 | | - HeaderComponent?: React.ReactElement; |
| 198 | + HeaderComponent?: React.ComponentType<InlineLoadingIndicatorProps>; |
196 | 199 | /** Whether or not the FlatList is inverted. Defaults to true */ |
197 | 200 | inverted?: boolean; |
198 | 201 | /** Turn off grouping of messages by user */ |
@@ -256,8 +259,8 @@ const MessageListWithContext = < |
256 | 259 | disableTypingIndicator, |
257 | 260 | EmptyStateIndicator, |
258 | 261 | FlatList, |
259 | | - FooterComponent, |
260 | | - HeaderComponent, |
| 262 | + FooterComponent = InlineLoadingIndicator, |
| 263 | + HeaderComponent = InlineLoadingIndicator, |
261 | 264 | initialScrollToFirstUnreadMessage, |
262 | 265 | InlineUnreadIndicator, |
263 | 266 | inverted = true, |
@@ -297,7 +300,7 @@ const MessageListWithContext = < |
297 | 300 | const { theme } = useTheme(); |
298 | 301 |
|
299 | 302 | const { |
300 | | - colors: { accent_blue, white_snow }, |
| 303 | + colors: { white_snow }, |
301 | 304 | messageList: { container, listContainer }, |
302 | 305 | } = theme; |
303 | 306 |
|
@@ -846,28 +849,15 @@ const MessageListWithContext = < |
846 | 849 | )} |
847 | 850 | </View> |
848 | 851 | } |
849 | | - ListFooterComponent={() => |
850 | | - FooterComponent ? ( |
851 | | - FooterComponent |
852 | | - ) : onEndReachedInProgress ? ( |
853 | | - <View style={[styles.activityIndicatorContainer]}> |
854 | | - <ActivityIndicator color={accent_blue} size='small' /> |
855 | | - </View> |
856 | | - ) : null |
857 | | - } |
858 | | - // TODO: Scrolling doesn't work perfectly with this loading indicator. Investigate and fix. |
859 | | - ListHeaderComponent={() => |
860 | | - HeaderComponent ? ( |
861 | | - HeaderComponent |
862 | | - ) : onStartReachedInProgress ? ( |
863 | | - <View style={[styles.activityIndicatorContainer]}> |
864 | | - <ActivityIndicator color={accent_blue} size='small' /> |
865 | | - </View> |
866 | | - ) : null |
867 | | - } |
| 852 | + ListFooterComponent={() => ( |
| 853 | + <FooterComponent loadingMore={onEndReachedInProgress} /> |
| 854 | + )} |
| 855 | + ListHeaderComponent={() => ( |
| 856 | + <HeaderComponent loadingMore={onStartReachedInProgress} /> |
| 857 | + )} |
868 | 858 | maintainVisibleContentPosition={{ |
869 | 859 | autoscrollToTopThreshold: autoscrollToTop ? 10 : undefined, |
870 | | - minIndexForVisible: 0, |
| 860 | + minIndexForVisible: 1, |
871 | 861 | }} |
872 | 862 | onScroll={handleScroll} |
873 | 863 | onScrollBeginDrag={onScrollBeginDrag} |
|
0 commit comments