@@ -40,7 +40,7 @@ function getVideoSrc(stream?: string, record?: string) {
4040 return src ;
4141}
4242
43- function getHeight ( width : number ) : number {
43+ export function getHeight ( width : number ) : number {
4444 return ( width / 16 ) * 9 ;
4545}
4646
@@ -52,16 +52,17 @@ export interface VideoBlockProps {
5252 className ?: string ;
5353 previewImg ?: string ;
5454 playButton ?: React . ReactNode ;
55+ height ?: number ;
5556}
5657
5758const VideoBlock = ( props : VideoBlockProps ) => {
58- const { stream, record, attributes, className, id, previewImg, playButton} = props ;
59+ const { stream, record, attributes, className, id, previewImg, playButton, height } = props ;
5960 const src = getVideoSrc ( stream , record ) ;
6061 const ref = useRef < HTMLDivElement > ( null ) ;
6162 const iframeRef = useRef < HTMLIFrameElement > ( ) ;
6263 const [ hidePreview , setHidePreview ] = useState ( false ) ;
6364 const norender = ( ! stream && ! record ) || ! src ;
64- const [ height , setHeight ] = useState < number > ( ) ;
65+ const [ currentHeight , setCurrentHeight ] = useState ( height || undefined ) ;
6566 const fullId = `${ iframeId } -${ id || src } ` ;
6667 const onPreviewClick = useCallback ( ( ) => {
6768 if ( iframeRef . current ) {
@@ -76,15 +77,17 @@ const VideoBlock = (props: VideoBlockProps) => {
7677
7778 useEffect ( ( ) => {
7879 const updateSize = _ . debounce ( ( ) => {
79- setHeight ( ref . current ? Math . round ( getHeight ( ref . current . offsetWidth ) ) : undefined ) ;
80+ setCurrentHeight (
81+ ref . current ? Math . round ( getHeight ( ref . current . offsetWidth ) ) : undefined ,
82+ ) ;
8083 } , 100 ) ;
8184
8285 updateSize ( ) ;
8386 window . addEventListener ( 'resize' , updateSize ) ;
8487 return ( ) => {
8588 window . removeEventListener ( 'resize' , updateSize ) ;
8689 } ;
87- } , [ ] ) ;
90+ } , [ height ] ) ;
8891
8992 useEffect ( ( ) => {
9093 if ( norender ) {
@@ -119,7 +122,7 @@ const VideoBlock = (props: VideoBlockProps) => {
119122 }
120123
121124 return (
122- < div className = { b ( null , className ) } ref = { ref } style = { { height} } >
125+ < div className = { b ( null , className ) } ref = { ref } style = { { height : currentHeight } } >
123126 { previewImg && ! hidePreview && (
124127 < div className = { b ( 'preview' ) } onClick = { onPreviewClick } >
125128 < Image src = { previewImg } className = { b ( 'image' ) } />
0 commit comments