Skip to content
This repository was archived by the owner on Jan 30, 2021. It is now read-only.

Commit 81fd1e7

Browse files
committed
Properly call onLayout prop
If an onLayout prop was passed, it was called incorrectly before: without an event argument or asynchronously, which made it unusable. This fixes the onLayout prop to be called synchronously only when the event fires.
1 parent bf7405b commit 81fd1e7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const statusBarHeight = isLandscape => {
106106
return _customStatusBarHidden ? 0 : 20;
107107
}
108108

109-
return (isLandscape || _customStatusBarHidden) ? 0 : 20;
109+
return isLandscape || _customStatusBarHidden ? 0 : 20;
110110
};
111111

112112
const doubleFromPercentString = percent => {
@@ -143,7 +143,7 @@ class SafeView extends Component {
143143
componentDidMount() {
144144
this._isMounted = true;
145145
InteractionManager.runAfterInteractions(() => {
146-
this._onLayout();
146+
this._updateMeasurements();
147147
});
148148
}
149149

@@ -152,7 +152,7 @@ class SafeView extends Component {
152152
}
153153

154154
componentDidUpdate() {
155-
this._onLayout();
155+
this._updateMeasurements();
156156
}
157157

158158
render() {
@@ -165,13 +165,19 @@ class SafeView extends Component {
165165
ref={c => (this.view = c)}
166166
pointerEvents="box-none"
167167
{...props}
168-
onLayout={this._onLayout}
168+
onLayout={this._handleLayout}
169169
style={safeAreaStyle}
170170
/>
171171
);
172172
}
173173

174-
_onLayout = (...args) => {
174+
_handleLayout = e => {
175+
if (this.props.onLayout) this.props.onLayout(e);
176+
177+
this._updateMeasurements();
178+
};
179+
180+
_updateMeasurements = () => {
175181
if (!this._isMounted) return;
176182
if (!this.view) return;
177183

@@ -217,8 +223,6 @@ class SafeView extends Component {
217223
viewWidth: winWidth,
218224
viewHeight: winHeight,
219225
});
220-
221-
if (this.props.onLayout) this.props.onLayout(...args);
222226
});
223227
};
224228

0 commit comments

Comments
 (0)