Skip to content

Commit 94c766a

Browse files
committed
chore: pull changes from base branch
2 parents 51cd7d5 + f137f01 commit 94c766a

File tree

55 files changed

+2438
-2227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2438
-2227
lines changed

examples/SampleApp/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ const isMessageAIGenerated = (message: LocalMessage) => !!message.ai_generated;
169169
const DrawerNavigatorWrapper: React.FC<{
170170
chatClient: StreamChat;
171171
}> = ({ chatClient }) => {
172-
const { bottom } = useSafeAreaInsets();
173172
const streamChatTheme = useStreamChatTheme();
174173

175174
chatClient.setMessageComposerSetupFunction(({ composer }) => {
@@ -182,7 +181,7 @@ const DrawerNavigatorWrapper: React.FC<{
182181

183182
return (
184183
<GestureHandlerRootView style={{ flex: 1 }}>
185-
<OverlayProvider bottomInset={bottom} value={{ style: streamChatTheme }}>
184+
<OverlayProvider value={{ style: streamChatTheme }}>
186185
<Chat
187186
client={chatClient}
188187
enableOfflineSupport

examples/SampleApp/src/components/ScreenHeader.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import { StyleProp, StyleSheet, Text, TouchableOpacity, View, ViewStyle } from 'react-native';
33
import { CompositeNavigationProp, useNavigation } from '@react-navigation/native';
44
import { useSafeAreaInsets } from 'react-native-safe-area-context';
5-
import { useAttachmentPickerContext, useTheme } from 'stream-chat-react-native';
5+
import { useTheme } from 'stream-chat-react-native';
66

77
import { ChannelsUnreadCountBadge } from './UnreadCountBadge';
88

@@ -122,13 +122,6 @@ export const ScreenHeader: React.FC<ScreenHeaderProps> = (props) => {
122122
},
123123
} = useTheme();
124124
const insets = useSafeAreaInsets();
125-
const { setTopInset } = useAttachmentPickerContext();
126-
127-
useEffect(() => {
128-
if (setTopInset) {
129-
setTopInset(HEADER_CONTENT_HEIGHT + insets.top);
130-
}
131-
}, [insets.top, setTopInset]);
132125

133126
return (
134127
<View

examples/SampleApp/src/screens/ThreadScreen.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import { StyleSheet, View } from 'react-native';
33
import { SafeAreaView } from 'react-native-safe-area-context';
4-
import {
5-
Channel,
6-
Thread,
7-
ThreadType,
8-
useAttachmentPickerContext,
9-
useTheme,
10-
useTypingString,
11-
} from 'stream-chat-react-native';
4+
import { Channel, Thread, ThreadType, useTheme, useTypingString } from 'stream-chat-react-native';
125
import { useStateStore } from 'stream-chat-react-native';
136

147
import { ScreenHeader } from '../components/ScreenHeader';
@@ -65,13 +58,6 @@ export const ThreadScreen: React.FC<ThreadScreenProps> = ({
6558
colors: { white },
6659
},
6760
} = useTheme();
68-
const { setSelectedImages } = useAttachmentPickerContext();
69-
70-
useEffect(() => {
71-
setSelectedImages([]);
72-
return () => setSelectedImages([]);
73-
// eslint-disable-next-line react-hooks/exhaustive-deps
74-
}, []);
7561

7662
return (
7763
<SafeAreaView style={[styles.container, { backgroundColor: white }]}>

examples/TypeScriptMessaging/App.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { DarkTheme, DefaultTheme, NavigationContainer, RouteProp } from '@react-navigation/native';
1212
import { createStackNavigator, StackNavigationProp } from '@react-navigation/stack';
1313
import { useHeaderHeight } from '@react-navigation/elements';
14-
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
14+
import { SafeAreaProvider } from 'react-native-safe-area-context';
1515
import { Channel as ChannelType, ChannelSort } from 'stream-chat';
1616
import {
1717
Channel,
@@ -24,7 +24,6 @@ import {
2424
Streami18n,
2525
Thread,
2626
ThreadContextValue,
27-
useAttachmentPickerContext,
2827
useChatContext,
2928
useCreateChatClient,
3029
useOverlayContext,
@@ -108,7 +107,6 @@ const EmptyHeader = () => <></>;
108107
const ChannelScreen: React.FC<ChannelScreenProps> = ({ navigation }) => {
109108
const { channel, setThread } = useContext(AppContext);
110109
const headerHeight = useHeaderHeight();
111-
const { setTopInset } = useAttachmentPickerContext();
112110
const { overlay } = useOverlayContext();
113111

114112
useEffect(() => {
@@ -117,10 +115,6 @@ const ChannelScreen: React.FC<ChannelScreenProps> = ({ navigation }) => {
117115
});
118116
}, [overlay, navigation]);
119117

120-
useEffect(() => {
121-
setTopInset(headerHeight);
122-
}, [headerHeight, setTopInset]);
123-
124118
if (channel === undefined) {
125119
return null;
126120
}
@@ -261,7 +255,6 @@ const NavigatorModule = () => {
261255
};
262256

263257
const App = () => {
264-
const { bottom } = useSafeAreaInsets();
265258
const theme = useStreamChatTheme();
266259

267260
const chatClient = useCreateChatClient({
@@ -275,7 +268,7 @@ const App = () => {
275268
}
276269

277270
return (
278-
<OverlayProvider bottomInset={bottom} i18nInstance={streami18n} value={{ style: theme }}>
271+
<OverlayProvider i18nInstance={streami18n} value={{ style: theme }}>
279272
<Chat client={chatClient} i18nInstance={streami18n} enableOfflineSupport>
280273
<NavigatorModule />
281274
</Chat>

package/src/components/AttachmentPicker/AttachmentPicker.tsx

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useRef, useState } from 'react';
1+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
import { BackHandler, Keyboard, Platform, StyleSheet } from 'react-native';
33

44
import BottomSheetOriginal from '@gorhom/bottom-sheet';
@@ -11,10 +11,8 @@ import type { AttachmentPickerErrorProps } from './components/AttachmentPickerEr
1111

1212
import { renderAttachmentPickerItem } from './components/AttachmentPickerItem';
1313

14-
import {
15-
AttachmentPickerContextValue,
16-
useAttachmentPickerContext,
17-
} from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
14+
import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
15+
import { MessageInputContextValue } from '../../contexts/messageInputContext/MessageInputContext';
1816
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1917
import { useScreenDimensions } from '../../hooks/useScreenDimensions';
2018
import { NativeHandlers } from '../../native';
@@ -31,7 +29,7 @@ const styles = StyleSheet.create({
3129
});
3230

3331
export type AttachmentPickerProps = Pick<
34-
AttachmentPickerContextValue,
32+
MessageInputContextValue,
3533
| 'AttachmentPickerBottomSheetHandle'
3634
| 'attachmentPickerBottomSheetHandleHeight'
3735
| 'attachmentSelectionBarHeight'
@@ -40,23 +38,27 @@ export type AttachmentPickerProps = Pick<
4038
/**
4139
* Custom UI component to render error component while opening attachment picker.
4240
*
43-
* **Default** [AttachmentPickerError](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/AttachmentPickerError.tsx)
41+
* **Default**
42+
* [AttachmentPickerError](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/AttachmentPickerError.tsx)
4443
*/
4544
AttachmentPickerError: React.ComponentType<AttachmentPickerErrorProps>;
4645
/**
4746
* Custom UI component to render error image for attachment picker
4847
*
49-
* **Default** [AttachmentPickerErrorImage](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/AttachmentPickerErrorImage.tsx)
48+
* **Default**
49+
* [AttachmentPickerErrorImage](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/AttachmentPickerErrorImage.tsx)
5050
*/
5151
AttachmentPickerErrorImage: React.ComponentType;
5252
/**
5353
* Custom UI Component to render select more photos for selected gallery access in iOS.
5454
*/
5555
AttachmentPickerIOSSelectMorePhotos: React.ComponentType;
5656
/**
57-
* Custom UI component to render overlay component, that shows up on top of [selected image](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png) (with tick mark)
57+
* Custom UI component to render overlay component, that shows up on top of [selected
58+
* image](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png) (with tick mark)
5859
*
59-
* **Default** [ImageOverlaySelectedComponent](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/ImageOverlaySelectedComponent.tsx)
60+
* **Default**
61+
* [ImageOverlaySelectedComponent](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/ImageOverlaySelectedComponent.tsx)
6062
*/
6163
ImageOverlaySelectedComponent: React.ComponentType;
6264
attachmentPickerErrorButtonText?: string;
@@ -87,17 +89,8 @@ export const AttachmentPicker = React.forwardRef(
8789
colors: { white },
8890
},
8991
} = useTheme();
90-
const {
91-
closePicker,
92-
maxNumberOfFiles,
93-
selectedFiles,
94-
selectedImages,
95-
selectedPicker,
96-
setSelectedFiles,
97-
setSelectedImages,
98-
setSelectedPicker,
99-
topInset,
100-
} = useAttachmentPickerContext();
92+
const { closePicker, selectedPicker, setSelectedPicker, topInset } =
93+
useAttachmentPickerContext();
10194
const { vh: screenVh } = useScreenDimensions();
10295

10396
const fullScreenHeight = screenVh(100);
@@ -157,7 +150,8 @@ export const AttachmentPicker = React.forwardRef(
157150
if (!NativeHandlers.oniOS14GalleryLibrarySelectionChange) {
158151
return;
159152
}
160-
// ios 14 library selection change event is fired when user reselects the images that are permitted to be readable by the app
153+
// ios 14 library selection change event is fired when user reselects the images that are permitted to be
154+
// readable by the app
161155
const { unsubscribe } = NativeHandlers.oniOS14GalleryLibrarySelectionChange(() => {
162156
// we reset the cursor and has next page to true to facilitate fetching of the first page of photos again
163157
hasNextPageRef.current = true;
@@ -182,8 +176,7 @@ export const AttachmentPicker = React.forwardRef(
182176
const backHandler = BackHandler.addEventListener('hardwareBackPress', backAction);
183177

184178
return () => backHandler.remove();
185-
// eslint-disable-next-line react-hooks/exhaustive-deps
186-
}, [selectedPicker, closePicker]);
179+
}, [selectedPicker, closePicker, setSelectedPicker]);
187180

188181
useEffect(() => {
189182
const onKeyboardOpenHandler = () => {
@@ -207,8 +200,7 @@ export const AttachmentPicker = React.forwardRef(
207200
Keyboard.removeListener(keyboardShowEvent, onKeyboardOpenHandler);
208201
}
209202
};
210-
// eslint-disable-next-line react-hooks/exhaustive-deps
211-
}, [closePicker, selectedPicker]);
203+
}, [closePicker, selectedPicker, setSelectedPicker]);
212204

213205
useEffect(() => {
214206
if (currentIndex < 0) {
@@ -232,25 +224,21 @@ export const AttachmentPicker = React.forwardRef(
232224
!loadingPhotos
233225
) {
234226
getMorePhotos();
235-
// we do this only once on open for avoiding to request permissions in rationale dialog again and again on Android
227+
// we do this only once on open for avoiding to request permissions in rationale dialog again and again on
228+
// Android
236229
attemptedToLoadPhotosOnOpenRef.current = true;
237230
}
238231
}, [currentIndex, selectedPicker, getMorePhotos, loadingPhotos]);
239232

240-
const selectedPhotos = photos.map((asset) => ({
241-
asset,
242-
ImageOverlaySelectedComponent,
243-
maxNumberOfFiles,
244-
numberOfAttachmentPickerImageColumns,
245-
numberOfUploads: selectedFiles.length + selectedImages.length,
246-
selected:
247-
selectedImages.some((image) => (image?.uri ? image.uri === asset.uri : false)) ||
248-
selectedFiles.some((file) => (file?.uri ? file.uri === asset.uri : false)),
249-
selectedFiles,
250-
selectedImages,
251-
setSelectedFiles,
252-
setSelectedImages,
253-
}));
233+
const selectedPhotos = useMemo(
234+
() =>
235+
photos.map((asset) => ({
236+
asset,
237+
ImageOverlaySelectedComponent,
238+
numberOfAttachmentPickerImageColumns,
239+
})),
240+
[photos, ImageOverlaySelectedComponent, numberOfAttachmentPickerImageColumns],
241+
);
254242

255243
const handleHeight = attachmentPickerBottomSheetHandleHeight;
256244

@@ -301,6 +289,7 @@ export const AttachmentPicker = React.forwardRef(
301289
numColumns={numberOfAttachmentPickerImageColumns ?? 3}
302290
onEndReached={photoError ? undefined : getMorePhotos}
303291
renderItem={renderAttachmentPickerItem}
292+
testID={'attachment-picker-list'}
304293
/>
305294
</BottomSheet>
306295
{selectedPicker === 'images' && photoError && (

0 commit comments

Comments
 (0)