mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
stylers removed
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import utils = require("utils/utils")
|
||||
import styling = require("ui/styling");
|
||||
import style = require("ui/styling/style");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
function onCheckedPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var swtch = <Switch>data.object;
|
||||
@@ -42,3 +45,50 @@ export class Switch extends common.Switch {
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class SwitchStyler implements style.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 style.StylePropertyChangedHandler(
|
||||
SwitchStyler.setColorProperty,
|
||||
SwitchStyler.resetColorProperty), "Switch");
|
||||
|
||||
style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(
|
||||
SwitchStyler.setBackgroundAndBorderProperty,
|
||||
SwitchStyler.resetBackgroundAndBorderProperty), "Switch");
|
||||
|
||||
style.registerHandler(style.borderWidthProperty, style.ignorePropertyHandler, "Switch");
|
||||
style.registerHandler(style.borderColorProperty, style.ignorePropertyHandler, "Switch");
|
||||
style.registerHandler(style.borderRadiusProperty, style.ignorePropertyHandler, "Switch");
|
||||
style.registerHandler(style.backgroundInternalProperty, style.ignorePropertyHandler, "Switch");
|
||||
}
|
||||
}
|
||||
|
||||
SwitchStyler.registerHandlers();
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import * as utilsModule from "utils/utils";
|
||||
import styling = require("ui/styling");
|
||||
import style = require("ui/styling/style");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
function onCheckedPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var swtch = <Switch>data.object;
|
||||
@@ -63,3 +66,52 @@ export class Switch extends common.Switch {
|
||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||
}
|
||||
}
|
||||
|
||||
export class SwitchStyler implements style.Styler {
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.thumbTintColor = newValue;
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.thumbTintColor = nativeValue;
|
||||
}
|
||||
|
||||
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.onTintColor = view.backgroundColor.ios;
|
||||
}
|
||||
|
||||
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
|
||||
var sw = <UISwitch>view.ios;
|
||||
sw.onTintColor = nativeValue;
|
||||
}
|
||||
|
||||
private static getBackgroundColorProperty(view: view.View): any {
|
||||
var sw = <UISwitch>view.ios;
|
||||
return sw.onTintColor;
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
|
||||
SwitchStyler.setColorProperty,
|
||||
SwitchStyler.resetColorProperty,
|
||||
SwitchStyler.getNativeColorValue), "Switch");
|
||||
|
||||
style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(
|
||||
SwitchStyler.setBackgroundColorProperty,
|
||||
SwitchStyler.resetBackgroundColorProperty,
|
||||
SwitchStyler.getBackgroundColorProperty), "Switch");
|
||||
|
||||
// Ignore the default backgroundInternalProperty handler
|
||||
style.registerHandler(style.backgroundInternalProperty, style.ignorePropertyHandler, "Switch");
|
||||
}
|
||||
}
|
||||
|
||||
SwitchStyler.registerHandlers();
|
||||
|
||||
Reference in New Issue
Block a user