Merge pull request #24 from TiE23/ISSUE-022
ISSUE-022 - Well. That just works. Awesome.
This commit is contained in:
6 files changed
+20
-86
No files matched your search
@@ -39,6 +39,7 @@
|
||||
"react-redux": "^7.2.6",
|
||||
"react-router-dom": "6",
|
||||
"react-scripts": "5.0.0",
|
||||
"react-use-measure": "^2.1.1",
|
||||
"resize-observer-polyfill": "^1.5.1",
|
||||
"styled-components": "^5.3.3",
|
||||
"typescript": "^4.4.2",
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
import { Outlet } from "react-router-dom";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { useDimensions } from "./utils/hooks";
|
||||
import {
|
||||
setDimensions,
|
||||
} from "./features/pageDimensions/pageDimensionsSlice";
|
||||
@@ -14,11 +14,11 @@ function App() {
|
||||
const [appRef, {
|
||||
height: appHeight,
|
||||
width: appWidth,
|
||||
}] = useDimensions<HTMLDivElement>();
|
||||
}] = useMeasure();
|
||||
const [mainMenuRef, {
|
||||
height: mainMenuHeight,
|
||||
width: mainMenuWidth,
|
||||
}] = useDimensions<HTMLDivElement>();
|
||||
}] = useMeasure();
|
||||
|
||||
// Set App dimensions.
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { useTransition, animated } from "@react-spring/web";
|
||||
import { useDrag } from "@use-gesture/react";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { useDimensions } from "../../../utils/hooks";
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
||||
import { OverlayImage, OverlayImageContainer, OverlayImageSubContainer } from "./styles";
|
||||
@@ -31,8 +31,7 @@ export function OverlayDisplay({
|
||||
const [overlayItemImageRef, {
|
||||
width: overlayItemWidth,
|
||||
height: overlayItemHeight,
|
||||
}] = useDimensions<HTMLImageElement>();
|
||||
console.log(overlayItemWidth, overlayItemHeight);
|
||||
}] = useMeasure();
|
||||
const
|
||||
minX = -bleedover,
|
||||
minY = -bleedover,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Outlet } from "react-router-dom";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { mainMenuDimensionsSelector } from "../../features/pageDimensions/pageDimensionsSelector";
|
||||
import { useDimensions } from "../../utils/hooks";
|
||||
import { setDimensions } from "../../features/pageDimensions/pageDimensionsSlice";
|
||||
|
||||
import { FullScreenContainer } from "../Common/FullScreenContainer.styled";
|
||||
@@ -18,7 +18,7 @@ export default function Workspaces() {
|
||||
const [workspaceRef, {
|
||||
height: workspaceHeight,
|
||||
width: workspaceWidth,
|
||||
}] = useDimensions<HTMLDivElement>();
|
||||
}] = useMeasure();
|
||||
|
||||
// Set Workspace dimensions.
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
import useResizeObserver from "@react-hook/resize-observer";
|
||||
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
|
||||
export const useDimensions = <T extends HTMLElement>() => {
|
||||
const ref = useRef<T>(null);
|
||||
const [width, setWidth] = useState(0);
|
||||
const [height, setHeight] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (element == null) return;
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
if (!Array.isArray(entries)) return;
|
||||
if (!entries.length) return;
|
||||
|
||||
const entry = entries[0];
|
||||
const boundingRect = entry.target.getBoundingClientRect();
|
||||
if (width !== boundingRect.width) setWidth(boundingRect.width);
|
||||
if (height !== boundingRect.height) setHeight(boundingRect.height);
|
||||
});
|
||||
resizeObserver.observe(element);
|
||||
|
||||
return () => resizeObserver.unobserve(element);
|
||||
}, [height, width]);
|
||||
|
||||
// Returning correctly with generics apparently requires type def here.
|
||||
return [
|
||||
ref,
|
||||
{ width, height },
|
||||
] as [
|
||||
React.RefObject<T>,
|
||||
{ height: number, width: number },
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Proven to be less reliable than using resizeObserver directly.
|
||||
* @returns
|
||||
*/
|
||||
export const useDimensionsAlt1 = <T extends HTMLElement>() => {
|
||||
const ref = useRef<T>(null);
|
||||
const [size, setSize] = useState<DOMRect>();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const element = ref.current;
|
||||
if (element == null) return;
|
||||
setSize(element.getBoundingClientRect());
|
||||
}, [ref]);
|
||||
|
||||
useResizeObserver(ref, (entry) => setSize(entry.contentRect));
|
||||
|
||||
// Returning correctly with generics apparently requires type def here.
|
||||
return [
|
||||
ref,
|
||||
size ?? { width: 0, height: 0 },
|
||||
] as [
|
||||
React.RefObject<T>,
|
||||
DOMRect,
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Based off the code demo for useResizeObserver.
|
||||
* https://github.com/jaredLunde/react-hook/tree/master/packages/resize-observer
|
||||
* @param target React Ref
|
||||
* @returns
|
||||
*/
|
||||
export const useDimensionsAlt2 = <T extends HTMLElement>(target: React.RefObject<T>) => {
|
||||
const [size, setSize] = useState<DOMRect>();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setSize(target.current?.getBoundingClientRect());
|
||||
}, [target]);
|
||||
|
||||
useResizeObserver(target, entry => setSize(entry.contentRect));
|
||||
return size ?? { width: 0, height: 0, x: 0, y: 0 };
|
||||
};
|
||||
@@ -3916,6 +3916,11 @@ data-urls@^2.0.0:
|
||||
whatwg-mimetype "^2.3.0"
|
||||
whatwg-url "^8.0.0"
|
||||
|
||||
debounce@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
|
||||
integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==
|
||||
|
||||
debug@2.6.9, debug@^2.6.0, debug@^2.6.9:
|
||||
version "2.6.9"
|
||||
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz"
|
||||
@@ -7818,6 +7823,13 @@ react-scripts@5.0.0:
|
||||
optionalDependencies:
|
||||
fsevents "^2.3.2"
|
||||
|
||||
react-use-measure@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/react-use-measure/-/react-use-measure-2.1.1.tgz#5824537f4ee01c9469c45d5f7a8446177c6cc4ba"
|
||||
integrity sha512-nocZhN26cproIiIduswYpV5y5lQpSQS1y/4KuvUCjSKmw7ZWIS/+g3aFnX3WdBkyuGUtTLif3UTqnLLhbDoQig==
|
||||
dependencies:
|
||||
debounce "^1.2.1"
|
||||
|
||||
react@^17.0.2:
|
||||
version "17.0.2"
|
||||
resolved "https://registry.npmjs.org/react/-/react-17.0.2.tgz"
|
||||
|
||||
Reference in new issue
Block a user