stream-chat-react-native-core 9.9.2-beta.2 → 9.9.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Channel/Channel.js +5 -2
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +7 -2
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Channel/Channel.js +5 -2
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +7 -2
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
- package/lib/typescript/contexts/attachmentPickerContext/AttachmentPickerContext.d.ts +13 -0
- package/lib/typescript/contexts/attachmentPickerContext/AttachmentPickerContext.d.ts.map +1 -1
- package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Channel/Channel.tsx +5 -1
- package/src/components/MessageInput/__tests__/AttachButton.test.tsx +88 -0
- package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +13 -0
- package/src/contexts/messageInputContext/MessageInputContext.tsx +12 -3
- package/src/version.json +1 -1
|
@@ -187,6 +187,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
|
|
|
187
187
|
| 'bottomInset'
|
|
188
188
|
| 'topInset'
|
|
189
189
|
| 'disableAttachmentPicker'
|
|
190
|
+
| 'shouldRenderAttachmentPicker'
|
|
190
191
|
| 'numberOfAttachmentPickerImageColumns'
|
|
191
192
|
| 'numberOfAttachmentImagesToLoadPerCall'
|
|
192
193
|
>
|
|
@@ -389,6 +390,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
|
|
|
389
390
|
const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) => {
|
|
390
391
|
const {
|
|
391
392
|
disableAttachmentPicker = !isImageMediaLibraryAvailable(),
|
|
393
|
+
shouldRenderAttachmentPicker = true,
|
|
392
394
|
additionalKeyboardAvoidingViewProps,
|
|
393
395
|
additionalPressableProps,
|
|
394
396
|
additionalTextInputProps,
|
|
@@ -1571,6 +1573,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
|
|
|
1571
1573
|
closePicker: handleClosePicker,
|
|
1572
1574
|
disableAttachmentPicker,
|
|
1573
1575
|
openPicker: handleOpenPicker,
|
|
1576
|
+
shouldRenderAttachmentPicker,
|
|
1574
1577
|
topInset,
|
|
1575
1578
|
numberOfAttachmentPickerImageColumns,
|
|
1576
1579
|
attachmentPickerBottomSheetHeight,
|
|
@@ -1583,6 +1586,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
|
|
|
1583
1586
|
handleClosePicker,
|
|
1584
1587
|
disableAttachmentPicker,
|
|
1585
1588
|
handleOpenPicker,
|
|
1589
|
+
shouldRenderAttachmentPicker,
|
|
1586
1590
|
topInset,
|
|
1587
1591
|
numberOfAttachmentPickerImageColumns,
|
|
1588
1592
|
attachmentPickerBottomSheetHeight,
|
|
@@ -1805,7 +1809,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
|
|
|
1805
1809
|
<AudioPlayerProvider value={audioPlayerContext}>
|
|
1806
1810
|
<NotificationAnnouncer />
|
|
1807
1811
|
<View style={{ height: '100%' }}>{children}</View>
|
|
1808
|
-
<AttachmentPicker />
|
|
1812
|
+
{shouldRenderAttachmentPicker ? <AttachmentPicker /> : null}
|
|
1809
1813
|
</AudioPlayerProvider>
|
|
1810
1814
|
</MessageInputProvider>
|
|
1811
1815
|
</MessageComposerProvider>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { Text } from 'react-native';
|
|
4
|
+
|
|
3
5
|
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react-native';
|
|
4
6
|
import type { Channel as ChannelType, StreamChat } from 'stream-chat';
|
|
5
7
|
|
|
6
8
|
import { OverlayProvider } from '../../../contexts';
|
|
9
|
+
import { useAttachmentPickerState } from '../../../hooks/useAttachmentPickerState';
|
|
7
10
|
|
|
8
11
|
import { initiateClientWithChannels } from '../../../mock-builders/api/initiateClientWithChannels';
|
|
9
12
|
import * as NativeHandler from '../../../native';
|
|
@@ -12,6 +15,11 @@ import { Channel } from '../../Channel/Channel';
|
|
|
12
15
|
import { Chat } from '../../Chat/Chat';
|
|
13
16
|
import { AttachButton } from '../components/InputButtons/AttachButton';
|
|
14
17
|
|
|
18
|
+
const SelectedPicker = () => {
|
|
19
|
+
const { selectedPicker } = useAttachmentPickerState();
|
|
20
|
+
return <Text testID='selected-picker'>{selectedPicker ?? 'none'}</Text>;
|
|
21
|
+
};
|
|
22
|
+
|
|
15
23
|
const renderComponent = ({
|
|
16
24
|
channelProps,
|
|
17
25
|
client,
|
|
@@ -32,6 +40,25 @@ const renderComponent = ({
|
|
|
32
40
|
);
|
|
33
41
|
};
|
|
34
42
|
|
|
43
|
+
const renderWithSelectedPicker = ({
|
|
44
|
+
channelProps,
|
|
45
|
+
client,
|
|
46
|
+
}: {
|
|
47
|
+
channelProps: Partial<ChannelProps>;
|
|
48
|
+
client: StreamChat;
|
|
49
|
+
}) => {
|
|
50
|
+
return render(
|
|
51
|
+
<OverlayProvider>
|
|
52
|
+
<Chat client={client}>
|
|
53
|
+
<Channel {...(channelProps as ChannelProps)}>
|
|
54
|
+
<AttachButton />
|
|
55
|
+
<SelectedPicker />
|
|
56
|
+
</Channel>
|
|
57
|
+
</Chat>
|
|
58
|
+
</OverlayProvider>,
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
35
62
|
describe('AttachButton', () => {
|
|
36
63
|
let client: StreamChat;
|
|
37
64
|
let channel: ChannelType;
|
|
@@ -211,4 +238,65 @@ describe('AttachButton', () => {
|
|
|
211
238
|
expect(queryByTestId('attachment-picker-list')).toBeNull();
|
|
212
239
|
});
|
|
213
240
|
});
|
|
241
|
+
|
|
242
|
+
it('should select the image picker when pressed', async () => {
|
|
243
|
+
jest.spyOn(NativeHandler, 'isImageMediaLibraryAvailable').mockImplementation(() => true);
|
|
244
|
+
|
|
245
|
+
renderWithSelectedPicker({ channelProps: { channel }, client });
|
|
246
|
+
|
|
247
|
+
await waitFor(() => {
|
|
248
|
+
expect(screen.queryByTestId('attach-button')).toBeTruthy();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
act(() => {
|
|
252
|
+
fireEvent.press(screen.getByTestId('attach-button'));
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
await waitFor(() => {
|
|
256
|
+
expect(screen.getByTestId('selected-picker')).toHaveTextContent('images');
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should not select a picker when pressed if shouldRenderAttachmentPicker is false', async () => {
|
|
261
|
+
jest.spyOn(NativeHandler, 'isImageMediaLibraryAvailable').mockImplementation(() => true);
|
|
262
|
+
|
|
263
|
+
renderWithSelectedPicker({
|
|
264
|
+
channelProps: { channel, shouldRenderAttachmentPicker: false },
|
|
265
|
+
client,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
await waitFor(() => {
|
|
269
|
+
expect(screen.queryByTestId('attach-button')).toBeTruthy();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
act(() => {
|
|
273
|
+
fireEvent.press(screen.getByTestId('attach-button'));
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
await waitFor(() => {
|
|
277
|
+
expect(screen.getByTestId('selected-picker')).toHaveTextContent('none');
|
|
278
|
+
expect(screen.queryByTestId('attachment-picker-list')).toBeNull();
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('should render the attachment picker by default', async () => {
|
|
283
|
+
renderWithSelectedPicker({ channelProps: { channel }, client });
|
|
284
|
+
|
|
285
|
+
await waitFor(() => {
|
|
286
|
+
expect(screen.queryByTestId('upload-file-touchable')).toBeTruthy();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('should not render the attachment picker when shouldRenderAttachmentPicker is false', async () => {
|
|
291
|
+
renderWithSelectedPicker({
|
|
292
|
+
channelProps: { channel, shouldRenderAttachmentPicker: false },
|
|
293
|
+
client,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await waitFor(() => {
|
|
297
|
+
expect(screen.queryByTestId('attach-button')).toBeTruthy();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
expect(screen.queryByTestId('upload-file-touchable')).toBeNull();
|
|
301
|
+
});
|
|
214
302
|
});
|
|
@@ -33,7 +33,20 @@ export type AttachmentPickerContextValue = Pick<
|
|
|
33
33
|
openPicker: () => void;
|
|
34
34
|
topInset: number;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* When `true`, the native image picker is used instead of the in-app image gallery.
|
|
38
|
+
* The attachment picker itself (with its attachment type selection bar) is still rendered.
|
|
39
|
+
* To not render the attachment picker at all, set `shouldRenderAttachmentPicker` to `false`.
|
|
40
|
+
*/
|
|
36
41
|
disableAttachmentPicker?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the attachment picker should be rendered at all. Defaults to `true`.
|
|
44
|
+
*
|
|
45
|
+
* Can be set to `false` if attachment picker is not used. `openAttachmentPicker` then
|
|
46
|
+
* does nothing. The attach button is still shown, so it needs to either be hidden it or set
|
|
47
|
+
* `handleAttachButtonPress` to override what it does.
|
|
48
|
+
*/
|
|
49
|
+
shouldRenderAttachmentPicker?: boolean;
|
|
37
50
|
attachmentPickerStore: AttachmentPickerStore;
|
|
38
51
|
numberOfAttachmentPickerImageColumns?: number;
|
|
39
52
|
numberOfAttachmentImagesToLoadPerCall?: number;
|
|
@@ -221,8 +221,13 @@ export const MessageInputProvider = ({
|
|
|
221
221
|
}: PropsWithChildren<{
|
|
222
222
|
value: InputMessageInputContextValue;
|
|
223
223
|
}>) => {
|
|
224
|
-
const {
|
|
225
|
-
|
|
224
|
+
const {
|
|
225
|
+
closePicker,
|
|
226
|
+
openPicker,
|
|
227
|
+
attachmentPickerStore,
|
|
228
|
+
disableAttachmentPicker,
|
|
229
|
+
shouldRenderAttachmentPicker = true,
|
|
230
|
+
} = useAttachmentPickerContext();
|
|
226
231
|
const { client } = useChatContext();
|
|
227
232
|
const channelCapabilities = useOwnCapabilitiesContext();
|
|
228
233
|
const [audioRecorderManager] = useState(new AudioRecorderManager());
|
|
@@ -371,10 +376,14 @@ export const MessageInputProvider = ({
|
|
|
371
376
|
* Function to open the attachment picker if the MediaLibary is installed.
|
|
372
377
|
*/
|
|
373
378
|
const openAttachmentPicker = useCallback(() => {
|
|
379
|
+
if (!shouldRenderAttachmentPicker) {
|
|
380
|
+
// There is no picker to open, and a selected picker would leave space reserved for it.
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
374
383
|
dismissKeyboard();
|
|
375
384
|
attachmentPickerStore.setSelectedPicker('images');
|
|
376
385
|
openPicker();
|
|
377
|
-
}, [attachmentPickerStore, openPicker]);
|
|
386
|
+
}, [attachmentPickerStore, openPicker, shouldRenderAttachmentPicker]);
|
|
378
387
|
|
|
379
388
|
/**
|
|
380
389
|
* Function to close the attachment picker if the MediaLibrary is installed.
|
package/src/version.json
CHANGED