mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-03-26 09:14:15 +08:00
[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:
committed by
Nicolas Gallagher
parent
1f3a77dada
commit
d31bdf2cf8
@@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user