mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(core): new defaultVisualState property option to override 'normal' default visualState (#10440)
This commit is contained in:
@@ -119,7 +119,7 @@ export class Button extends ButtonBase {
|
|||||||
switch (args.action) {
|
switch (args.action) {
|
||||||
case TouchAction.up:
|
case TouchAction.up:
|
||||||
case TouchAction.cancel:
|
case TouchAction.cancel:
|
||||||
this._goToVisualState('normal');
|
this._goToVisualState(this.defaultVisualState);
|
||||||
break;
|
break;
|
||||||
case TouchAction.down:
|
case TouchAction.down:
|
||||||
this._goToVisualState('highlighted');
|
this._goToVisualState('highlighted');
|
||||||
|
|||||||
@@ -380,6 +380,11 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
|||||||
*/
|
*/
|
||||||
public sharedTransitionIgnore: boolean;
|
public sharedTransitionIgnore: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default visual state, defaults to 'normal'
|
||||||
|
*/
|
||||||
|
public defaultVisualState: string = 'normal';
|
||||||
|
|
||||||
public _domId: number;
|
public _domId: number;
|
||||||
public _context: any /* android.content.Context */;
|
public _context: any /* android.content.Context */;
|
||||||
public _isAddedToNativeVisualTree: boolean;
|
public _isAddedToNativeVisualTree: boolean;
|
||||||
@@ -1231,6 +1236,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
|||||||
view._isAddedToNativeVisualTree = false;
|
view._isAddedToNativeVisualTree = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get visualState() {
|
||||||
|
return this._visualState;
|
||||||
|
}
|
||||||
|
|
||||||
public _goToVisualState(state: string) {
|
public _goToVisualState(state: string) {
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(this + ' going to state: ' + state, Trace.categories.Style);
|
Trace.write(this + ' going to state: ' + state, Trace.categories.Style);
|
||||||
|
|||||||
@@ -1192,12 +1192,24 @@ export const originYProperty = new Property<ViewCommon, number>({
|
|||||||
});
|
});
|
||||||
originYProperty.register(ViewCommon);
|
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>({
|
export const isEnabledProperty = new Property<ViewCommon, boolean>({
|
||||||
name: 'isEnabled',
|
name: 'isEnabled',
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
valueConverter: booleanConverter,
|
valueConverter: booleanConverter,
|
||||||
valueChanged(this: void, target, oldValue, newValue): void {
|
valueChanged(this: void, target, oldValue, newValue): void {
|
||||||
target._goToVisualState(newValue ? 'normal' : 'disabled');
|
target._goToVisualState(newValue ? target.defaultVisualState : 'disabled');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
isEnabledProperty.register(ViewCommon);
|
isEnabledProperty.register(ViewCommon);
|
||||||
|
|||||||
Reference in New Issue
Block a user