mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(core): allow View subclass to force onLayoutChangeListener (#9886)
This commit is contained in:
@@ -349,7 +349,7 @@ export class View extends ViewCommon {
|
|||||||
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;
|
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
|
// 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.nativeViewProtected.removeOnLayoutChangeListener(this.layoutChangeListener);
|
||||||
this.layoutChangeListenerIsSet = false;
|
this.layoutChangeListenerIsSet = false;
|
||||||
}
|
}
|
||||||
@@ -468,11 +468,15 @@ export class View extends ViewCommon {
|
|||||||
super.initNativeView();
|
super.initNativeView();
|
||||||
this._isClickable = this.nativeViewProtected.isClickable();
|
this._isClickable = this.nativeViewProtected.isClickable();
|
||||||
|
|
||||||
if (this.hasListeners(ViewCommon.layoutChangedEvent)) {
|
if (this.needsOnLayoutChangeListener()) {
|
||||||
this.setOnLayoutChangeListener();
|
this.setOnLayoutChangeListener();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public needsOnLayoutChangeListener() {
|
||||||
|
return this.hasListeners(ViewCommon.layoutChangedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
public disposeNativeView(): void {
|
public disposeNativeView(): void {
|
||||||
super.disposeNativeView();
|
super.disposeNativeView();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user