fix(core): allow View subclass to force onLayoutChangeListener (#9886)

This commit is contained in:
farfromrefuge
2022-04-30 19:41:32 +02:00
committed by GitHub
parent 647ed5cf7d
commit 6f68b2f78d

View File

@@ -349,7 +349,7 @@ export class View extends ViewCommon {
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;
// Remove native listener only if there are no more user listeners for LayoutChanged event
if (this.isLoaded && this.layoutChangeListenerIsSet && isLayoutEvent && !this.hasListeners(ViewCommon.layoutChangedEvent)) {
if (this.isLoaded && this.layoutChangeListenerIsSet && isLayoutEvent && !this.needsOnLayoutChangeListener()) {
this.nativeViewProtected.removeOnLayoutChangeListener(this.layoutChangeListener);
this.layoutChangeListenerIsSet = false;
}
@@ -468,11 +468,15 @@ export class View extends ViewCommon {
super.initNativeView();
this._isClickable = this.nativeViewProtected.isClickable();
if (this.hasListeners(ViewCommon.layoutChangedEvent)) {
if (this.needsOnLayoutChangeListener()) {
this.setOnLayoutChangeListener();
}
}
public needsOnLayoutChangeListener() {
return this.hasListeners(ViewCommon.layoutChangedEvent);
}
public disposeNativeView(): void {
super.disposeNativeView();