fix: Positioning of editing toolbar on mobile devices (#6279)
This commit is contained in:
@@ -12,7 +12,7 @@ import * as React from "react";
|
||||
export default function useEventListener<T extends EventListener>(
|
||||
eventName: string,
|
||||
handler: T,
|
||||
element: Window | Node = window,
|
||||
element: Window | VisualViewport | Node | null = window,
|
||||
options: AddEventListenerOptions = {}
|
||||
) {
|
||||
const savedHandler = React.useRef<T>();
|
||||
|
||||
@@ -10,24 +10,25 @@ import useThrottledCallback from "./useThrottledCallback";
|
||||
*/
|
||||
export default function useWindowSize() {
|
||||
const [windowSize, setWindowSize] = React.useState({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
width: window.visualViewport?.width || window.innerWidth,
|
||||
height: window.visualViewport?.height || window.innerHeight,
|
||||
});
|
||||
|
||||
const handleResize = useThrottledCallback(() => {
|
||||
const width = window.visualViewport?.width || window.innerWidth;
|
||||
const height = window.visualViewport?.height || window.innerHeight;
|
||||
|
||||
setWindowSize((state) => {
|
||||
if (
|
||||
window.innerWidth === state.width &&
|
||||
window.innerHeight === state.height
|
||||
) {
|
||||
if (width === state.width && height === state.height) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return { width: window.innerWidth, height: window.innerHeight };
|
||||
return { width, height };
|
||||
});
|
||||
}, 100);
|
||||
|
||||
useEventListener("resize", handleResize);
|
||||
useEventListener("resize", handleResize, window.visualViewport);
|
||||
|
||||
// Call handler right away so state gets updated with initial window size
|
||||
React.useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user