Skip to content

Commit 1d44679

Browse files
buuhuuMartoYankov
authored andcommitted
fix(tabview): implemented setter for TabViewItem Directive's configuration (#845) (#1370)
1 parent 7b397df commit 1d44679

File tree

1 file changed

+51
-40
lines changed

1 file changed

+51
-40
lines changed

Diff for: nativescript-angular/directives/tab-view.ts

+51-40
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import { InvisibleNode } from "../element-registry";
1414
import { rendererLog } from "../trace";
1515
import { isBlank } from "../lang-facade";
1616

17+
export interface TabViewItemDef {
18+
title?: string;
19+
iconSource?: string;
20+
textTransform?: TextTransform;
21+
}
22+
1723
@Directive({
1824
selector: "TabView", // tslint:disable-line:directive-selector
1925
})
@@ -52,9 +58,7 @@ export class TabViewDirective implements AfterViewInit {
5258
})
5359
export class TabViewItemDirective implements OnInit {
5460
private item: TabViewItem;
55-
private _title: string;
56-
private _iconSource: string;
57-
private _textTransform: TextTransform;
61+
private _config: TabViewItemDef;
5862

5963
constructor(
6064
private owner: TabViewDirective,
@@ -63,46 +67,46 @@ export class TabViewItemDirective implements OnInit {
6367
) {
6468
}
6569

66-
@Input("tabItem") config: any; // tslint:disable-line:no-input-rename
70+
@Input("tabItem")
71+
set config(config: TabViewItemDef) {
72+
if (!this._config
73+
|| this._config.iconSource !== config.iconSource
74+
|| this._config.title !== config.title
75+
|| this._config.textTransform !== config.textTransform) {
76+
this._config = config;
77+
this.applyConfig();
78+
}
79+
}
80+
81+
get config(): TabViewItemDef { // tslint:disable-line:no-input-rename
82+
return this._config || {};
83+
}
6784

6885
@Input()
69-
get title() {
70-
return this._title;
86+
set title(title: string) {
87+
this.config = Object.assign(this.config, { title });
7188
}
7289

73-
set title(value: string) {
74-
if (this._title !== value) {
75-
this._title = value;
76-
this.ensureItem();
77-
this.item.title = this._title;
78-
}
90+
get title() {
91+
return this.config.title;
7992
}
8093

8194
@Input()
82-
get iconSource() {
83-
return this._iconSource;
95+
set iconSource(iconSource: string) {
96+
this.config = Object.assign(this.config, { iconSource });
8497
}
8598

86-
set iconSource(value: string) {
87-
if (this._iconSource !== value) {
88-
this._iconSource = value;
89-
this.ensureItem();
90-
this.item.iconSource = this._iconSource;
91-
}
99+
get iconSource() {
100+
return this.config.iconSource;
92101
}
93102

94-
95103
@Input()
96-
get textTransform() {
97-
return this._textTransform;
104+
set textTransform(textTransform: TextTransform) {
105+
this.config = Object.assign(this.config, { textTransform });
98106
}
99107

100-
set textTransform(value: TextTransform) {
101-
if (this._textTransform && this._textTransform !== value) {
102-
this._textTransform = value;
103-
this.ensureItem();
104-
this.item.textTransform = this._textTransform;
105-
}
108+
get textTransform() {
109+
return this.config.textTransform;
106110
}
107111

108112
private ensureItem() {
@@ -111,19 +115,26 @@ export class TabViewItemDirective implements OnInit {
111115
}
112116
}
113117

114-
ngOnInit() {
118+
private applyConfig() {
115119
this.ensureItem();
116-
if (this.config) {
117-
this.item.title = this._title || this.config.title;
118-
this.item.iconSource = this._iconSource || this.config.iconSource;
119-
120-
// TabViewItem textTransform has a default value for Android that kick in
121-
// only if no value (even a null value) is set.
122-
const textTransformValue = this._textTransform || this.config.textTransform;
123-
if (textTransformValue) {
124-
this.item.textTransform = textTransformValue;
125-
}
120+
121+
if (this.config.title) {
122+
this.item.title = this.config.title;
123+
}
124+
125+
if (this.config.iconSource) {
126+
this.item.iconSource = this.config.iconSource;
127+
}
128+
129+
// TabViewItem textTransform has a default value for Android that kick in
130+
// only if no value (even a null value) is set.
131+
if (this.config.textTransform) {
132+
this.item.textTransform = this.config.textTransform;
126133
}
134+
}
135+
136+
ngOnInit() {
137+
this.applyConfig();
127138

128139
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
129140
// Filter out text nodes and comments

0 commit comments

Comments
 (0)