mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
getter in ListViewStyler for separatorColor
This commit is contained in:
@@ -9,6 +9,7 @@ import { Label } from "ui/label";
|
|||||||
import helper = require("../helper");
|
import helper = require("../helper");
|
||||||
import { Page } from "ui/page";
|
import { Page } from "ui/page";
|
||||||
import { View, KeyedTemplate } from "ui/core/view";
|
import { View, KeyedTemplate } from "ui/core/view";
|
||||||
|
import { separatorColorProperty } from "ui/styling/style";
|
||||||
|
|
||||||
// >> article-require-listview-module
|
// >> article-require-listview-module
|
||||||
import listViewModule = require("ui/list-view");
|
import listViewModule = require("ui/list-view");
|
||||||
@@ -698,6 +699,35 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
|
|||||||
TKUnit.assert(weakRef.get(), weakRef.get() + " died prematurely!");
|
TKUnit.assert(weakRef.get(), weakRef.get() + " died prematurely!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public test_separatorColor_setInCSS_is_respected() {
|
||||||
|
let listView = this.testView;
|
||||||
|
let items = ["John", "Joshua", "Gregory"];
|
||||||
|
listView.items = items;
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(listView, function (views) {
|
||||||
|
let page = views[1];
|
||||||
|
page.css = "ListView { separator-color: #FF0000; }";
|
||||||
|
|
||||||
|
TKUnit.assertEqual(listView.style.separatorColor.hex, "#FF0000", "separatorColor property");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_separatorColor_reset() {
|
||||||
|
let listView = this.testView;
|
||||||
|
let items = ["John", "Joshua", "Gregory"];
|
||||||
|
listView.items = items;
|
||||||
|
|
||||||
|
helper.buildUIAndRunTest(listView, function (views) {
|
||||||
|
let defaultsSeparatorColor = listView.style.separatorColor;
|
||||||
|
|
||||||
|
listView.style._setValue(separatorColorProperty, "#FF0000");
|
||||||
|
TKUnit.assertEqual(listView.style.separatorColor.hex, "#FF0000", "set separatorColor property");
|
||||||
|
|
||||||
|
listView.style._resetValue(separatorColorProperty);
|
||||||
|
TKUnit.assertEqual(listView.style.separatorColor, defaultsSeparatorColor, "reset separatorColor property");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private assertNoMemoryLeak(weakRef: WeakRef<listViewModule.ListView>) {
|
private assertNoMemoryLeak(weakRef: WeakRef<listViewModule.ListView>) {
|
||||||
this.tearDown();
|
this.tearDown();
|
||||||
TKUnit.waitUntilReady(() => {
|
TKUnit.waitUntilReady(() => {
|
||||||
|
|||||||
@@ -290,22 +290,37 @@ function ensureListViewAdapterClass() {
|
|||||||
|
|
||||||
export class ListViewStyler implements Styler {
|
export class ListViewStyler implements Styler {
|
||||||
// separator-color
|
// separator-color
|
||||||
|
private static getSeparatorColorProperty(view: viewModule.View): any {
|
||||||
|
let listView = <android.widget.ListView>view._nativeView;
|
||||||
|
return listView.getDivider();
|
||||||
|
}
|
||||||
|
|
||||||
private static setSeparatorColorProperty(view: viewModule.View, newValue: any) {
|
private static setSeparatorColorProperty(view: viewModule.View, newValue: any) {
|
||||||
let listView = <android.widget.ListView>view._nativeView;
|
let listView = <android.widget.ListView>view._nativeView;
|
||||||
|
|
||||||
|
if (newValue instanceof android.graphics.drawable.Drawable) {
|
||||||
|
listView.setDivider(newValue);
|
||||||
|
} else {
|
||||||
listView.setDivider(new android.graphics.drawable.ColorDrawable(newValue));
|
listView.setDivider(new android.graphics.drawable.ColorDrawable(newValue));
|
||||||
|
}
|
||||||
listView.setDividerHeight(1);
|
listView.setDividerHeight(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static resetSeparatorColorProperty(view: viewModule.View, nativeValue: any) {
|
private static resetSeparatorColorProperty(view: viewModule.View, nativeValue: any) {
|
||||||
let listView = <android.widget.ListView>view._nativeView;
|
let listView = <android.widget.ListView>view._nativeView;
|
||||||
|
|
||||||
|
if (nativeValue instanceof android.graphics.drawable.Drawable) {
|
||||||
|
listView.setDivider(nativeValue);
|
||||||
|
} else {
|
||||||
listView.setDivider(new android.graphics.drawable.ColorDrawable(nativeValue));
|
listView.setDivider(new android.graphics.drawable.ColorDrawable(nativeValue));
|
||||||
listView.setDividerHeight(1);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static registerHandlers() {
|
public static registerHandlers() {
|
||||||
registerHandler(separatorColorProperty, new StylePropertyChangedHandler(
|
registerHandler(separatorColorProperty, new StylePropertyChangedHandler(
|
||||||
ListViewStyler.setSeparatorColorProperty,
|
ListViewStyler.setSeparatorColorProperty,
|
||||||
ListViewStyler.resetSeparatorColorProperty), "ListView");
|
ListViewStyler.resetSeparatorColorProperty,
|
||||||
|
ListViewStyler.getSeparatorColorProperty), "ListView");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user