mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
progress css support for color and backgroundColor added
This commit is contained in:
@ -2,6 +2,9 @@
|
|||||||
import helper = require("../helper");
|
import helper = require("../helper");
|
||||||
import viewModule = require("ui/core/view");
|
import viewModule = require("ui/core/view");
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
|
import color = require("color");
|
||||||
|
import platform = require("platform");
|
||||||
|
|
||||||
// <snippet module="ui/progress" title="progress">
|
// <snippet module="ui/progress" title="progress">
|
||||||
// # Progress
|
// # Progress
|
||||||
// Using the progress view requires the Progress module.
|
// Using the progress view requires the Progress module.
|
||||||
@ -70,6 +73,31 @@ export function test_set_value_greater_than_max_should_set_value_to_max() {
|
|||||||
helper.buildUIAndRunTest(progress, testAction);
|
helper.buildUIAndRunTest(progress, testAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uncomment this when find way to check android Drawable color set by setColorFilter() method.
|
||||||
|
if (platform.device.os === platform.platformNames.ios) {
|
||||||
|
exports.test_set_color = function () {
|
||||||
|
var progress = new progressModule.Progress();
|
||||||
|
progress.color = new color.Color("red");
|
||||||
|
|
||||||
|
function testAction(views: Array<viewModule.View>) {
|
||||||
|
TKUnit.assertEqual(progress.color.ios.CGColor, progress.ios.progressTintColor.CGColor, "progress.color");
|
||||||
|
};
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(progress, testAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.test_set_backgroundColor = function () {
|
||||||
|
var progress = new progressModule.Progress();
|
||||||
|
progress.backgroundColor = new color.Color("red");
|
||||||
|
|
||||||
|
function testAction(views: Array<viewModule.View>) {
|
||||||
|
TKUnit.assertEqual(progress.backgroundColor.ios.CGColor, progress.ios.trackTintColor.CGColor, "progress.color");
|
||||||
|
};
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(progress, testAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function test_set_maxValue_should_adjust_value() {
|
export function test_set_maxValue_should_adjust_value() {
|
||||||
var progress = new progressModule.Progress();
|
var progress = new progressModule.Progress();
|
||||||
|
|
||||||
|
@ -505,6 +505,51 @@ export class SegmentedBarStyler implements definition.stylers.Styler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ProgressStyler implements definition.stylers.Styler {
|
||||||
|
private static setColorProperty(view: view.View, newValue: any) {
|
||||||
|
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||||
|
bar.getProgressDrawable().setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetColorProperty(view: view.View, nativeValue: number) {
|
||||||
|
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||||
|
bar.getProgressDrawable().clearColorFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static setBackgroundAndBorderProperty(view: view.View, newValue: any) {
|
||||||
|
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||||
|
var progressDrawable = <android.graphics.drawable.LayerDrawable>bar.getProgressDrawable();
|
||||||
|
|
||||||
|
if (progressDrawable.getNumberOfLayers && progressDrawable.getNumberOfLayers() > 0) {
|
||||||
|
var backgroundDrawable = progressDrawable.getDrawable(0);
|
||||||
|
if (backgroundDrawable) {
|
||||||
|
backgroundDrawable.setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetBackgroundAndBorderProperty(view: view.View, nativeValue: number) {
|
||||||
|
var bar = <android.widget.ProgressBar>view._nativeView;
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static registerHandlers() {
|
||||||
|
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||||
|
ProgressStyler.setColorProperty,
|
||||||
|
ProgressStyler.resetColorProperty), "Progress");
|
||||||
|
|
||||||
|
var borderHandler = new stylersCommon.StylePropertyChangedHandler(
|
||||||
|
ProgressStyler.setBackgroundAndBorderProperty,
|
||||||
|
ProgressStyler.resetBackgroundAndBorderProperty);
|
||||||
|
|
||||||
|
style.registerHandler(style.backgroundColorProperty, borderHandler, "Progress");
|
||||||
|
style.registerHandler(style.borderWidthProperty, borderHandler, "Progress");
|
||||||
|
style.registerHandler(style.borderColorProperty, borderHandler, "Progress");
|
||||||
|
style.registerHandler(style.borderRadiusProperty, borderHandler, "Progress");
|
||||||
|
style.registerHandler(style.backgroundInternalProperty, borderHandler, "Progress");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class SearchBarStyler implements definition.stylers.Styler {
|
export class SearchBarStyler implements definition.stylers.Styler {
|
||||||
|
|
||||||
private static getBackgroundColorProperty(view: view.View): any {
|
private static getBackgroundColorProperty(view: view.View): any {
|
||||||
@ -703,4 +748,5 @@ export function _registerDefaultStylers() {
|
|||||||
SearchBarStyler.registerHandlers();
|
SearchBarStyler.registerHandlers();
|
||||||
ActionBarStyler.registerHandlers();
|
ActionBarStyler.registerHandlers();
|
||||||
TabViewStyler.registerHandlers();
|
TabViewStyler.registerHandlers();
|
||||||
|
ProgressStyler.registerHandlers();
|
||||||
}
|
}
|
||||||
|
@ -394,6 +394,51 @@ export class SegmentedBarStyler implements definition.stylers.Styler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ProgressStyler implements definition.stylers.Styler {
|
||||||
|
//Text color methods
|
||||||
|
private static setColorProperty(view: view.View, newValue: any) {
|
||||||
|
var bar = <UIProgressView>view.ios;
|
||||||
|
bar.progressTintColor = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||||
|
var bar = <UIProgressView>view.ios;
|
||||||
|
bar.progressTintColor = nativeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static getNativeColorValue(view: view.View): any {
|
||||||
|
var bar = <UIProgressView>view.ios;
|
||||||
|
return bar.progressTintColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
||||||
|
var bar = <UIProgressView>view.ios;
|
||||||
|
bar.trackTintColor = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetBackgroundColorProperty(view: view.View, nativeValue: any) {
|
||||||
|
var bar = <UIProgressView>view.ios;
|
||||||
|
bar.trackTintColor = nativeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static getBackgroundColorProperty(view: view.View): any {
|
||||||
|
var bar = <UIProgressView>view.ios;
|
||||||
|
return bar.trackTintColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static registerHandlers() {
|
||||||
|
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||||
|
ProgressStyler.setColorProperty,
|
||||||
|
ProgressStyler.resetColorProperty,
|
||||||
|
ProgressStyler.getNativeColorValue), "Progress");
|
||||||
|
|
||||||
|
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||||
|
ProgressStyler.setBackgroundColorProperty,
|
||||||
|
ProgressStyler.resetBackgroundColorProperty,
|
||||||
|
ProgressStyler.getBackgroundColorProperty), "Progress");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class SearchBarStyler implements definition.stylers.Styler {
|
export class SearchBarStyler implements definition.stylers.Styler {
|
||||||
|
|
||||||
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
private static setBackgroundColorProperty(view: view.View, newValue: any) {
|
||||||
@ -547,4 +592,5 @@ export function _registerDefaultStylers() {
|
|||||||
SearchBarStyler.registerHandlers();
|
SearchBarStyler.registerHandlers();
|
||||||
ActionBarStyler.registerHandlers();
|
ActionBarStyler.registerHandlers();
|
||||||
TabViewStyler.registerHandlers();
|
TabViewStyler.registerHandlers();
|
||||||
|
ProgressStyler.registerHandlers();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user