mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
SwitchStylers added
This commit is contained in:
@ -550,6 +550,52 @@ export class ProgressStyler implements definition.stylers.Styler {
|
||||
}
|
||||
}
|
||||
|
||||
export class SwitchStyler implements definition.stylers.Styler {
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var sw = <android.widget.Switch>view._nativeView;
|
||||
|
||||
var drawable = <android.graphics.drawable.StateListDrawable>sw.getThumbDrawable();
|
||||
if (drawable) {
|
||||
drawable.setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: number) {
|
||||
var sw = <android.widget.Switch>view._nativeView;
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
private static setBackgroundAndBorderProperty(view: view.View, newValue: any) {
|
||||
var sw = <android.widget.Switch>view._nativeView;
|
||||
|
||||
var drawable = <android.graphics.drawable.StateListDrawable>sw.getTrackDrawable();
|
||||
if (drawable) {
|
||||
drawable.setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
private static resetBackgroundAndBorderProperty(view: view.View, nativeValue: number) {
|
||||
var sw = <android.widget.Switch>view._nativeView;
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||
SwitchStyler.setColorProperty,
|
||||
SwitchStyler.resetColorProperty), "Switch");
|
||||
|
||||
var borderHandler = new stylersCommon.StylePropertyChangedHandler(
|
||||
SwitchStyler.setBackgroundAndBorderProperty,
|
||||
SwitchStyler.resetBackgroundAndBorderProperty);
|
||||
|
||||
style.registerHandler(style.backgroundColorProperty, borderHandler, "Switch");
|
||||
style.registerHandler(style.borderWidthProperty, borderHandler, "Switch");
|
||||
style.registerHandler(style.borderColorProperty, borderHandler, "Switch");
|
||||
style.registerHandler(style.borderRadiusProperty, borderHandler, "Switch");
|
||||
style.registerHandler(style.backgroundInternalProperty, borderHandler, "Switch");
|
||||
}
|
||||
}
|
||||
|
||||
export class SearchBarStyler implements definition.stylers.Styler {
|
||||
|
||||
private static getBackgroundColorProperty(view: view.View): any {
|
||||
@ -749,4 +795,5 @@ export function _registerDefaultStylers() {
|
||||
ActionBarStyler.registerHandlers();
|
||||
TabViewStyler.registerHandlers();
|
||||
ProgressStyler.registerHandlers();
|
||||
SwitchStyler.registerHandlers();
|
||||
}
|
||||
|
@ -439,6 +439,53 @@ export class ProgressStyler implements definition.stylers.Styler {
|
||||
}
|
||||
}
|
||||
|
||||
export class SwitchStyler implements definition.stylers.Styler {
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.thumbTintColor = UIColor.alloc().initWithCGColor((<UIColor>newValue).CGColor);
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.thumbTintColor = UIColor.alloc().initWithCGColor((<UIColor>nativeValue).CGColor);
|
||||
}
|
||||
|
||||
private static getNativeColorValue(view: view.View): any {
|
||||
var sw = <UISwitch>view.ios;
|
||||
return sw.thumbTintColor;
|
||||
}
|
||||
|
||||
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.tintColor = UIColor.alloc().initWithCGColor((<UIColor>newValue).CGColor);
|
||||
}
|
||||
|
||||
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.tintColor = UIColor.alloc().initWithCGColor((<UIColor>nativeValue).CGColor);
|
||||
}
|
||||
|
||||
private static getBackgroundColorProperty(view: view.View): any {
|
||||
var sw = <UISwitch>view.ios;
|
||||
return sw.tintColor;
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||
SwitchStyler.setColorProperty,
|
||||
SwitchStyler.resetColorProperty,
|
||||
SwitchStyler.getNativeColorValue), "Switch");
|
||||
|
||||
var bkgHandler = new stylersCommon.StylePropertyChangedHandler(
|
||||
SwitchStyler.setBackgroundColorProperty,
|
||||
SwitchStyler.resetBackgroundColorProperty,
|
||||
SwitchStyler.getBackgroundColorProperty);
|
||||
|
||||
style.registerHandler(style.backgroundColorProperty, bkgHandler, "Switch");
|
||||
style.registerHandler(style.backgroundInternalProperty, bkgHandler, "Switch");
|
||||
}
|
||||
}
|
||||
|
||||
export class SearchBarStyler implements definition.stylers.Styler {
|
||||
|
||||
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
||||
@ -593,4 +640,5 @@ export function _registerDefaultStylers() {
|
||||
ActionBarStyler.registerHandlers();
|
||||
TabViewStyler.registerHandlers();
|
||||
ProgressStyler.registerHandlers();
|
||||
SwitchStyler.registerHandlers();
|
||||
}
|
||||
|
Reference in New Issue
Block a user