feat(core): new defaultVisualState property option to override 'normal' default visualState (#10440)

This commit is contained in:
farfromrefuge
2023-12-20 21:58:28 +01:00
committed by GitHub
parent c5561d60df
commit 31ed40c17a
3 changed files with 23 additions and 2 deletions

View File

@@ -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');

View File

@@ -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);

View File

@@ -1192,12 +1192,24 @@ export const originYProperty = new Property<ViewCommon, number>({
});
originYProperty.register(ViewCommon);
export const defaultVisualStateProperty = new Property<ViewCommon, string>({
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<ViewCommon, boolean>({
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);