Skip to content

Commit 8f8d17b

Browse files
committed
fix: refine the android video recording handler
1 parent 521ea88 commit 8f8d17b

File tree

11 files changed

+60
-35
lines changed

11 files changed

+60
-35
lines changed

package/expo-package/src/optionalDependencies/takePhoto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ export const takePhoto = ImagePicker
4343

4444
if (permissionGranted) {
4545
const imagePickerSuccessResult = await ImagePicker.launchCameraAsync({
46-
mediaTypes: Platform.OS === 'ios' ? mediaTypeMap[mediaType] : mediaType[mediaType],
46+
mediaTypes: mediaTypeMap[mediaType],
4747
quality: Math.min(Math.max(0, compressImageQuality), 1),
4848
});
4949
const canceled = imagePickerSuccessResult.canceled;
5050
const assets = imagePickerSuccessResult.assets;
5151
// since we only support single photo upload for now we will only be focusing on 0'th element.
5252
const photo = assets && assets[0];
53-
console.log('photo', photo);
5453
if (canceled) {
5554
return { cancelled: true };
5655
}

package/native-package/src/optionalDependencies/takePhoto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const takePhoto = ImagePicker
3535
mediaType: mediaType,
3636
quality: Math.min(Math.max(0, compressImageQuality), 1),
3737
});
38-
if (!result.assets.length) {
38+
if (!result.assets.length || result.didCancel) {
3939
return {
4040
cancelled: true,
4141
};

package/src/components/AttachmentPicker/components/AttachmentPickerItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const AttachmentVideo = (props: AttachmentVideoProps) => {
113113
</View>
114114
)}
115115
<View style={styles.videoView}>
116-
<Recorder height={20} pathFill={white} width={25} />
116+
<Recorder height={20} pathFill={white} width={20} />
117117
{videoDuration ? (
118118
<Text style={[{ color: white }, styles.durationText, durationText]}>
119119
{durationLabel}

package/src/components/AttachmentPicker/components/AttachmentPickerSelectionBar.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React from 'react';
2-
import { StyleSheet, TouchableOpacity, View } from 'react-native';
2+
import { Platform, StyleSheet, TouchableOpacity, View } from 'react-native';
33

44
import { useAttachmentPickerContext } from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
55
import { useChannelContext } from '../../../contexts/channelContext/ChannelContext';
66
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
77
import { useMessagesContext } from '../../../contexts/messagesContext/MessagesContext';
88
import { useOwnCapabilitiesContext } from '../../../contexts/ownCapabilitiesContext/OwnCapabilitiesContext';
99
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
10-
import { Recorder } from '../../../icons';
1110

1211
const styles = StyleSheet.create({
1312
container: {
@@ -30,6 +29,7 @@ export const AttachmentPickerSelectionBar = () => {
3029
ImageSelectorIcon,
3130
selectedPicker,
3231
setSelectedPicker,
32+
VideoRecorderSelectorIcon,
3333
} = useAttachmentPickerContext();
3434

3535
const {
@@ -49,7 +49,6 @@ export const AttachmentPickerSelectionBar = () => {
4949
const {
5050
theme: {
5151
attachmentSelectionBar: { container, icon },
52-
colors: { grey },
5352
},
5453
} = useTheme();
5554

@@ -108,7 +107,7 @@ export const AttachmentPickerSelectionBar = () => {
108107
<TouchableOpacity
109108
hitSlop={{ bottom: 15, top: 15 }}
110109
onPress={() => {
111-
takeAndUploadImage();
110+
takeAndUploadImage(Platform.OS === 'android' ? 'image' : 'mixed');
112111
}}
113112
testID='take-photo-touchable'
114113
>
@@ -120,16 +119,19 @@ export const AttachmentPickerSelectionBar = () => {
120119
</View>
121120
</TouchableOpacity>
122121
) : null}
123-
{hasCameraPicker ? (
122+
{hasCameraPicker && Platform.OS === 'android' ? (
124123
<TouchableOpacity
125124
hitSlop={{ bottom: 15, top: 15 }}
126125
onPress={() => {
127126
takeAndUploadImage('video');
128127
}}
129128
testID='take-photo-touchable'
130129
>
131-
<View style={[styles.icon, icon]}>
132-
<Recorder pathFill={grey} height={20} width={20} />
130+
<View style={[styles.icon, { marginTop: 4 }, icon]}>
131+
<VideoRecorderSelectorIcon
132+
numberOfImageUploads={imageUploads.length}
133+
selectedPicker={selectedPicker}
134+
/>
133135
</View>
134136
</TouchableOpacity>
135137
) : null}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
4+
import { Recorder } from '../../../icons';
5+
6+
export const VideoRecorderSelectorIcon = () => {
7+
const {
8+
theme: {
9+
colors: { grey },
10+
},
11+
} = useTheme();
12+
13+
return <Recorder height={20} pathFill={grey} width={20} />;
14+
};

package/src/components/MessageInput/components/NativeAttachmentPicker.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import React, { useEffect, useRef } from 'react';
2-
import { Animated, Easing, LayoutRectangle, Pressable, StyleSheet } from 'react-native';
2+
import { Animated, Easing, LayoutRectangle, Platform, Pressable, StyleSheet } from 'react-native';
33

44
import {
5+
useAttachmentPickerContext,
56
useChannelContext,
67
useMessagesContext,
78
useOwnCapabilitiesContext,
89
} from '../../../contexts';
910
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
1011
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
1112

12-
import { CameraSelectorIcon } from '../../AttachmentPicker/components/CameraSelectorIcon';
13-
import { FileSelectorIcon } from '../../AttachmentPicker/components/FileSelectorIcon';
14-
import { ImageSelectorIcon } from '../../AttachmentPicker/components/ImageSelectorIcon';
1513
import { CreatePollIcon } from '../../Poll/components/CreatePollIcon';
16-
import { Recorder } from '../../../icons';
1714

1815
type NativeAttachmentPickerProps = {
1916
onRequestedClose: () => void;
@@ -29,10 +26,9 @@ export const NativeAttachmentPicker = ({
2926
}: NativeAttachmentPickerProps) => {
3027
const size = attachButtonLayoutRectangle?.width ?? 0;
3128
const attachButtonItemSize = 40;
32-
const NUMBER_OF_BUTTONS = 5;
3329
const {
3430
theme: {
35-
colors: { grey, grey_whisper },
31+
colors: { grey_whisper },
3632
messageInput: {
3733
nativeAttachmentPicker: {
3834
buttonContainer,
@@ -55,14 +51,16 @@ export const NativeAttachmentPicker = ({
5551
const { threadList } = useChannelContext();
5652
const { hasCreatePoll } = useMessagesContext();
5753
const ownCapabilities = useOwnCapabilitiesContext();
54+
const { CameraSelectorIcon, FileSelectorIcon, ImageSelectorIcon, VideoRecorderSelectorIcon } =
55+
useAttachmentPickerContext();
5856

5957
const popupHeight =
6058
// the top padding
6159
TOP_PADDING +
6260
// take margins into account
63-
ATTACH_MARGIN_BOTTOM * NUMBER_OF_BUTTONS +
61+
ATTACH_MARGIN_BOTTOM +
6462
// the size of the attachment icon items (same size as attach button * amount of attachment button types)
65-
attachButtonItemSize * NUMBER_OF_BUTTONS;
63+
attachButtonItemSize;
6664

6765
const containerPopupStyle = {
6866
borderTopEndRadius: size / 2,
@@ -148,15 +146,19 @@ export const NativeAttachmentPicker = ({
148146
buttons.push({
149147
icon: <CameraSelectorIcon />,
150148
id: 'Camera',
151-
onPressHandler: takeAndUploadImage,
152-
});
153-
buttons.push({
154-
icon: <Recorder pathFill={grey} height={20} width={20} />,
155-
id: 'Video',
156149
onPressHandler: () => {
157-
takeAndUploadImage('video');
150+
takeAndUploadImage(Platform.OS === 'android' ? 'image' : 'mixed');
158151
},
159152
});
153+
if (Platform.OS === 'android') {
154+
buttons.push({
155+
icon: <VideoRecorderSelectorIcon />,
156+
id: 'Video',
157+
onPressHandler: () => {
158+
takeAndUploadImage('video');
159+
},
160+
});
161+
}
160162
}
161163

162164
return (

package/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from './AttachmentPicker/components/AttachmentPickerErrorImage';
1717
export * from './AttachmentPicker/components/AttachmentPickerSelectionBar';
1818
export * from './AttachmentPicker/components/CameraSelectorIcon';
1919
export * from './AttachmentPicker/components/FileSelectorIcon';
20+
export * from './AttachmentPicker/components/VideoRecorderSelectorIcon';
2021
export * from './AttachmentPicker/components/ImageOverlaySelectedComponent';
2122
export * from './AttachmentPicker/components/ImageSelectorIcon';
2223

package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
88
import { isTestEnvironment } from '../utils/isTestEnvironment';
99

1010
export type AttachmentPickerIconProps = {
11-
numberOfImageUploads: number;
11+
numberOfImageUploads?: number;
1212
selectedPicker?: 'images';
1313
};
1414

@@ -90,6 +90,12 @@ export type AttachmentPickerContextValue = {
9090
setSelectedPicker: React.Dispatch<React.SetStateAction<'images' | undefined>>;
9191
setTopInset: React.Dispatch<React.SetStateAction<number>>;
9292
topInset: number;
93+
/**
94+
* Custom UI component for Android's video recorder selector icon.
95+
*
96+
* **Default: ** [VideoRecorderSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/VideoRecorderSelectorIcon.tsx)
97+
*/
98+
VideoRecorderSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;
9399
selectedPicker?: 'images';
94100
};
95101

@@ -109,6 +115,7 @@ export const AttachmentPickerProvider = ({
109115
| 'FileSelectorIcon'
110116
| 'ImageSelectorIcon'
111117
| 'openPicker'
118+
| 'VideoRecorderSelectorIcon'
112119
> &
113120
Partial<Pick<AttachmentPickerContextValue, 'bottomInset' | 'topInset'>>;
114121
}>) => {

package/src/contexts/overlayContext/OverlayContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type OverlayProviderProps<
4444
| 'FileSelectorIcon'
4545
| 'ImageSelectorIcon'
4646
| 'topInset'
47+
| 'VideoRecorderSelectorIcon'
4748
>
4849
> &
4950
ImageGalleryCustomComponents<StreamChatGenerics> & {

package/src/contexts/overlayContext/OverlayProvider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CameraSelectorIcon as DefaultCameraSelectorIcon } from '../../component
1919
import { FileSelectorIcon as DefaultFileSelectorIcon } from '../../components/AttachmentPicker/components/FileSelectorIcon';
2020
import { ImageOverlaySelectedComponent as DefaultImageOverlaySelectedComponent } from '../../components/AttachmentPicker/components/ImageOverlaySelectedComponent';
2121
import { ImageSelectorIcon as DefaultImageSelectorIcon } from '../../components/AttachmentPicker/components/ImageSelectorIcon';
22+
import { VideoRecorderSelectorIcon as DefaultVideoRecorderSelectorIcon } from '../../components/AttachmentPicker/components/VideoRecorderSelectorIcon';
2223
import { ImageGallery } from '../../components/ImageGallery/ImageGallery';
2324
import { CreatePollIcon as DefaultCreatePollIcon } from '../../components/Poll/components/CreatePollIcon';
2425
import { useStreami18n } from '../../hooks/useStreami18n';
@@ -116,6 +117,7 @@ export const OverlayProvider = <
116117
},
117118
topInset,
118119
value,
120+
VideoRecorderSelectorIcon = DefaultVideoRecorderSelectorIcon,
119121
} = props;
120122

121123
const attachmentPickerProps = {
@@ -192,6 +194,7 @@ export const OverlayProvider = <
192194
ImageSelectorIcon,
193195
openPicker: () => openPicker(bottomSheetRef),
194196
topInset,
197+
VideoRecorderSelectorIcon,
195198
};
196199

197200
const overlayContext = {

0 commit comments

Comments
 (0)