From 31ed40c17ab6ff026dde65c786a3c8ad8e625b3b Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Wed, 20 Dec 2023 21:58:28 +0100 Subject: [PATCH] feat(core): new `defaultVisualState` property option to override 'normal' default visualState (#10440) --- packages/core/ui/button/index.android.ts | 2 +- packages/core/ui/core/view-base/index.ts | 9 +++++++++ packages/core/ui/core/view/view-common.ts | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/button/index.android.ts b/packages/core/ui/button/index.android.ts index 097efc734..869d47236 100644 --- a/packages/core/ui/button/index.android.ts +++ b/packages/core/ui/button/index.android.ts @@ -119,7 +119,7 @@ export class Button extends ButtonBase { switch (args.action) { case TouchAction.up: case TouchAction.cancel: - this._goToVisualState('normal'); + this._goToVisualState(this.defaultVisualState); break; case TouchAction.down: this._goToVisualState('highlighted'); diff --git a/packages/core/ui/core/view-base/index.ts b/packages/core/ui/core/view-base/index.ts index 79ca72c45..2d091fa28 100644 --- a/packages/core/ui/core/view-base/index.ts +++ b/packages/core/ui/core/view-base/index.ts @@ -380,6 +380,11 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition */ public sharedTransitionIgnore: boolean; + /** + * Default visual state, defaults to 'normal' + */ + public defaultVisualState: string = 'normal'; + public _domId: number; public _context: any /* android.content.Context */; public _isAddedToNativeVisualTree: boolean; @@ -1231,6 +1236,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition view._isAddedToNativeVisualTree = false; } + public get visualState() { + return this._visualState; + } + public _goToVisualState(state: string) { if (Trace.isEnabled()) { Trace.write(this + ' going to state: ' + state, Trace.categories.Style); diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index ad3e3cf26..83289f7ee 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -1192,12 +1192,24 @@ export const originYProperty = new Property({ }); originYProperty.register(ViewCommon); +export const defaultVisualStateProperty = new Property({ + name: 'defaultVisualState', + defaultValue: 'normal', + valueChanged(this: void, target, oldValue, newValue): void { + target.defaultVisualState = newValue || 'normal'; + if (!target.visualState || target.visualState === oldValue) { + target._goToVisualState(target.defaultVisualState); + } + }, +}); +defaultVisualStateProperty.register(ViewCommon); + export const isEnabledProperty = new Property({ name: 'isEnabled', defaultValue: true, valueConverter: booleanConverter, valueChanged(this: void, target, oldValue, newValue): void { - target._goToVisualState(newValue ? 'normal' : 'disabled'); + target._goToVisualState(newValue ? target.defaultVisualState : 'disabled'); }, }); isEnabledProperty.register(ViewCommon);