Skip to content

Commit 88dca0c

Browse files
authored
feat: add ability to autoplay videos in gallery (#2195)
1 parent e359465 commit 88dca0c

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

docusaurus/docs/reactnative/core-components/overlay_provider.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ This can also be set via the `setBottomInset` function provided by the `useAttac
154154
| ------ | ------- |
155155
| number | 0 |
156156

157+
### autoPlayVideo
158+
159+
Enables or disables auto play of videos in the overlay.
160+
161+
| Type | Default |
162+
| ------- | ------- |
163+
| boolean | false |
164+
157165
### giphyVersion
158166

159167
<GiphyVersion />

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type Props<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamC
131131
| 'imageGalleryGridSnapPoints'
132132
| 'imageGalleryGridHandleHeight'
133133
| 'numberOfImageGalleryGridColumns'
134+
| 'autoPlayVideo'
134135
>;
135136

136137
export const ImageGallery = <
@@ -139,6 +140,7 @@ export const ImageGallery = <
139140
props: Props<StreamChatGenerics>,
140141
) => {
141142
const {
143+
autoPlayVideo = false,
142144
giphyVersion = 'fixed_height',
143145
imageGalleryCustomComponents,
144146
imageGalleryGridHandleHeight,
@@ -273,6 +275,7 @@ export const ImageGallery = <
273275
const attachmentPhotos = attachmentImages.map((a) => {
274276
const imageUrl = getUrlOfImageAttachment(a) as string;
275277
const giphyURL = a.giphy?.[giphyVersion]?.url || a.thumb_url || a.image_url;
278+
const isInitiallyPaused = !autoPlayVideo;
276279

277280
return {
278281
channelId: cur.cid,
@@ -283,7 +286,7 @@ export const ImageGallery = <
283286
mime_type: a.type === 'giphy' ? getGiphyMimeType(giphyURL ?? '') : a.mime_type,
284287
original_height: a.original_height,
285288
original_width: a.original_width,
286-
paused: true,
289+
paused: isInitiallyPaused,
287290
progress: 0,
288291
type: a.type,
289292
uri:

package/src/contexts/overlayContext/OverlayContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type OverlayProviderProps<
5858
>
5959
> &
6060
Pick<OverlayContextValue, 'translucentStatusBar'> & {
61+
autoPlayVideo?: boolean;
6162
/**
6263
* The giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values. Uses 'fixed_height' by default
6364
* */

package/src/contexts/overlayContext/OverlayProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const OverlayProvider = <
6464
) => {
6565
const bottomSheetCloseTimeoutRef = useRef<NodeJS.Timeout>();
6666
const {
67+
autoPlayVideo,
6768
AttachmentPickerBottomSheetHandle = DefaultAttachmentPickerBottomSheetHandle,
6869
attachmentPickerBottomSheetHandleHeight,
6970
attachmentPickerBottomSheetHeight,
@@ -237,6 +238,7 @@ export const OverlayProvider = <
237238
)}
238239
{overlay === 'gallery' && (
239240
<ImageGallery<StreamChatGenerics>
241+
autoPlayVideo={autoPlayVideo}
240242
giphyVersion={giphyVersion}
241243
imageGalleryCustomComponents={imageGalleryCustomComponents}
242244
imageGalleryGridHandleHeight={imageGalleryGridHandleHeight}

0 commit comments

Comments
 (0)