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(() => {
|
||||||
@@ -864,18 +894,18 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
|
|||||||
TKUnit.wait(0.05);
|
TKUnit.wait(0.05);
|
||||||
|
|
||||||
// Forward
|
// Forward
|
||||||
for(let i = 0, length = listView.items.length; i < length; i++){
|
for (let i = 0, length = listView.items.length; i < length; i++) {
|
||||||
listView.scrollToIndex(i);
|
listView.scrollToIndex(i);
|
||||||
TKUnit.wait(0.05);
|
TKUnit.wait(0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back
|
// Back
|
||||||
for(let i = listView.items.length - 1; i >= 0; i--){
|
for (let i = listView.items.length - 1; i >= 0; i--) {
|
||||||
listView.scrollToIndex(i);
|
listView.scrollToIndex(i);
|
||||||
TKUnit.wait(0.05);
|
TKUnit.wait(0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listView.android){
|
if (listView.android) {
|
||||||
//(<any>listView)._dumpRealizedTemplates();
|
//(<any>listView)._dumpRealizedTemplates();
|
||||||
let realizedItems = <Map<android.view.View, View>>(<any>listView)._realizedItems;
|
let realizedItems = <Map<android.view.View, View>>(<any>listView)._realizedItems;
|
||||||
TKUnit.assertTrue(realizedItems.size <= 6, 'Realized items must be 6 or less');
|
TKUnit.assertTrue(realizedItems.size <= 6, 'Realized items must be 6 or less');
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import stackLayout = require("ui/layouts/stack-layout");
|
|||||||
import proxy = require("ui/core/proxy");
|
import proxy = require("ui/core/proxy");
|
||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import definition = require("ui/list-view");
|
import definition = require("ui/list-view");
|
||||||
import {ProxyViewContainer} from "ui/proxy-view-container";
|
import { ProxyViewContainer } from "ui/proxy-view-container";
|
||||||
import * as layoutBase from "ui/layouts/layout-base";
|
import * as layoutBase from "ui/layouts/layout-base";
|
||||||
import * as colorModule from "color";
|
import * as colorModule from "color";
|
||||||
import { separatorColorProperty, registerHandler, Styler, StylePropertyChangedHandler } from "ui/styling/style";
|
import { separatorColorProperty, registerHandler, Styler, StylePropertyChangedHandler } from "ui/styling/style";
|
||||||
@@ -120,7 +120,7 @@ export class ListView extends common.ListView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public _dumpRealizedTemplates(){
|
public _dumpRealizedTemplates() {
|
||||||
console.log(`Realized Templates:`);
|
console.log(`Realized Templates:`);
|
||||||
this._realizedTemplates.forEach((value, index, map) => {
|
this._realizedTemplates.forEach((value, index, map) => {
|
||||||
console.log(`\t${index}:`);
|
console.log(`\t${index}:`);
|
||||||
@@ -149,11 +149,11 @@ export class ListView extends common.ListView {
|
|||||||
|
|
||||||
public _onItemTemplatesPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onItemTemplatesPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
this._itemTemplatesInternal = new Array<viewModule.KeyedTemplate>(this._defaultTemplate);
|
this._itemTemplatesInternal = new Array<viewModule.KeyedTemplate>(this._defaultTemplate);
|
||||||
if (data.newValue){
|
if (data.newValue) {
|
||||||
this._itemTemplatesInternal = this._itemTemplatesInternal.concat(data.newValue);
|
this._itemTemplatesInternal = this._itemTemplatesInternal.concat(data.newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.android){
|
if (this.android) {
|
||||||
ensureListViewAdapterClass();
|
ensureListViewAdapterClass();
|
||||||
this.android.setAdapter(new ListViewAdapterClass(this));
|
this.android.setAdapter(new ListViewAdapterClass(this));
|
||||||
}
|
}
|
||||||
@@ -224,9 +224,9 @@ function ensureListViewAdapterClass() {
|
|||||||
// Recycle an existing view or create a new one if needed.
|
// Recycle an existing view or create a new one if needed.
|
||||||
let template = this._listView._getItemTemplate(index);
|
let template = this._listView._getItemTemplate(index);
|
||||||
let view: viewModule.View;
|
let view: viewModule.View;
|
||||||
if (convertView){
|
if (convertView) {
|
||||||
view = this._listView._realizedTemplates.get(template.key).get(convertView);
|
view = this._listView._realizedTemplates.get(template.key).get(convertView);
|
||||||
if (!view){
|
if (!view) {
|
||||||
throw new Error(`There is no entry with key '${convertView}' in the realized views cache for template with key'${template.key}'.`);
|
throw new Error(`There is no entry with key '${convertView}' in the realized views cache for template with key'${template.key}'.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ function ensureListViewAdapterClass() {
|
|||||||
|
|
||||||
// Cache the view for recycling
|
// Cache the view for recycling
|
||||||
let realizedItemsForTemplateKey = this._listView._realizedTemplates.get(template.key);
|
let realizedItemsForTemplateKey = this._listView._realizedTemplates.get(template.key);
|
||||||
if (!realizedItemsForTemplateKey){
|
if (!realizedItemsForTemplateKey) {
|
||||||
realizedItemsForTemplateKey = new Map<android.view.View, viewModule.View>();
|
realizedItemsForTemplateKey = new Map<android.view.View, viewModule.View>();
|
||||||
this._listView._realizedTemplates.set(template.key, realizedItemsForTemplateKey);
|
this._listView._realizedTemplates.set(template.key, realizedItemsForTemplateKey);
|
||||||
}
|
}
|
||||||
@@ -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