Skip to content

Commit 6fb7e0e

Browse files
Merge branch 'develop' of https://github.com/GetStream/stream-chat-react-native into feat/optimistic-db-updates
2 parents 11ae740 + 8b1eff9 commit 6fb7e0e

File tree

7 files changed

+64
-30
lines changed

7 files changed

+64
-30
lines changed
Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
1-
import DocumentPicker from 'react-native-document-picker';
1+
/**
2+
* Types are approximated from what we need from the DocumentPicker API.
3+
*
4+
* For its full API, see https://github.com/rnmods/react-native-document-picker/blob/master/src/index.tsx
5+
* */
6+
type ResponseValue = {
7+
name: string;
8+
uri: string;
9+
size: number;
10+
type: string;
11+
};
212

3-
export const pickDocument = async ({ maxNumberOfFiles }: { maxNumberOfFiles: number }) => {
4-
try {
5-
let res = await DocumentPicker.pickMultiple({
6-
type: [DocumentPicker.types.allFiles],
7-
});
13+
let DocumentPicker: {
14+
types: { allFiles: string };
15+
pickMultiple: (opts?: { type: string[] }) => Promise<ResponseValue[]>;
16+
};
817

9-
if (maxNumberOfFiles && res.length > maxNumberOfFiles) {
10-
res = res.slice(0, maxNumberOfFiles);
11-
}
18+
try {
19+
DocumentPicker = require('react-native-document-picker').default;
20+
} catch (err) {
21+
console.log('react-native-document-picker is not installed');
22+
}
1223

13-
return {
14-
cancelled: false,
15-
docs: res.map(({ name, size, type, uri }) => ({
16-
name,
17-
size,
18-
type,
19-
uri,
20-
})),
21-
};
22-
} catch (err) {
23-
return {
24-
cancelled: true,
25-
};
26-
}
27-
};
24+
export const pickDocument = DocumentPicker
25+
? async ({ maxNumberOfFiles }: { maxNumberOfFiles: number }) => {
26+
try {
27+
let res = await DocumentPicker.pickMultiple({
28+
type: [DocumentPicker.types.allFiles],
29+
});
30+
31+
if (maxNumberOfFiles && res.length > maxNumberOfFiles) {
32+
res = res.slice(0, maxNumberOfFiles);
33+
}
34+
35+
return {
36+
cancelled: false,
37+
docs: res.map(({ name, size, type, uri }) => ({
38+
name,
39+
size,
40+
type,
41+
uri,
42+
})),
43+
};
44+
} catch (err) {
45+
return {
46+
cancelled: true,
47+
};
48+
}
49+
}
50+
: null;

package/src/components/Channel/Channel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import {
7474
ThumbsUpReaction,
7575
WutReaction,
7676
} from '../../icons';
77-
import { FlatList as FlatListDefault } from '../../native';
77+
import { FlatList as FlatListDefault, pickDocument } from '../../native';
7878
import * as dbApi from '../../store/apis';
7979
import type { DefaultStreamChatGenerics } from '../../types/types';
8080
import { addReactionToLocalState } from '../../utils/addReactionToLocalState';
@@ -455,7 +455,8 @@ const ChannelWithContext = <
455455
handleRetry,
456456
handleThreadReply,
457457
hasCommands = true,
458-
hasFilePicker = true,
458+
// If pickDocument isn't available, default to hiding the file picker
459+
hasFilePicker = pickDocument !== null,
459460
hasImagePicker = true,
460461
hideDateSeparators = false,
461462
hideStickyDateHeader = false,

package/src/components/ImageGallery/components/ImageGrid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const ImageGrid = <
137137
theme: {
138138
colors: { white },
139139
imageGallery: {
140-
grid: { contentContainer },
140+
grid: { container, contentContainer },
141141
},
142142
},
143143
} = useTheme();
@@ -165,6 +165,7 @@ export const ImageGrid = <
165165
keyExtractor={(item, index) => `${item.uri}-${index}`}
166166
numColumns={numberOfImageGalleryGridColumns || 3}
167167
renderItem={renderItem}
168+
style={container}
168169
/>
169170
);
170171
};

package/src/components/ImageGallery/components/ImageGridHandle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const styles = StyleSheet.create({
1313
},
1414
handle: {
1515
alignItems: 'center',
16-
borderTopLeftRadius: 16,
17-
borderTopRightRadius: 16,
16+
borderTopLeftRadius: 12,
17+
borderTopRightRadius: 12,
1818
flexDirection: 'row',
1919
height: 40,
2020
justifyContent: 'center',

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,13 @@ export const MessageInputProvider = <
575575
};
576576

577577
const pickFile = async () => {
578+
if (pickDocument === null) {
579+
console.log(
580+
'The file picker is not installed. Check our Getting Started documentation to install it.',
581+
);
582+
return;
583+
}
584+
578585
if (numberOfUploads >= value.maxNumberOfFiles) {
579586
Alert.alert('Maximum number of files reached');
580587
return;

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export type Theme = {
182182
rightContainer: ViewStyle;
183183
};
184184
grid: {
185+
container: ViewStyle;
185186
contentContainer: ViewStyle;
186187
gridAvatar: ImageStyle;
187188
gridAvatarWrapper: ViewStyle;
@@ -685,6 +686,7 @@ export const defaultTheme: Theme = {
685686
rightContainer: {},
686687
},
687688
grid: {
689+
container: {},
688690
contentContainer: {},
689691
gridAvatar: {},
690692
gridAvatarWrapper: {},

package/src/native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export const registerNativeHandlers = (handlers: Handlers) => {
251251
getPhotos = handlers.getPhotos;
252252
}
253253

254-
if (handlers.pickDocument) {
254+
if (handlers.pickDocument !== undefined) {
255255
pickDocument = handlers.pickDocument;
256256
}
257257

0 commit comments

Comments
 (0)