Skip to content

Commit ef288f9

Browse files
committed
fix(onlayout): fix onlayout trigger on text change
1 parent 28f5b8d commit ef288f9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/ViewWrapper.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const ViewWrapper = ({ name, style, children }: Props) => {
2020
<View
2121
ref={ref}
2222
style={style}
23-
onLayout={() => {
23+
onLayout={({ nativeEvent }) => {
24+
const element = state[name];
2425
if (mainViewRef && !state[name]) {
2526
ref.current?.measureLayout(mainViewRef, (_, y, _w, h) => {
2627
setState((s) => ({
@@ -34,6 +35,14 @@ const ViewWrapper = ({ name, style, children }: Props) => {
3435
},
3536
}));
3637
});
38+
} else if (element) {
39+
setState({
40+
...state,
41+
[name]: {
42+
...element,
43+
height: nativeEvent.layout.height,
44+
},
45+
});
3746
}
3847
}}
3948
>

0 commit comments

Comments
 (0)