feat: maskpage&newchatpage adapt new ui framework done

This commit is contained in:
butterfly
2024-04-19 11:55:51 +08:00
parent b3559f99a2
commit 3d0a98d5d2
40 changed files with 2273 additions and 774 deletions

View File

@@ -1,26 +1,35 @@
import { useLayoutEffect, useRef } from "react";
import { useLayoutEffect, useRef, useState } from "react";
type Size = {
width: number;
height: number;
};
export function useWindowSize(callback: (size: Size) => void) {
export function useWindowSize(callback?: (size: Size) => void) {
const callbackRef = useRef<typeof callback>();
callbackRef.current = callback;
const [size, setSize] = useState({
width: window.innerWidth,
height: window.innerHeight,
});
useLayoutEffect(() => {
const onResize = () => {
callbackRef.current?.({
width: window.innerWidth,
height: window.innerHeight,
});
setSize({
width: window.innerWidth,
height: window.innerHeight,
});
};
window.addEventListener("resize", onResize);
callback({
callback?.({
width: window.innerWidth,
height: window.innerHeight,
});
@@ -29,4 +38,6 @@ export function useWindowSize(callback: (size: Size) => void) {
window.removeEventListener("resize", onResize);
};
}, []);
return size;
}