Skip to content

Commit cae4458

Browse files
committed
fix: add typescript messaging app custom code
1 parent d732e33 commit cae4458

File tree

1 file changed

+65
-3
lines changed
  • examples/TypeScriptMessaging

1 file changed

+65
-3
lines changed

examples/TypeScriptMessaging/App.tsx

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
import React, { useContext, useEffect, useMemo, useState } from 'react';
2-
import { I18nManager, LogBox, Platform, SafeAreaView, useColorScheme, View } from 'react-native';
2+
import {
3+
I18nManager,
4+
LogBox,
5+
Platform,
6+
Pressable,
7+
SafeAreaView,
8+
StyleSheet,
9+
useColorScheme,
10+
View,
11+
} from 'react-native';
312
import { DarkTheme, DefaultTheme, NavigationContainer, RouteProp } from '@react-navigation/native';
413
import { createStackNavigator, StackNavigationProp } from '@react-navigation/stack';
514
import { useHeaderHeight } from '@react-navigation/elements';
615
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
716
import { Channel as ChannelType, ChannelSort } from 'stream-chat';
817
import {
18+
Archieve,
919
Channel,
1020
ChannelList,
21+
ChannelPreviewStatus,
22+
ChannelPreviewStatusProps,
1123
Chat,
1224
MessageInput,
1325
MessageList,
1426
OverlayProvider,
27+
Pin,
1528
Streami18n,
1629
Thread,
1730
ThreadContextValue,
31+
Unpin,
1832
useAttachmentPickerContext,
33+
useChannelMembershipState,
1934
useCreateChatClient,
2035
useOverlayContext,
2136
} from 'stream-chat-react-native';
@@ -73,7 +88,7 @@ const filters = {
7388
};
7489

7590
const sort: ChannelSort<StreamChatGenerics> = [
76-
{ pinned_at: 1 },
91+
{ pinned_at: -1 },
7792
{ last_message_at: -1 },
7893
{ updated_at: -1 },
7994
];
@@ -90,6 +105,51 @@ type ChannelListScreenProps = {
90105
navigation: StackNavigationProp<NavigationParamsList, 'ChannelList'>;
91106
};
92107

108+
const CustomChannelPreviewStatus = (props: ChannelPreviewStatusProps) => {
109+
const { channel } = props;
110+
const membership = useChannelMembershipState(channel);
111+
112+
return (
113+
<View style={styles.statusContainer}>
114+
<ChannelPreviewStatus {...props} />
115+
<Pressable
116+
style={styles.iconContainer}
117+
onPress={async () => {
118+
if (membership.pinned_at) {
119+
await channel.unpin();
120+
} else {
121+
await channel.pin();
122+
}
123+
}}
124+
>
125+
{membership.pinned_at ? <Unpin height={24} width={24} pathFill='red' /> : <Pin size={24} />}
126+
</Pressable>
127+
<Pressable
128+
style={styles.iconContainer}
129+
onPress={async () => {
130+
if (membership.archived_at) {
131+
await channel.unarchive();
132+
} else {
133+
await channel.archive();
134+
}
135+
}}
136+
>
137+
<Archieve height={24} width={24} fill={membership.archived_at ? 'red' : 'grey'} />
138+
</Pressable>
139+
</View>
140+
);
141+
};
142+
143+
const styles = StyleSheet.create({
144+
statusContainer: {
145+
flexDirection: 'row',
146+
alignItems: 'center',
147+
},
148+
iconContainer: {
149+
marginLeft: 8,
150+
},
151+
});
152+
93153
const ChannelListScreen: React.FC<ChannelListScreenProps> = ({ navigation }) => {
94154
const { setChannel } = useContext(AppContext);
95155

@@ -98,7 +158,9 @@ const ChannelListScreen: React.FC<ChannelListScreenProps> = ({ navigation }) =>
98158
return (
99159
<View style={{ height: '100%' }}>
100160
<ChannelList<StreamChatGenerics>
161+
PreviewStatus={CustomChannelPreviewStatus}
101162
filters={memoizedFilters}
163+
lockChannelOrder
102164
onSelect={(channel) => {
103165
setChannel(channel);
104166
navigation.navigate('Channel');
@@ -241,7 +303,7 @@ const App = () => {
241303
i18nInstance={streami18n}
242304
value={{ style: theme }}
243305
>
244-
<Chat client={chatClient} i18nInstance={streami18n} enableOfflineSupport>
306+
<Chat client={chatClient} i18nInstance={streami18n}>
245307
<Stack.Navigator
246308
initialRouteName='ChannelList'
247309
screenOptions={{

0 commit comments

Comments
 (0)