Skip to content

Commit

Permalink
feat(controls): add autoDismiss prop
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash committed Dec 20, 2022
1 parent b79acbe commit 1f88f19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/VideoControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const VideoControls = ({
videoElement,
onZoomIn,
onZoomOut,
autoDismiss = true,
}: PropsWithChildren<VideoControlProps>) => {
const [visible, setVisible] = useState(initialVisible);
const opacityAnim = useSharedValue(initialVisible ? 1 : 0);
Expand Down Expand Up @@ -143,6 +144,7 @@ export const VideoControls = ({
visible={visible}
visibilityDuration={autoHideAfterDuration}
isPlaying={componentsProps?.videoState?.isPlaying ?? false}
autoDismiss={autoDismiss}
>
<GestureDetector
gesture={Gesture.Exclusive(pinchGesture, doubleTap, tapGesture)}
Expand Down
6 changes: 6 additions & 0 deletions src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ export type VideoControlProps = {
* Function called on pinch gesture that is zooming out
*/
onZoomOut?: () => void;
/**
* Boolean indicating the auto dismiss of the controls.
*
* Defaults to true
*/
autoDismiss?: boolean;
};

export type ControlTouchableProps = {
Expand Down
6 changes: 4 additions & 2 deletions src/context/ControlsVisibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ControlsVisibilityProviderProps = {
onHide: () => void;
visibilityDuration?: number;
isPlaying: boolean;
autoDismiss?: boolean;
};

const ControlsVisibilityProvider = ({
Expand All @@ -35,17 +36,18 @@ const ControlsVisibilityProvider = ({
children,
visibilityDuration,
isPlaying,
autoDismiss = true,
}: PropsWithChildren<ControlsVisibilityProviderProps>) => {
const timeoutId = useRef<NodeJS.Timeout | undefined>(undefined);
const startTimer = useCallback(() => {
if (!timeoutId.current) {
if (!timeoutId.current && autoDismiss) {
timeoutId.current = setTimeout(() => {
if (isPlaying) {
onHide();
}
}, visibilityDuration);
}
}, [visibilityDuration, onHide, isPlaying]);
}, [visibilityDuration, onHide, isPlaying, autoDismiss]);

const stopTimer = useCallback(() => {
clearTimeout(timeoutId.current);
Expand Down

0 comments on commit 1f88f19

Please sign in to comment.