Skip to content

Commit 0816c40

Browse files
committed
[fix] add 'target' to onLayout nativeEvent
1 parent 2756ab4 commit 0816c40

File tree

1 file changed

+12
-7
lines changed
  • packages/react-native-web/src/modules/applyLayout

1 file changed

+12
-7
lines changed

packages/react-native-web/src/modules/applyLayout/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (canUseDOM) {
2222
if (typeof window.ResizeObserver !== 'undefined') {
2323
resizeObserver = new window.ResizeObserver(entries => {
2424
entries.forEach(({ target }) => {
25-
const instance = registry[target._onLayoutId];
25+
const instance = registry[target._layoutId];
2626
instance && instance._handleLayout();
2727
});
2828
});
@@ -52,24 +52,24 @@ const observe = instance => {
5252

5353
if (resizeObserver) {
5454
const node = findNodeHandle(instance);
55-
node._onLayoutId = id;
55+
node._layoutId = id;
5656
resizeObserver.observe(node);
5757
} else {
58-
instance._onLayoutId = id;
58+
instance._layoutId = id;
5959
setTimeout(() => {
6060
instance._handleLayout();
6161
}, 0);
6262
}
6363
};
6464

6565
const unobserve = instance => {
66-
delete registry[instance._onLayoutId];
66+
delete registry[instance._layoutId];
6767
if (resizeObserver) {
6868
const node = findNodeHandle(instance);
69-
delete node._onLayoutId;
69+
delete node._layoutId;
7070
resizeObserver.unobserve(node);
7171
} else {
72-
delete instance._onLayoutId;
72+
delete instance._layoutId;
7373
}
7474
};
7575

@@ -131,7 +131,12 @@ const applyLayout = Component => {
131131
layout.height !== height
132132
) {
133133
this._layoutState = { x, y, width, height };
134-
const nativeEvent = { layout: this._layoutState };
134+
const nativeEvent = {
135+
layout: this._layoutState,
136+
get target() {
137+
return findNodeHandle(this);
138+
}
139+
};
135140
onLayout({ nativeEvent, timeStamp: Date.now() });
136141
}
137142
});

0 commit comments

Comments
 (0)