Skip to content

Commit e09b9fc

Browse files
Allowing custom NetworkDownIndicator on messagelist
1 parent 799790c commit e09b9fc

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

src/components/MessageList/MessageList.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
ThreadContextValue,
4343
useThreadContext,
4444
} from '../../contexts/threadContext/ThreadContext';
45-
import { useTranslationContext } from '../../contexts/translationContext/TranslationContext';
4645
import { styled } from '../../styles/styledComponents';
4746

4847
import type { UserResponse } from 'stream-chat';
@@ -61,20 +60,7 @@ import type {
6160
UnknownType,
6261
} from '../../types/types';
6362

64-
const ErrorNotification = styled.View`
65-
align-items: center;
66-
background-color: #fae6e8;
67-
color: red;
68-
padding: 5px;
69-
z-index: 10;
70-
${({ theme }) => theme.messageList.errorNotification.css}
71-
`;
72-
73-
const ErrorNotificationText = styled.Text`
74-
background-color: #fae6e8;
75-
color: red;
76-
${({ theme }) => theme.messageList.errorNotificationText.css}
77-
`;
63+
import { NetworkDownIndicator as DefaultNetworkDownIndicator } from './NetworkDownIndicator';
7864

7965
const ListContainer = (styled(FlatList)`
8066
flex: 1;
@@ -185,6 +171,12 @@ export type MessageListProps<
185171
MessageSystem?: React.ComponentType<
186172
MessageSystemProps<At, Ch, Co, Ev, Me, Re, Us>
187173
>;
174+
/**
175+
* Custom UI component to render network down indicator
176+
*
177+
* Defaults to and accepts same props as: [NetworkDownIndicator](https://getstream.github.io/stream-chat-react-native/#NetworkDownIndicator)
178+
*/
179+
NetworkDownIndicator?: React.ComponentType;
188180
/** Turn off grouping of messages by user */
189181
noGroupByUser?: boolean;
190182
onListScroll?: ScrollViewProps['onScroll'];
@@ -261,6 +253,7 @@ export const MessageList = <
261253
onThreadSelect,
262254
setFlatListRef,
263255
threadList,
256+
NetworkDownIndicator = DefaultNetworkDownIndicator,
264257
TypingIndicator = DefaultTypingIndicator,
265258
} = props;
266259

@@ -280,7 +273,6 @@ export const MessageList = <
280273
Message: MessageFromContext,
281274
} = useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
282275
const { loadMoreThread } = useThreadContext<At, Ch, Co, Ev, Me, Re, Us>();
283-
const { t } = useTranslationContext();
284276

285277
const messageList = useMessageList<At, Ch, Co, Ev, Me, Re, Us>({
286278
inverted,
@@ -455,13 +447,7 @@ export const MessageList = <
455447
showNotification={newMessagesNotification}
456448
/>
457449
)}
458-
{!isOnline && (
459-
<ErrorNotification testID='error-notification'>
460-
<ErrorNotificationText>
461-
{t('Connection failure, reconnecting now ...')}
462-
</ErrorNotificationText>
463-
</ErrorNotification>
464-
)}
450+
{!isOnline && <NetworkDownIndicator />}
465451
</View>
466452
{
467453
// Mask for edit state
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import { useTranslationContext } from '../../contexts/translationContext/TranslationContext';
3+
import { styled } from '../../styles/styledComponents';
4+
5+
const ErrorNotification = styled.View`
6+
align-items: center;
7+
background-color: #fae6e8;
8+
color: red;
9+
padding: 5px;
10+
z-index: 10;
11+
${({ theme }) => theme.messageList.errorNotification.css}
12+
`;
13+
14+
const ErrorNotificationText = styled.Text`
15+
background-color: #fae6e8;
16+
color: red;
17+
${({ theme }) => theme.messageList.errorNotificationText.css}
18+
`;
19+
20+
export const NetworkDownIndicator = () => {
21+
const { t } = useTranslationContext();
22+
return (
23+
<ErrorNotification testID='error-notification'>
24+
<ErrorNotificationText>
25+
{t('Connection failure, reconnecting now ...')}
26+
</ErrorNotificationText>
27+
</ErrorNotification>
28+
);
29+
};

0 commit comments

Comments
 (0)