Skip to content

Commit b13a89c

Browse files
committed
fix: issues with video upload in expo from attachment picker and component displayname
1 parent 1c5aa3e commit b13a89c

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

package/expo-package/src/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ import * as MediaLibrary from 'expo-media-library';
1212
import * as Sharing from 'expo-sharing';
1313
import { registerNativeHandlers } from 'stream-chat-react-native-core';
1414

15+
const VideoComponent = ({ onPlaybackStatusUpdate, paused, resizeMode, style, uri, videoRef }) => (
16+
<ExpoVideoPlayer
17+
onPlaybackStatusUpdate={onPlaybackStatusUpdate}
18+
ref={videoRef}
19+
resizeMode={resizeMode}
20+
shouldPlay={!paused}
21+
source={{
22+
uri,
23+
}}
24+
style={[style]}
25+
/>
26+
);
27+
1528
registerNativeHandlers({
1629
compressImage: async ({ compressImageQuality = 1, uri }) => {
1730
const { uri: compressedUri } = await ImageManipulator.manipulateAsync(uri, [], {
@@ -219,19 +232,7 @@ registerNativeHandlers({
219232
Haptics.selectionAsync();
220233
}
221234
},
222-
// eslint-disable-next-line react/display-name
223-
Video: ({ onPlaybackStatusUpdate, paused, style, uri, videoRef }) => (
224-
<ExpoVideoPlayer
225-
onPlaybackStatusUpdate={onPlaybackStatusUpdate}
226-
ref={videoRef}
227-
resizeMode='contain'
228-
shouldPlay={!paused}
229-
source={{
230-
uri,
231-
}}
232-
style={[style]}
233-
/>
234-
),
235+
Video: VideoComponent,
235236
});
236237

237238
export * from 'stream-chat-react-native-core';

package/native-package/src/index.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ import NetInfo from '@react-native-community/netinfo';
1515
import { FlatList } from '@stream-io/flat-list-mvcp';
1616
import { registerNativeHandlers } from 'stream-chat-react-native-core';
1717

18+
const VideoComponent = ({
19+
onBuffer,
20+
onEnd,
21+
onLoad,
22+
onProgress,
23+
paused,
24+
resizeMode,
25+
style,
26+
uri,
27+
videoRef,
28+
}) => (
29+
<Video
30+
onBuffer={onBuffer}
31+
onEnd={onEnd}
32+
onError={(error) => {
33+
console.error(error);
34+
}}
35+
onLoad={onLoad}
36+
onProgress={onProgress}
37+
paused={paused}
38+
ref={videoRef}
39+
resizeMode={resizeMode}
40+
source={{
41+
uri,
42+
}}
43+
style={style}
44+
/>
45+
);
46+
1847
registerNativeHandlers({
1948
compressImage: async ({ compressImageQuality = 1, height, uri, width }) => {
2049
try {
@@ -249,24 +278,7 @@ registerNativeHandlers({
249278
ignoreAndroidSystemSettings: false,
250279
});
251280
},
252-
// eslint-disable-next-line react/display-name
253-
Video: ({ onBuffer, onEnd, onLoad, onProgress, paused, resizeMode, style, uri, videoRef }) => (
254-
<Video
255-
onBuffer={onBuffer}
256-
onEnd={onEnd}
257-
onError={(error) => {
258-
console.error(error);
259-
}}
260-
onLoad={onLoad}
261-
onProgress={onProgress}
262-
paused={paused}
263-
ref={videoRef}
264-
source={{
265-
uri,
266-
}}
267-
style={style}
268-
/>
269-
),
281+
Video: VideoComponent,
270282
});
271283

272284
if (Platform.OS === 'android') {

package/src/components/AttachmentPicker/AttachmentPicker.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type { AttachmentPickerErrorProps } from './components/AttachmentPickerEr
2525
import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
2626
import { useTheme } from '../../contexts/themeContext/ThemeContext';
2727
import { Recorder } from '../../icons';
28-
import { getPhotos } from '../../native';
28+
import { getLocalAssetUri, getPhotos } from '../../native';
2929
import type { Asset, File } from '../../types/types';
3030
import { vh, vw } from '../../utils/utils';
3131

@@ -110,7 +110,9 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
110110

111111
const size = vw(100) / (numberOfAttachmentPickerImageColumns || 3) - 2;
112112

113-
const onPressVideo = () => {
113+
const onPressVideo = async () => {
114+
// For the case of expo messaging app where you need to fetch the asset uri from asset id
115+
const localAssetURI = asset.id && (await getLocalAssetUri(asset.id));
114116
if (selected) {
115117
setSelectedFiles((files) => files.filter((file) => file.uri !== asset.uri));
116118
} else {
@@ -125,7 +127,7 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
125127
name: asset.filename,
126128
size: asset.fileSize,
127129
type: 'video',
128-
uri: asset.uri,
130+
uri: localAssetURI || asset.uri,
129131
},
130132
];
131133
});

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ export const ImageGallery = <
252252
*/
253253

254254
const photos = images.reduce((acc: Photo<StreamChatGenerics>[], cur) => {
255-
console.log(cur);
256255
const attachmentImages =
257256
cur.attachments?.filter(
258257
(attachment) =>

package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export const AnimatedGalleryVideo: React.FC<Props> = React.memo(
181181
onPlaybackStatusUpdate={onPlayBackStatusUpdate}
182182
onProgress={onProgress}
183183
paused={paused}
184-
resizeMode='cover'
184+
resizeMode='contain'
185185
style={style}
186186
uri={source.uri}
187187
videoRef={videoRef}

0 commit comments

Comments
 (0)