Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto restart video in gallery when end reached on Expo #2304

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package/src/components/ImageGallery/ImageGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ export const ImageGallery = <
photoLength={imageGalleryAttachments.length}
progress={imageGalleryAttachments[selectedIndex].progress || 0}
selectedIndex={selectedIndex}
videoRef={videoRef}
visible={headerFooterVisible}
{...imageGalleryCustomComponents?.footer}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ImageGalleryVideoControl } from './ImageGalleryVideoControl';
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
import { Grid as GridIconDefault, Share as ShareIconDefault } from '../../../icons';
import { deleteFile, saveFile, shareImage } from '../../../native';
import { deleteFile, saveFile, shareImage, VideoType } from '../../../native';

import type { DefaultStreamChatGenerics } from '../../../types/types';
import type { Photo } from '../ImageGallery';
Expand Down Expand Up @@ -67,6 +67,7 @@ export type ImageGalleryFooterVideoControlProps = {
onPlayPause: (status?: boolean) => void;
paused: boolean;
progress: number;
videoRef: React.RefObject<VideoType>;
};

export type ImageGalleryFooterVideoControlComponent = ({
Expand Down Expand Up @@ -100,6 +101,7 @@ type ImageGalleryFooterPropsWithContext<
photoLength: number;
progress: number;
selectedIndex: number;
videoRef: React.RefObject<VideoType>;
visible: Animated.SharedValue<number>;
};

Expand All @@ -125,6 +127,7 @@ export const ImageGalleryFooterWithContext = <
selectedIndex,
ShareIcon,
videoControlElement,
videoRef,
visible,
} = props;

Expand Down Expand Up @@ -181,13 +184,14 @@ export const ImageGalleryFooterWithContext = <
<ReanimatedSafeAreaView style={[container, footerStyle, { backgroundColor: white }]}>
{photo.type === 'video' ? (
videoControlElement ? (
videoControlElement({ duration, onPlayPause, paused, progress })
videoControlElement({ duration, onPlayPause, paused, progress, videoRef })
) : (
<ImageGalleryVideoControl
duration={duration}
onPlayPause={onPlayPause}
paused={paused}
progress={progress}
videoRef={videoRef}
/>
)
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const styles = StyleSheet.create({

export const ImageGalleryVideoControl: React.FC<ImageGalleryFooterVideoControlProps> = React.memo(
(props) => {
const { duration, onPlayPause, paused, progress } = props;
const { duration, onPlayPause, paused, progress, videoRef } = props;

const videoDuration = duration
? duration / 3600 >= 1
Expand All @@ -60,14 +60,19 @@ export const ImageGalleryVideoControl: React.FC<ImageGalleryFooterVideoControlPr
},
} = useTheme();

const handlePlayPause = async () => {
if (progress === 1) {
// For expo CLI
if (videoRef.current?.setPositionAsync) {
await videoRef.current.setPositionAsync(0);
}
}
onPlayPause();
};

return (
<View style={[styles.videoContainer, videoContainer]}>
<TouchableOpacity
accessibilityLabel='Play Pause Button'
onPress={() => {
onPlayPause();
}}
>
<TouchableOpacity accessibilityLabel='Play Pause Button' onPress={handlePlayPause}>
<View style={[styles.roundedView, roundedView, { backgroundColor: static_white }]}>
{paused ? (
<Play accessibilityLabel='Play Icon' height={24} pathFill={static_black} width={24} />
Expand Down