mirror of https://github.com/mifi/lossless-cut
try to implement window popout #726
parent
280068a08f
commit
216b39ade7
@ -0,0 +1,30 @@
|
|||||||
|
import { memo, useEffect, useRef, useState } from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
|
// todo https://github.com/JakeGinnivan/react-popout/blob/master/lib/react-popout.jsx
|
||||||
|
|
||||||
|
// https://github.com/mifi/lossless-cut/issues/726
|
||||||
|
const Window = memo(({ children, features, onClose }) => {
|
||||||
|
const windowRef = useRef();
|
||||||
|
const [windowOpen, setWindowOpen] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
windowRef.current = window.open(undefined, undefined, features);
|
||||||
|
setWindowOpen(true);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
windowRef.current.close();
|
||||||
|
};
|
||||||
|
}, [features]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
windowRef.current.addEventListener('unload', onClose);
|
||||||
|
return () => windowRef.current.removeEventListener('unload', onClose);
|
||||||
|
}, [onClose]);
|
||||||
|
|
||||||
|
if (!windowOpen) return null;
|
||||||
|
|
||||||
|
return ReactDOM.createPortal(children, windowRef.current.document.body);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Window;
|
||||||
Loading…
Reference in New Issue