@idealyst/components 1.2.34 → 1.2.35
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idealyst/components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.35",
|
|
4
4
|
"description": "Shared component library for React and React Native",
|
|
5
5
|
"documentation": "https://github.com/IdealystIO/idealyst-framework/tree/main/packages/components#readme",
|
|
6
6
|
"readme": "README.md",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"publish:npm": "npm publish"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@idealyst/theme": "^1.2.
|
|
59
|
+
"@idealyst/theme": "^1.2.35",
|
|
60
60
|
"@mdi/js": ">=7.0.0",
|
|
61
61
|
"@mdi/react": ">=1.0.0",
|
|
62
62
|
"@react-native-vector-icons/common": ">=12.0.0",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@idealyst/theme": "^1.2.
|
|
109
|
+
"@idealyst/theme": "^1.2.35",
|
|
110
110
|
"@idealyst/tooling": "^1.2.30",
|
|
111
111
|
"@mdi/react": "^1.6.1",
|
|
112
112
|
"@types/react": "^19.1.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useWebLayout } from './useWebLayout';
|
|
1
|
+
export { useWebLayout } from './useWebLayout.web';
|
|
@@ -12,41 +12,36 @@ export function useWebLayout<T extends HTMLElement = HTMLElement>(
|
|
|
12
12
|
onLayout: ((event: LayoutChangeEvent) => void) | undefined
|
|
13
13
|
) {
|
|
14
14
|
const ref = useRef<T>(null);
|
|
15
|
+
// Store callback in a ref to avoid re-running effect when callback identity changes
|
|
16
|
+
const onLayoutRef = useRef(onLayout);
|
|
17
|
+
onLayoutRef.current = onLayout;
|
|
15
18
|
|
|
16
19
|
useEffect(() => {
|
|
17
|
-
if (!
|
|
20
|
+
if (!ref.current) return;
|
|
18
21
|
|
|
19
22
|
const element = ref.current;
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const fireLayoutEvent = () => {
|
|
25
|
+
if (!onLayoutRef.current) return;
|
|
26
|
+
const rect = element.getBoundingClientRect();
|
|
27
|
+
onLayoutRef.current({
|
|
28
|
+
nativeEvent: {
|
|
29
|
+
layout: {
|
|
30
|
+
x: rect.left,
|
|
31
|
+
y: rect.top,
|
|
32
|
+
width: rect.width,
|
|
33
|
+
height: rect.height,
|
|
34
|
+
},
|
|
30
35
|
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
36
|
+
} as LayoutChangeEvent);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Call immediately with initial layout
|
|
40
|
+
fireLayoutEvent();
|
|
33
41
|
|
|
34
42
|
// Set up ResizeObserver for subsequent changes
|
|
35
|
-
const resizeObserver = new ResizeObserver((
|
|
36
|
-
|
|
37
|
-
const { width, height } = entry.contentRect;
|
|
38
|
-
const boundingRect = element.getBoundingClientRect();
|
|
39
|
-
onLayout({
|
|
40
|
-
nativeEvent: {
|
|
41
|
-
layout: {
|
|
42
|
-
x: boundingRect.left,
|
|
43
|
-
y: boundingRect.top,
|
|
44
|
-
width,
|
|
45
|
-
height,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
} as LayoutChangeEvent);
|
|
49
|
-
}
|
|
43
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
44
|
+
fireLayoutEvent();
|
|
50
45
|
});
|
|
51
46
|
|
|
52
47
|
resizeObserver.observe(element);
|
|
@@ -54,7 +49,7 @@ export function useWebLayout<T extends HTMLElement = HTMLElement>(
|
|
|
54
49
|
return () => {
|
|
55
50
|
resizeObserver.disconnect();
|
|
56
51
|
};
|
|
57
|
-
}, [
|
|
52
|
+
}, []);
|
|
58
53
|
|
|
59
54
|
return ref;
|
|
60
55
|
}
|