[fix] ResizeObserve only on elements using 'onLayout' prop

Only observe nodes when the 'onLayout' prop is specified on the
element. Fixes performance regression for browsers that rely on
MutationObserver-based shim for ResizeObserver.

Fix #1128
Close #1129
This commit is contained in:
Charlie Croom
2018-10-09 16:51:29 -07:00
committed by Nicolas Gallagher
parent 1f3a77dada
commit d31bdf2cf8

View File

@@ -97,7 +97,9 @@ const applyLayout = Component => {
function componentDidMount() {
this._layoutState = emptyObject;
this._isMounted = true;
observe(this);
if (this.props.onLayout) {
observe(this);
}
}
);
@@ -116,7 +118,9 @@ const applyLayout = Component => {
componentWillUnmount,
function componentWillUnmount() {
this._isMounted = false;
unobserve(this);
if (this.props.onLayout) {
unobserve(this);
}
}
);