This commit is contained in:
lloydzhou 2024-07-25 19:31:16 +08:00
parent 6a083b24c4
commit 556d563ba0
2 changed files with 13 additions and 5 deletions

View File

@ -33,14 +33,18 @@ export function HTMLPreview(props: {
*/
useEffect(() => {
window.addEventListener("message", (e) => {
const handleMessage = (e) => {
const { id, height, title } = e.data;
setTitle(title);
if (id == frameId.current) {
setIframeHeight(height);
}
});
}, [iframeHeight]);
};
window.addEventListener("message", handleMessage);
return () => {
window.removeEventListener("message", handleMessage);
};
}, []);
const height = useMemo(() => {
const parentHeight = props.height || 600;

View File

@ -528,11 +528,15 @@ export function FullScreen(props: any) {
}
}, []);
useEffect(() => {
document.addEventListener("fullscreenchange", (e) => {
const handleScreenChange = (e) => {
if (e.target === ref.current) {
setFullScreen(!!document.fullscreenElement);
}
});
};
document.addEventListener("fullscreenchange", handleScreenChange);
return () => {
document.removeEventListener("fullscreenchange", handleScreenChange);
};
}, []);
return (
<div ref={ref} style={{ position: "relative" }} {...rest}>