@expofp/ui 3.26.0 → 3.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
/**
|
|
3
|
+
* How long the window size must hold still before consumers see it. A live window drag fires
|
|
4
|
+
* `resize` on every frame, and a state update per frame re-renders every consumer's subtree for
|
|
5
|
+
* the whole drag — for layout breakpoints, one update once the drag settles is enough.
|
|
6
|
+
*/
|
|
7
|
+
const RESIZE_DEBOUNCE_MS = 200;
|
|
8
|
+
const measure = () => {
|
|
9
|
+
const isInIframe = window !== window.top;
|
|
10
|
+
if (isInIframe) {
|
|
11
11
|
return {
|
|
12
|
-
width: window.innerWidth,
|
|
13
|
-
height: window.innerHeight,
|
|
12
|
+
width: document.documentElement.clientWidth || window.innerWidth,
|
|
13
|
+
height: document.documentElement.clientHeight || window.innerHeight,
|
|
14
14
|
};
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
width: window.innerWidth,
|
|
18
|
+
height: window.innerHeight,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const useWindowSize = () => {
|
|
22
|
+
const [windowSize, setWindowSize] = useState(measure);
|
|
16
23
|
useEffect(() => {
|
|
24
|
+
let timeoutId;
|
|
17
25
|
const handleResize = () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
setWindowSize({
|
|
21
|
-
width: document.documentElement.clientWidth || window.innerWidth,
|
|
22
|
-
height: document.documentElement.clientHeight || window.innerHeight,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
setWindowSize({
|
|
27
|
-
width: window.innerWidth,
|
|
28
|
-
height: window.innerHeight,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
26
|
+
clearTimeout(timeoutId);
|
|
27
|
+
timeoutId = setTimeout(() => setWindowSize(measure()), RESIZE_DEBOUNCE_MS);
|
|
31
28
|
};
|
|
32
29
|
window.addEventListener('resize', handleResize);
|
|
33
30
|
window.addEventListener('orientationchange', handleResize);
|
|
34
31
|
return () => {
|
|
32
|
+
clearTimeout(timeoutId);
|
|
35
33
|
window.removeEventListener('resize', handleResize);
|
|
36
34
|
window.removeEventListener('orientationchange', handleResize);
|
|
37
35
|
};
|