forked from triniwiz/nativescript-accordion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccordion.common.ts
150 lines (115 loc) · 4.27 KB
/
accordion.common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import {View, AddArrayFromBuilder} from "ui/core/view";
import {PropertyMetadata} from "ui/core/proxy";
import {Property, PropertyChangeData, PropertyMetadataSettings} from "ui/core/dependency-observable";
import {StackLayout} from "ui/layouts/stack-layout";
import {isAndroid} from "platform";
export module knownCollections {
export const items = "items";
}
// function onItemsChanged(data: PropertyChangeData) {
// const accordion = <any>data.object;
// accordion.updateItems(<Array<any>>data.oldValue, <Array<any>>data.newValue);
// }
// on Android we explicitly set propertySettings to None because android will invalidate its layout (skip unnecessary native call).
let AffectsLayout = isAndroid ? PropertyMetadataSettings.None : PropertyMetadataSettings.AffectsLayout;
const itemsProperty = new Property("items", "Accordion", new PropertyMetadata(undefined, AffectsLayout));
const selectedIndexProperty = new Property("selectedIndex", "Accordion", new PropertyMetadata(undefined, PropertyMetadataSettings.None));
(<PropertyMetadata>itemsProperty.metadata).onSetNativeValue = function (data: PropertyChangeData) {
const accordion = <Accordion>data.object;
accordion.updateItems(<Array<any>>data.oldValue, <Array<any>>data.newValue);
};
(<PropertyMetadata>selectedIndexProperty.metadata).onSetNativeValue = function (data: PropertyChangeData) {
const accordion = <Accordion>data.object;
accordion.indexChanged(data.newValue);
};
export abstract class Accordion extends View implements AddArrayFromBuilder {
private _selectedIndexes;
private _allowMultiple: boolean;
private _separatorColor: string;
private _headerHeight: number;
private _headerTextColor: string;
private _headerColor: string;
private _headerTextVerticalAlignment: string;
private _headerTextHorizontalAlignment: string;
private _headerTextSize: number;
public static itemsProperty = itemsProperty;
public static selectedIndexProperty = selectedIndexProperty;
constructor() {
super();
}
public _addArrayFromBuilder(name: string, value: Array<any>) {
if (name === "items") {
this.items = value;
}
}
get headerHeight(): number {
return this._headerHeight;
}
set headerHeight(value: number) {
this._headerHeight = value;
}
get headerTextColor(): string {
return this._headerTextColor;
}
set headerTextColor(value: string) {
this._headerTextColor = value;
}
get headerColor(): string {
return this._headerColor;
}
set headerColor(value: string) {
this._headerColor = value;
}
get headerTextVerticalAlignment(): string {
return this._headerTextVerticalAlignment;
}
set headerTextVerticalAlignment(value: string) {
this._headerTextVerticalAlignment = value;
}
get headerTextHorizontalAlignment(): string {
return this._headerTextHorizontalAlignment;
}
set headerTextHorizontalAlignment(value: string) {
this._headerTextHorizontalAlignment = value;
}
get headerTextSize(): number {
return this._headerTextSize;
}
set headerTextSize(value: number) {
this._headerTextSize = value;
}
get items() {
return this._getValue(Accordion.itemsProperty);
}
set items(value: Array<any>) {
this._setValue(Accordion.itemsProperty, value);
}
get selectedIndex() {
return this._getValue(Accordion.selectedIndexProperty);
}
set selectedIndex(value:number) {
this._setValue(Accordion.selectedIndexProperty,value);
}
get selectedIndexes() {
return this._selectedIndexes;
}
set selectedIndexes(indexes) {
this._selectedIndexes = indexes;
}
get allowMultiple() {
return this._allowMultiple;
}
set allowMultiple(value: boolean) {
this._allowMultiple = true;
}
get separatorColor() {
return this._separatorColor;
}
set separatorColor(value: string) {
this._separatorColor = value;
}
public abstract updateItems(oldItems: Array<any>, newItems: Array<any>): void;
public abstract addItem(view: any): void;
public abstract indexChanged(index:number):void;
public abstract groupCollapsed(index:number):void;
}