Skip to content

Commit 1461ccc

Browse files
committed
chore: add option to switch between lists
1 parent 0082352 commit 1461ccc

File tree

3 files changed

+76
-14
lines changed

3 files changed

+76
-14
lines changed

examples/SampleApp/src/components/SecretMenu.tsx

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export const SlideInView = ({
3535

3636
const animatedStyle = useAnimatedStyle(
3737
() => ({
38-
height: withSpring(visible ? animatedHeight.value : 0, { damping: 10 }),
38+
height: withSpring(visible ? animatedHeight.value : 0, {
39+
damping: 20,
40+
overshootClamping: true,
41+
}),
3942
opacity: withTiming(visible ? 1 : 0, { duration: 500 }),
4043
}),
4144
[visible],
@@ -55,6 +58,7 @@ export const SlideInView = ({
5558
const isAndroid = Platform.OS === 'android';
5659

5760
type NotificationConfigItem = { label: string; name: string; id: string };
61+
type MessageListImplementationConfigItem = { label: string; id: string };
5862

5963
const SecretMenuNotificationConfigItem = ({
6064
notificationConfigItem,
@@ -120,6 +124,23 @@ const SecretMenuNotificationConfigItem = ({
120124
);
121125
};
122126

127+
const SecretMenuMessageListConfigItem = ({
128+
messageListImplementationConfigItem,
129+
storeMessageListImplementation,
130+
isSelected,
131+
}: {
132+
messageListImplementationConfigItem: MessageListImplementationConfigItem;
133+
storeMessageListImplementation: (item: MessageListImplementationConfigItem) => void;
134+
isSelected: boolean;
135+
}) => (
136+
<TouchableOpacity
137+
style={[styles.notificationItemContainer, { borderColor: isSelected ? 'green' : 'gray' }]}
138+
onPress={() => storeMessageListImplementation(messageListImplementationConfigItem)}
139+
>
140+
<Text style={styles.notificationItem}>{messageListImplementationConfigItem.label}</Text>
141+
</TouchableOpacity>
142+
);
143+
123144
export const SecretMenu = ({
124145
close,
125146
visible,
@@ -130,6 +151,9 @@ export const SecretMenu = ({
130151
chatClient: StreamChat;
131152
}) => {
132153
const [selectedProvider, setSelectedProvider] = useState<string | null>(null);
154+
const [selectedMessageListImplementation, setSelectedMessageListImplementation] = useState<
155+
string | null
156+
>(null);
133157
const {
134158
theme: {
135159
colors: { black, grey },
@@ -144,22 +168,43 @@ export const SecretMenu = ({
144168
[],
145169
);
146170

171+
const messageListImplementationConfigItems = useMemo(
172+
() => [
173+
{ label: 'FlashList', id: 'flashlist' },
174+
{ label: 'FlatList', id: 'flatlist' },
175+
],
176+
[],
177+
);
178+
147179
useEffect(() => {
148-
const getSelectedProvider = async () => {
149-
const provider = await AsyncStore.getItem(
180+
const getSelectedConfig = async () => {
181+
const notificationProvider = await AsyncStore.getItem(
150182
'@stream-rn-sampleapp-push-provider',
151183
notificationConfigItems[0],
152184
);
153-
setSelectedProvider(provider?.id ?? 'firebase');
185+
const messageListImplementation = await AsyncStore.getItem(
186+
'@stream-rn-sampleapp-messagelist-implementation',
187+
messageListImplementationConfigItems[0],
188+
);
189+
setSelectedProvider(notificationProvider?.id ?? 'firebase');
190+
setSelectedMessageListImplementation(messageListImplementation?.id ?? 'flashlist');
154191
};
155-
getSelectedProvider();
156-
}, [notificationConfigItems]);
192+
getSelectedConfig();
193+
}, [notificationConfigItems, messageListImplementationConfigItems]);
157194

158195
const storeProvider = useCallback(async (item: NotificationConfigItem) => {
159196
await AsyncStore.setItem('@stream-rn-sampleapp-push-provider', item);
160197
setSelectedProvider(item.id);
161198
}, []);
162199

200+
const storeMessageListImplementation = useCallback(
201+
async (item: MessageListImplementationConfigItem) => {
202+
await AsyncStore.setItem('@stream-rn-sampleapp-messagelist-implementation', item);
203+
setSelectedMessageListImplementation(item.id);
204+
},
205+
[],
206+
);
207+
163208
const removeAllDevices = useCallback(async () => {
164209
const { devices } = await chatClient.getDevices(chatClient.userID);
165210
for (const device of devices ?? []) {
@@ -169,12 +214,7 @@ export const SecretMenu = ({
169214

170215
return (
171216
<SlideInView visible={visible}>
172-
<View
173-
style={[
174-
menuDrawerStyles.menuItem,
175-
{ alignItems: 'flex-start' },
176-
]}
177-
>
217+
<View style={[menuDrawerStyles.menuItem, { alignItems: 'flex-start' }]}>
178218
<Notification height={24} pathFill={grey} width={24} />
179219
<View>
180220
<Text
@@ -200,6 +240,22 @@ export const SecretMenu = ({
200240
</View>
201241
</View>
202242
</View>
243+
<View style={[menuDrawerStyles.menuItem, { alignItems: 'flex-start' }]}>
244+
<Notification height={24} pathFill={grey} width={24} />
245+
<View>
246+
<Text style={[menuDrawerStyles.menuTitle]}>Message List implementation</Text>
247+
<View style={{ marginLeft: 16 }}>
248+
{messageListImplementationConfigItems.map((item) => (
249+
<SecretMenuMessageListConfigItem
250+
key={item.id}
251+
messageListImplementationConfigItem={item}
252+
storeMessageListImplementation={storeMessageListImplementation}
253+
isSelected={item.id === selectedMessageListImplementation}
254+
/>
255+
))}
256+
</View>
257+
</View>
258+
</View>
203259
<TouchableOpacity onPress={removeAllDevices} style={menuDrawerStyles.menuItem}>
204260
<Delete height={24} size={24} pathFill={grey} width={24} />
205261
<Text

examples/SampleApp/src/context/AppContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type AppContextType = {
99
loginUser: (config: LoginConfig) => void;
1010
logout: () => void;
1111
switchUser: (userId?: string) => void;
12+
messageListImplementation: 'flatlist' | 'flashlist';
1213
};
1314

1415
export const AppContext = React.createContext({} as AppContextType);

examples/SampleApp/src/screens/ChannelScreen.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { channelMessageActions } from '../utils/messageActions.tsx';
3232
import { MessageLocation } from '../components/LocationSharing/MessageLocation.tsx';
3333
import { useStreamChatContext } from '../context/StreamChatContext.tsx';
3434
import { CustomAttachmentPickerSelectionBar } from '../components/AttachmentPickerSelectionBar.tsx';
35+
import { MessageList } from 'stream-chat-react-native-core';
3536

3637
export type ChannelScreenNavigationProp = StackNavigationProp<
3738
StackNavigatorParamList,
@@ -118,7 +119,7 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
118119
params: { channel: channelFromProp, channelId, messageId },
119120
},
120121
}) => {
121-
const { chatClient } = useAppContext();
122+
const { chatClient, messageListImplementation } = useAppContext();
122123
const navigation = useNavigation();
123124
const { bottom } = useSafeAreaInsets();
124125
const {
@@ -216,7 +217,11 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
216217
thread={selectedThread}
217218
>
218219
<ChannelHeader channel={channel} />
219-
<MessageFlashList onThreadSelect={onThreadSelect} />
220+
{messageListImplementation === 'flashlist' ? (
221+
<MessageFlashList onThreadSelect={onThreadSelect} />
222+
) : (
223+
<MessageList onThreadSelect={onThreadSelect} />
224+
)}
220225
<AITypingIndicatorView channel={channel} />
221226
<MessageInput />
222227
</Channel>

0 commit comments

Comments
 (0)