Skip to content

Commit

Permalink
test: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thenick775 committed Dec 17, 2024
1 parent 7d2db54 commit 36170e6
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions gbajs3/src/components/screen/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Screen = () => {
const { setCanvas } = useEmulatorContext();
const { areItemsDraggable } = useDragContext();
const { areItemsResizable } = useResizeContext();
const { layouts, setLayout, hasSetLayout } = useLayoutContext();
const { layouts, setLayout, hasSetLayout, clearLayouts } = useLayoutContext();
const screenWrapperXStart = isLargerThanPhone ? NavigationMenuWidth + 10 : 0;
const screenWrapperYStart = isLargerThanPhone && !isMobileLandscape ? 15 : 0;
const rndRef = useRef<Rnd | null>();
Expand All @@ -89,19 +89,29 @@ export const Screen = () => {
useLayoutEffect(() => {
if (layouts?.screen?.position || layouts?.screen?.size) return;

const x = Math.floor(
window.innerWidth / 2 - (layouts?.screen?.initialBounds?.width ?? 0) / 2
);
const y = Math.floor(
window.innerHeight / 2 - (layouts?.screen?.initialBounds?.height ?? 0) / 2
);

if (isMobileLandscape) rndRef?.current?.updatePosition({ x, y });

setLayout('screen', {
initialBounds:
rndRef.current?.resizableElement?.current?.getBoundingClientRect()
});
const timeout = setTimeout(() => {
const currentDimensions =
rndRef?.current?.resizableElement?.current?.getBoundingClientRect();
const width = currentDimensions?.width;
const height = currentDimensions?.height;

const x = Math.floor(
document.documentElement.clientWidth / 2 - (width ?? 0) / 2
);
const y = Math.floor(
document.documentElement.clientHeight / 2 - (height ?? 0) / 2
);

if (isMobileLandscape) rndRef?.current?.updatePosition({ x, y });

clearLayouts();
setLayout('screen', {
initialBounds:
rndRef.current?.resizableElement?.current?.getBoundingClientRect()
});
}, 100);

return () => clearTimeout(timeout);
}, [

Check warning on line 115 in gbajs3/src/components/screen/screen.tsx

View workflow job for this annotation

GitHub Actions / gbajs3 / build

React Hook useLayoutEffect has a missing dependency: 'clearLayouts'. Either include it or remove the dependency array
isMobileLandscape,
layouts?.screen?.initialBounds?.width,
Expand Down

0 comments on commit 36170e6

Please sign in to comment.