[fix] onLayout timing without ResizeObserver

onLayout is called after the component is mounted to the DOM. This makes
both the fallback and ResizeObserver code path behave the same as React
Native.

Fix #911
Fix #941
Close #939
This commit is contained in:
Nicolas Gallagher
2018-05-08 12:55:35 -07:00
parent ee5e80064f
commit dcdf1468f9

View File

@@ -55,9 +55,10 @@ const observe = instance => {
node._onLayoutId = id;
resizeObserver.observe(node);
} else {
const id = guid();
instance._onLayoutId = id;
instance._handleLayout();
setTimeout(() => {
instance._handleLayout();
}, 0);
}
};
@@ -105,8 +106,6 @@ const applyLayout = Component => {
observe(this);
} else if (!this.props.onLayout && prevProps.onLayout) {
unobserve(this);
} else if (!resizeObserver) {
this._handleLayout();
}
}
);
@@ -123,10 +122,8 @@ const applyLayout = Component => {
const layout = this._layoutState;
const { onLayout } = this.props;
if (onLayout) {
if (this._isMounted && onLayout) {
this.measure((x, y, width, height) => {
if (!this._isMounted) return;
if (
layout.x !== x ||
layout.y !== y ||