Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
justusmattern27 committed Sep 22, 2024
1 parent cd09c37 commit 1ab4818
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions packages/player-react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
'use client';
import {Player as CorePlayer} from '@revideo/core';
import {
ComponentProps,
LegacyRef,
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import {ComponentProps, useCallback, useEffect, useRef, useState} from 'react';
import {Controls} from './controls';
import './styles.css';
import {shouldShowControls} from './utils';
Expand Down Expand Up @@ -81,6 +74,7 @@ export function Player({
const focus = useRef(false);
const playerRef = useRef<HTMLDivElement | null>(null);
const wrapperRef = useRef<HTMLDivElement | null>(null);
const lastRect = useRef<DOMRectReadOnly | null>(null);

const onClickHandler = controls ? () => setPlaying(prev => !prev) : undefined;

Expand Down Expand Up @@ -138,25 +132,24 @@ export function Player({

const handlePlayerResize = useCallback(
(entries: ResizeObserverEntry[]) => {
const [entry] = entries;
if (entry && wrapperRef.current) {
const newRect = entry.contentRect;
if (
!lastRect.current ||
newRect.width !== lastRect.current.width ||
newRect.height !== lastRect.current.height
) {
console.log('jo resize');
lastRect.current = newRect;
onPlayerResize?.(newRect);
}
const [firstEntry] = entries;
if (!firstEntry || !wrapperRef.current) {
return;
}

const newRect = firstEntry.contentRect;
const sameWidth = newRect.width === lastRect.current.width;
const sameHeight = newRect.height === lastRect.current.height;
if (lastRect.current && sameWidth && sameHeight) {
return;
}

lastRect.current = newRect;
onPlayerResize(newRect);
},
[onPlayerResize],
);

const lastRect = useRef<DOMRectReadOnly | null>(null);

useEffect(() => {
if (!wrapperRef.current) return;

Expand Down Expand Up @@ -215,7 +208,7 @@ export function Player({
>
<div className="p-relative">
<revideo-player
ref={playerRef as LegacyRef<HTMLDivElement>}
ref={playerRef}
src={src}
playing={String(playingState)}
onClick={onClickHandler}
Expand Down

0 comments on commit 1ab4818

Please sign in to comment.