more fixes web + mobile
This commit is contained in:
@@ -3,6 +3,9 @@ import { Asset } from "expo-asset";
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
|
||||
const CLOSE_THRESHOLD_SECONDS = 0.35;
|
||||
const CLOSE_POLL_INTERVAL_MS = 500;
|
||||
|
||||
const overlayStyle = {
|
||||
position: "fixed",
|
||||
top: 0,
|
||||
@@ -112,8 +115,29 @@ const FullscreenIntroVideo = ({ url, visible = true, onClose }) => {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const handleEnded = handleClose;
|
||||
const shouldClose = () => {
|
||||
if (hasClosedRef.current) {
|
||||
return false;
|
||||
}
|
||||
if (video.ended) {
|
||||
return true;
|
||||
}
|
||||
const remaining = video.duration - video.currentTime;
|
||||
return Number.isFinite(remaining) && remaining <= CLOSE_THRESHOLD_SECONDS;
|
||||
};
|
||||
|
||||
const tryHandleClose = () => {
|
||||
if (shouldClose()) {
|
||||
handleClose();
|
||||
}
|
||||
};
|
||||
const handleEnded = tryHandleClose;
|
||||
const handleTimeUpdate = tryHandleClose;
|
||||
const handlePause = tryHandleClose;
|
||||
video.addEventListener("ended", handleEnded);
|
||||
video.addEventListener("timeupdate", handleTimeUpdate);
|
||||
video.addEventListener("pause", handlePause);
|
||||
const pollId = setInterval(tryHandleClose, CLOSE_POLL_INTERVAL_MS);
|
||||
|
||||
video.currentTime = 0;
|
||||
const attemptPlay = () => {
|
||||
@@ -133,6 +157,9 @@ const FullscreenIntroVideo = ({ url, visible = true, onClose }) => {
|
||||
return () => {
|
||||
video.pause();
|
||||
video.removeEventListener("ended", handleEnded);
|
||||
video.removeEventListener("timeupdate", handleTimeUpdate);
|
||||
video.removeEventListener("pause", handlePause);
|
||||
clearInterval(pollId);
|
||||
};
|
||||
}, [handleClose, muted, uri, visible]);
|
||||
|
||||
@@ -154,7 +181,6 @@ const FullscreenIntroVideo = ({ url, visible = true, onClose }) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log("video uri", uri);
|
||||
return (
|
||||
<Portal>
|
||||
<View pointerEvents="box-none" style={overlayStyle}>
|
||||
|
||||
Reference in New Issue
Block a user