一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
36 行
921 B
TypeScript
36 行
921 B
TypeScript
import { RefObject, useState } from 'react';
|
|
import useMessageHandler from './useMessageHandler';
|
|
|
|
interface Size {
|
|
width: number;
|
|
height: number;
|
|
hash: string;
|
|
}
|
|
|
|
export default function(viewRef: RefObject<HTMLIFrameElement>, htmlHash: string, minWidth: number, minHeight: number) {
|
|
const [contentSize, setContentSize] = useState<Size>({
|
|
width: minWidth,
|
|
height: minHeight,
|
|
hash: '',
|
|
});
|
|
|
|
useMessageHandler(viewRef, event => {
|
|
if (event.data.message !== 'updateContentSize') return;
|
|
const rect = event.data.size;
|
|
|
|
let w = rect.width;
|
|
let h = rect.height;
|
|
if (w < minWidth) w = minWidth;
|
|
if (h < minHeight) h = minHeight;
|
|
|
|
const newSize = { width: w, height: h, hash: htmlHash };
|
|
|
|
setContentSize((current: Size) => {
|
|
if (current.width === newSize.width && current.height === newSize.height && current.hash === htmlHash) return current;
|
|
return newSize;
|
|
});
|
|
});
|
|
|
|
return contentSize;
|
|
}
|