From 6f68b2f78dc5994191a5f9a12402d7b2fe9f8041 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Sat, 30 Apr 2022 19:41:32 +0200 Subject: [PATCH] fix(core): allow View subclass to force onLayoutChangeListener (#9886) --- packages/core/ui/core/view/index.android.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index 30ac9b62a..5528f4b5a 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -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();