@draftbit/core 47.8.2 → 47.8.3-28183.2
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/lib/commonjs/components/Layout/ZStack.js +1 -1
- package/lib/typescript/src/components/Layout/ZStack.js +49 -3
- package/lib/typescript/src/components/Layout/ZStack.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/Layout/ZStack.js +49 -3
- package/src/components/Layout/ZStack.js.map +1 -1
- package/src/components/Layout/ZStack.tsx +81 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "47.8.2",
|
|
3
|
+
"version": "47.8.3-028183.2+0281830",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"types": "lib/typescript/src/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@date-io/date-fns": "^1.3.13",
|
|
43
43
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
44
|
-
"@draftbit/types": "47.
|
|
44
|
+
"@draftbit/types": "^47.8.3-028183.2+0281830",
|
|
45
45
|
"@expo/vector-icons": "^13.0.0",
|
|
46
46
|
"@material-ui/core": "^4.11.0",
|
|
47
47
|
"@material-ui/pickers": "^3.2.10",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
],
|
|
103
103
|
"testEnvironment": "node"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "02818304a5b734c6094441abb059ea3b806e9a70"
|
|
106
106
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
|
|
3
|
+
import { useDeepCompareEffect } from "../../utilities";
|
|
4
|
+
const ZStack = ({ reversed, children, style, ...rest }) => {
|
|
5
|
+
const [childSizes, setChildSizes] = React.useState(new Map());
|
|
6
|
+
const [maxChildWidth, setMaxChildWidth] = React.useState();
|
|
7
|
+
const [maxChildHeight, setMaxChildHeight] = React.useState();
|
|
8
|
+
const onChildLayout = React.useCallback((index, width, height) => {
|
|
9
|
+
const size = {
|
|
10
|
+
width: roundTo3DecimalPoints(width),
|
|
11
|
+
height: roundTo3DecimalPoints(height),
|
|
12
|
+
};
|
|
13
|
+
setChildSizes(new Map(childSizes.set(index, size)));
|
|
14
|
+
}, [childSizes, setChildSizes]);
|
|
4
15
|
const absoluteChildren = React.useMemo(() => {
|
|
5
16
|
let childrenArray = React.Children.toArray(children);
|
|
6
17
|
if (reversed) {
|
|
@@ -10,11 +21,46 @@ const ZStack = ({ reversed, children, ...rest }) => {
|
|
|
10
21
|
const props = child.props || {};
|
|
11
22
|
return React.cloneElement(child, {
|
|
12
23
|
...props,
|
|
24
|
+
onLayout: (event) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const layout = event.nativeEvent.layout;
|
|
27
|
+
const fullWidth = layout.x + layout.width;
|
|
28
|
+
const fullHeight = layout.y + layout.height;
|
|
29
|
+
onChildLayout(index, fullWidth, fullHeight);
|
|
30
|
+
(_a = props.onLayout) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
31
|
+
},
|
|
32
|
+
key: index,
|
|
13
33
|
style: { position: "absolute", zIndex: index + 1, ...props.style },
|
|
14
34
|
}, props.children);
|
|
15
35
|
});
|
|
16
|
-
}, [children, reversed]);
|
|
17
|
-
|
|
36
|
+
}, [children, reversed, onChildLayout]);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
setChildSizes(new Map());
|
|
39
|
+
}, [absoluteChildren.length]);
|
|
40
|
+
const childSizeValues = Array.from(childSizes.values());
|
|
41
|
+
useDeepCompareEffect(() => {
|
|
42
|
+
let maxWidth = 0;
|
|
43
|
+
let maxHeight = 0;
|
|
44
|
+
childSizeValues.forEach(({ width, height }) => {
|
|
45
|
+
if (width > maxWidth) {
|
|
46
|
+
maxWidth = width;
|
|
47
|
+
}
|
|
48
|
+
if (height > maxHeight) {
|
|
49
|
+
maxHeight = height;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
setMaxChildWidth(maxWidth);
|
|
53
|
+
setMaxChildHeight(maxHeight);
|
|
54
|
+
}, [childSizeValues, setMaxChildWidth, setMaxChildHeight]);
|
|
55
|
+
return (React.createElement(View, { style: [
|
|
56
|
+
maxChildWidth && maxChildHeight
|
|
57
|
+
? { width: maxChildWidth, height: maxChildHeight }
|
|
58
|
+
: {},
|
|
59
|
+
style,
|
|
60
|
+
], ...rest }, absoluteChildren));
|
|
18
61
|
};
|
|
62
|
+
function roundTo3DecimalPoints(value) {
|
|
63
|
+
return Math.round(value * 1000) / 1000;
|
|
64
|
+
}
|
|
19
65
|
export default ZStack;
|
|
20
66
|
//# sourceMappingURL=ZStack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZStack.js","sourceRoot":"","sources":["ZStack.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"ZStack.js","sourceRoot":"","sources":["ZStack.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAgC,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAWvD,MAAM,MAAM,GAA0B,CAAC,EACrC,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,GAAG,IAAI,EACR,EAAE,EAAE;IACH,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAChD,IAAI,GAAG,EAAE,CACV,CAAC;IACF,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAU,CAAC;I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,CAAC,EAAE;YACN,KAAK;SACN,KACG,IAAI,IAEP,gBAAgB,CACZ,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,qBAAqB,CAAC,KAAa;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACzC,CAAC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { View, ViewProps } from "react-native";
|
|
2
|
+
import { View, ViewProps, LayoutChangeEvent } from "react-native";
|
|
3
|
+
import { useDeepCompareEffect } from "../../utilities";
|
|
3
4
|
|
|
4
5
|
interface ZStackProps extends ViewProps {
|
|
5
6
|
reversed?: boolean;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
interface ChildSize {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ZStack: React.FC<ZStackProps> = ({
|
|
15
|
+
reversed,
|
|
16
|
+
children,
|
|
17
|
+
style,
|
|
18
|
+
...rest
|
|
19
|
+
}) => {
|
|
20
|
+
const [childSizes, setChildSizes] = React.useState<Map<number, ChildSize>>(
|
|
21
|
+
new Map()
|
|
22
|
+
);
|
|
23
|
+
const [maxChildWidth, setMaxChildWidth] = React.useState<number>();
|
|
24
|
+
const [maxChildHeight, setMaxChildHeight] = React.useState<number>();
|
|
25
|
+
|
|
26
|
+
const onChildLayout = React.useCallback(
|
|
27
|
+
(index: number, width: number, height: number) => {
|
|
28
|
+
const size: ChildSize = {
|
|
29
|
+
width: roundTo3DecimalPoints(width), // rounded to prevent infinte useEffect loop caused by floating point precision issues
|
|
30
|
+
height: roundTo3DecimalPoints(height),
|
|
31
|
+
};
|
|
32
|
+
setChildSizes(new Map(childSizes.set(index, size)));
|
|
33
|
+
},
|
|
34
|
+
[childSizes, setChildSizes]
|
|
35
|
+
);
|
|
36
|
+
|
|
9
37
|
const absoluteChildren = React.useMemo(() => {
|
|
10
38
|
let childrenArray = React.Children.toArray(
|
|
11
39
|
children
|
|
@@ -21,14 +49,63 @@ const ZStack: React.FC<ZStackProps> = ({ reversed, children, ...rest }) => {
|
|
|
21
49
|
child,
|
|
22
50
|
{
|
|
23
51
|
...props,
|
|
52
|
+
onLayout: (event: LayoutChangeEvent) => {
|
|
53
|
+
const layout = event.nativeEvent.layout;
|
|
54
|
+
|
|
55
|
+
const fullWidth = layout.x + layout.width;
|
|
56
|
+
const fullHeight = layout.y + layout.height;
|
|
57
|
+
onChildLayout(index, fullWidth, fullHeight);
|
|
58
|
+
|
|
59
|
+
props.onLayout?.(event);
|
|
60
|
+
},
|
|
61
|
+
key: index,
|
|
24
62
|
style: { position: "absolute", zIndex: index + 1, ...props.style },
|
|
25
63
|
},
|
|
26
64
|
props.children
|
|
27
65
|
);
|
|
28
66
|
});
|
|
29
|
-
}, [children, reversed]);
|
|
67
|
+
}, [children, reversed, onChildLayout]);
|
|
68
|
+
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
setChildSizes(new Map());
|
|
71
|
+
}, [absoluteChildren.length]);
|
|
72
|
+
|
|
73
|
+
const childSizeValues = Array.from(childSizes.values());
|
|
74
|
+
|
|
75
|
+
useDeepCompareEffect(() => {
|
|
76
|
+
let maxWidth = 0;
|
|
77
|
+
let maxHeight = 0;
|
|
78
|
+
|
|
79
|
+
childSizeValues.forEach(({ width, height }) => {
|
|
80
|
+
if (width > maxWidth) {
|
|
81
|
+
maxWidth = width;
|
|
82
|
+
}
|
|
83
|
+
if (height > maxHeight) {
|
|
84
|
+
maxHeight = height;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
30
87
|
|
|
31
|
-
|
|
88
|
+
setMaxChildWidth(maxWidth);
|
|
89
|
+
setMaxChildHeight(maxHeight);
|
|
90
|
+
}, [childSizeValues, setMaxChildWidth, setMaxChildHeight]);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<View
|
|
94
|
+
style={[
|
|
95
|
+
maxChildWidth && maxChildHeight
|
|
96
|
+
? { width: maxChildWidth, height: maxChildHeight }
|
|
97
|
+
: {},
|
|
98
|
+
style,
|
|
99
|
+
]}
|
|
100
|
+
{...rest}
|
|
101
|
+
>
|
|
102
|
+
{absoluteChildren}
|
|
103
|
+
</View>
|
|
104
|
+
);
|
|
32
105
|
};
|
|
33
106
|
|
|
107
|
+
function roundTo3DecimalPoints(value: number) {
|
|
108
|
+
return Math.round(value * 1000) / 1000;
|
|
109
|
+
}
|
|
110
|
+
|
|
34
111
|
export default ZStack;
|