mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
fix(webui): prevent initial scale fit layout race condition
This commit is contained in:
@@ -376,8 +376,14 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||||||
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
|
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
|
||||||
const videoRef = useRef<HTMLVideoElement | null>(null)
|
const videoRef = useRef<HTMLVideoElement | null>(null)
|
||||||
const [zoom, setZoom] = useState(1)
|
const [zoom, setZoom] = useState(1)
|
||||||
|
const [hasManuallyZoomed, setHasManuallyZoomed] = useState(false)
|
||||||
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
|
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
|
||||||
|
|
||||||
|
const handleZoomChange = (newZoom: number) => {
|
||||||
|
setZoom(newZoom)
|
||||||
|
setHasManuallyZoomed(true)
|
||||||
|
}
|
||||||
|
|
||||||
// Store
|
// Store
|
||||||
const {
|
const {
|
||||||
isDrawing,
|
isDrawing,
|
||||||
@@ -406,20 +412,17 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||||||
return () => observer.disconnect()
|
return () => observer.disconnect()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Fit to screen initial
|
// Fit to screen initial / responsive resize
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (containerSize.width > 0 && containerSize.height > 0) {
|
if (containerSize.width > 0 && containerSize.height > 0) {
|
||||||
// Only if not already set or reset?
|
|
||||||
// Actually, we want to start fit.
|
|
||||||
const vidW = data.media?.metadata?.originalWidth ?? 1920
|
const vidW = data.media?.metadata?.originalWidth ?? 1920
|
||||||
const vidH = data.media?.metadata?.originalHeight ?? 1080
|
const vidH = data.media?.metadata?.originalHeight ?? 1080
|
||||||
const scale = Math.min(containerSize.width / vidW, containerSize.height / vidH)
|
const scale = Math.min(containerSize.width / vidW, containerSize.height / vidH)
|
||||||
// Only set if zoom is 1 (initial).
|
if (!hasManuallyZoomed) {
|
||||||
if (zoom === 1) {
|
|
||||||
setZoom(scale)
|
setZoom(scale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [containerSize.width, containerSize.height, data.media?.metadata])
|
}, [containerSize.width, containerSize.height, data.media?.metadata, hasManuallyZoomed])
|
||||||
|
|
||||||
// Cleanup ref when player is disposed
|
// Cleanup ref when player is disposed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -922,7 +925,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||||||
changeResolution={changeResolution}
|
changeResolution={changeResolution}
|
||||||
handleDownload={handleDownload}
|
handleDownload={handleDownload}
|
||||||
toggleFullScreen={toggleFullScreen}
|
toggleFullScreen={toggleFullScreen}
|
||||||
onZoomChange={setZoom}
|
onZoomChange={handleZoomChange}
|
||||||
frameRate={frameRate}
|
frameRate={frameRate}
|
||||||
totalFrames={totalFrames}
|
totalFrames={totalFrames}
|
||||||
currentFrame={currentFrame}
|
currentFrame={currentFrame}
|
||||||
|
|||||||
Reference in New Issue
Block a user