mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Merge pull request #3233 from NativeScript/zhecheva/separator-color
separatorColor property of ListView can be set in CSS
This commit is contained in:
@ -205,10 +205,10 @@ export class ListView extends view.View implements definition.ListView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get separatorColor(): color.Color {
|
get separatorColor(): color.Color {
|
||||||
return this._getValue(ListView.separatorColorProperty);
|
return this.style._getValue(ListView.separatorColorProperty);
|
||||||
}
|
}
|
||||||
set separatorColor(value: color.Color) {
|
set separatorColor(value: color.Color) {
|
||||||
this._setValue(ListView.separatorColorProperty,
|
this.style._setValue(ListView.separatorColorProperty,
|
||||||
value instanceof color.Color ? value : new color.Color(<any>value));
|
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ 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";
|
||||||
|
|
||||||
let color: typeof colorModule;
|
let color: typeof colorModule;
|
||||||
function ensureColor() {
|
function ensureColor() {
|
||||||
@ -23,16 +24,16 @@ let ITEMTAP = common.ListView.itemTapEvent;
|
|||||||
global.moduleMerge(common, exports);
|
global.moduleMerge(common, exports);
|
||||||
|
|
||||||
function onSeparatorColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
function onSeparatorColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
let bar = <ListView>data.object;
|
let listView = <ListView>data.object;
|
||||||
if (!bar.android) {
|
if (!listView.android) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureColor();
|
ensureColor();
|
||||||
|
|
||||||
if (data.newValue instanceof color.Color) {
|
if (data.newValue instanceof color.Color) {
|
||||||
bar.android.setDivider(new android.graphics.drawable.ColorDrawable(data.newValue.android));
|
listView.android.setDivider(new android.graphics.drawable.ColorDrawable(data.newValue.android));
|
||||||
bar.android.setDividerHeight(1);
|
listView.android.setDividerHeight(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,4 +286,27 @@ function ensureListViewAdapterClass() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ListViewAdapterClass = ListViewAdapter;
|
ListViewAdapterClass = ListViewAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ListViewStyler implements Styler {
|
||||||
|
// separator-color
|
||||||
|
private static setSeparatorColorProperty(view: viewModule.View, newValue: any) {
|
||||||
|
let listView = <android.widget.ListView>view._nativeView;
|
||||||
|
listView.setDivider(new android.graphics.drawable.ColorDrawable(newValue));
|
||||||
|
listView.setDividerHeight(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetSeparatorColorProperty(view: viewModule.View, nativeValue: any) {
|
||||||
|
let listView = <android.widget.ListView>view._nativeView;
|
||||||
|
listView.setDivider(new android.graphics.drawable.ColorDrawable(nativeValue));
|
||||||
|
listView.setDividerHeight(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static registerHandlers() {
|
||||||
|
registerHandler(separatorColorProperty, new StylePropertyChangedHandler(
|
||||||
|
ListViewStyler.setSeparatorColorProperty,
|
||||||
|
ListViewStyler.resetSeparatorColorProperty), "ListView");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ListViewStyler.registerHandlers();
|
@ -8,6 +8,7 @@ import {StackLayout} from "ui/layouts/stack-layout";
|
|||||||
import {ProxyViewContainer} from "ui/proxy-view-container";
|
import {ProxyViewContainer} from "ui/proxy-view-container";
|
||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import * as colorModule from "color";
|
import * as colorModule from "color";
|
||||||
|
import { separatorColorProperty, registerHandler, Styler, StylePropertyChangedHandler } from "ui/styling/style";
|
||||||
|
|
||||||
var color: typeof colorModule;
|
var color: typeof colorModule;
|
||||||
function ensureColor() {
|
function ensureColor() {
|
||||||
@ -193,15 +194,15 @@ class UITableViewRowHeightDelegateImpl extends NSObject implements UITableViewDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onSeparatorColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
function onSeparatorColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var bar = <ListView>data.object;
|
var listView = <ListView>data.object;
|
||||||
if (!bar.ios) {
|
if (!listView.ios) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureColor();
|
ensureColor();
|
||||||
|
|
||||||
if (data.newValue instanceof color.Color) {
|
if (data.newValue instanceof color.Color) {
|
||||||
bar.ios.separatorColor = data.newValue.ios;
|
listView.ios.separatorColor = data.newValue.ios;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,4 +405,31 @@ export class ListView extends common.ListView {
|
|||||||
view.parent._removeView(view);
|
view.parent._removeView(view);
|
||||||
this._map.delete(cell);
|
this._map.delete(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ListViewStyler implements Styler {
|
||||||
|
// separator-color
|
||||||
|
private static setSeparatorColorProperty(view: view.View, newValue: any) {
|
||||||
|
let tableView = <UITableView>view._nativeView;
|
||||||
|
tableView.separatorColor = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetSeparatorColorProperty(view: view.View, nativeValue: any) {
|
||||||
|
let tableView = <UITableView>view._nativeView;
|
||||||
|
tableView.separatorColor = nativeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static getSeparatorColorProperty(view: view.View): any {
|
||||||
|
let tableView = <UITableView>view._nativeView;
|
||||||
|
return tableView.separatorColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static registerHandlers() {
|
||||||
|
registerHandler(separatorColorProperty, new StylePropertyChangedHandler(
|
||||||
|
ListViewStyler.setSeparatorColorProperty,
|
||||||
|
ListViewStyler.resetSeparatorColorProperty,
|
||||||
|
ListViewStyler.getSeparatorColorProperty), "ListView");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ListViewStyler.registerHandlers();
|
5
tns-core-modules/ui/styling/style.d.ts
vendored
5
tns-core-modules/ui/styling/style.d.ts
vendored
@ -108,6 +108,9 @@ declare module "ui/styling/style" {
|
|||||||
public selectedTabTextColor: Color;
|
public selectedTabTextColor: Color;
|
||||||
public androidSelectedTabHighlightColor: Color;
|
public androidSelectedTabHighlightColor: Color;
|
||||||
|
|
||||||
|
// ListView-specific props
|
||||||
|
public separatorColor : Color;
|
||||||
|
|
||||||
//SegmentedBar-specific props
|
//SegmentedBar-specific props
|
||||||
public selectedBackgroundColor: Color;
|
public selectedBackgroundColor: Color;
|
||||||
|
|
||||||
@ -189,6 +192,8 @@ declare module "ui/styling/style" {
|
|||||||
export var statusBarStyleProperty: styleProperty.Property;
|
export var statusBarStyleProperty: styleProperty.Property;
|
||||||
export var androidStatusBarBackgroundProperty: styleProperty.Property;
|
export var androidStatusBarBackgroundProperty: styleProperty.Property;
|
||||||
|
|
||||||
|
export var separatorColorProperty: styleProperty.Property;
|
||||||
|
|
||||||
// Helper property holding most layout related properties available in CSS.
|
// Helper property holding most layout related properties available in CSS.
|
||||||
// When layout related properties are set in CSS we chache them and send them to the native view in a single call.
|
// When layout related properties are set in CSS we chache them and send them to the native view in a single call.
|
||||||
export var nativeLayoutParamsProperty: styleProperty.Property;
|
export var nativeLayoutParamsProperty: styleProperty.Property;
|
||||||
|
@ -887,6 +887,13 @@ export class Style extends DependencyObservable implements styling.Style {
|
|||||||
this._setValue(selectedBackgroundColorProperty, value);
|
this._setValue(selectedBackgroundColorProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get separatorColor(): Color {
|
||||||
|
return this._getValue(separatorColorProperty);
|
||||||
|
}
|
||||||
|
set separatorColor(value: Color) {
|
||||||
|
this._setValue(separatorColorProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public _updateTextDecoration() {
|
public _updateTextDecoration() {
|
||||||
if (this._getValue(textDecorationProperty) !== enums.TextDecoration.none) {
|
if (this._getValue(textDecorationProperty) !== enums.TextDecoration.none) {
|
||||||
this._applyProperty(textDecorationProperty, this._getValue(textDecorationProperty));
|
this._applyProperty(textDecorationProperty, this._getValue(textDecorationProperty));
|
||||||
@ -1162,12 +1169,17 @@ export var statusBarStyleProperty = new styleProperty.Property("statusBarStyle",
|
|||||||
export var androidStatusBarBackgroundProperty = new styleProperty.Property("androidStatusBarBackground", "android-status-bar-background",
|
export var androidStatusBarBackgroundProperty = new styleProperty.Property("androidStatusBarBackground", "android-status-bar-background",
|
||||||
new PropertyMetadata(undefined, PropertyMetadataSettings.None, undefined, Color.isValid, Color.equals),
|
new PropertyMetadata(undefined, PropertyMetadataSettings.None, undefined, Color.isValid, Color.equals),
|
||||||
converters.colorConverter);
|
converters.colorConverter);
|
||||||
|
|
||||||
// SegmentedBar-specific props
|
// SegmentedBar-specific props
|
||||||
export var selectedBackgroundColorProperty = new styleProperty.Property("selectedBackgroundColor", "selected-background-color",
|
export var selectedBackgroundColorProperty = new styleProperty.Property("selectedBackgroundColor", "selected-background-color",
|
||||||
new PropertyMetadata(undefined, PropertyMetadataSettings.None, undefined, Color.isValid, Color.equals),
|
new PropertyMetadata(undefined, PropertyMetadataSettings.None, undefined, Color.isValid, Color.equals),
|
||||||
converters.colorConverter);
|
converters.colorConverter);
|
||||||
|
|
||||||
|
// ListView-specific props
|
||||||
|
export var separatorColorProperty = new styleProperty.Property("separatorColor", "separator-color",
|
||||||
|
new PropertyMetadata(undefined, PropertyMetadataSettings.None, undefined, Color.isValid, Color.equals),
|
||||||
|
converters.colorConverter);
|
||||||
|
|
||||||
// Helper property holding most layout related properties available in CSS.
|
// Helper property holding most layout related properties available in CSS.
|
||||||
// When layout related properties are set in CSS we chache them and send them to the native view in a single call.
|
// When layout related properties are set in CSS we chache them and send them to the native view in a single call.
|
||||||
export var nativeLayoutParamsProperty = new styleProperty.Property("nativeLayoutParams", "nativeLayoutParams",
|
export var nativeLayoutParamsProperty = new styleProperty.Property("nativeLayoutParams", "nativeLayoutParams",
|
||||||
|
5
tns-core-modules/ui/styling/styling.d.ts
vendored
5
tns-core-modules/ui/styling/styling.d.ts
vendored
@ -333,6 +333,11 @@
|
|||||||
*/
|
*/
|
||||||
selectedBackgroundColor: color.Color;
|
selectedBackgroundColor: color.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the color of the line(separator) between the items of ListView.
|
||||||
|
*/
|
||||||
|
separatorColor: color.Color;
|
||||||
|
|
||||||
//@private
|
//@private
|
||||||
public _beginUpdate();
|
public _beginUpdate();
|
||||||
public _endUpdate();
|
public _endUpdate();
|
||||||
|
Reference in New Issue
Block a user