From e6beb1d8165f8c84b8a8f4632d10fed31c1ad68a Mon Sep 17 00:00:00 2001 From: Dimitris-Rafail Katsampas Date: Wed, 29 Jan 2025 21:26:59 +0200 Subject: [PATCH] fix(core): pseudo-class handlers failing to unsubscribe listeners (#10680) --- packages/core/ui/button/index.android.ts | 1 + packages/core/ui/button/index.ios.ts | 32 ++++++++++++------- .../ui/core/control-state-change/index.ios.ts | 9 +++--- packages/core/ui/core/view/view-common.ts | 22 +++++++------ .../editable-text-base-common.ts | 16 +++++++--- packages/core/ui/styling/style-scope.ts | 4 +-- 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/packages/core/ui/button/index.android.ts b/packages/core/ui/button/index.android.ts index 2660d8c43..09aa8ba98 100644 --- a/packages/core/ui/button/index.android.ts +++ b/packages/core/ui/button/index.android.ts @@ -103,6 +103,7 @@ export class Button extends ButtonBase { this.on(GestureTypes[GestureTypes.touch], onButtonStateChange); } else { this.off(GestureTypes[GestureTypes.touch], onButtonStateChange); + this._removeVisualState('highlighted'); } } diff --git a/packages/core/ui/button/index.ios.ts b/packages/core/ui/button/index.ios.ts index a5f87a780..753b1e136 100644 --- a/packages/core/ui/button/index.ios.ts +++ b/packages/core/ui/button/index.ios.ts @@ -29,6 +29,12 @@ export class Button extends ButtonBase { public disposeNativeView(): void { this._tapHandler = null; + + if (this._stateChangedHandler) { + this._stateChangedHandler.stop(); + this._stateChangedHandler = null; + } + super.disposeNativeView(); } @@ -37,28 +43,32 @@ export class Button extends ButtonBase { return this.nativeViewProtected; } - public onUnloaded() { - super.onUnloaded(); - if (this._stateChangedHandler) { - this._stateChangedHandler.stop(); - } - } - @PseudoClassHandler('normal', 'highlighted', 'pressed', 'active') _updateButtonStateChangeHandler(subscribe: boolean) { if (subscribe) { if (!this._stateChangedHandler) { + const viewRef = new WeakRef