mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-03-28 08:18:49 +08:00
[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:
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user