Skip to content

Commit 29e07dd

Browse files
author
Hristo Hristov
authored
Hhristov/fix tab view selected index (NativeScript#3893)
* fix button ios color property when textDecoration is applied * Button ios color set on titleLabel * Coerce tabView selectedIndex after native items are set
1 parent 86b9be3 commit 29e07dd

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

apps/.vscode/launch.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"platform": "ios",
99
"appRoot": "${workspaceRoot}",
1010
"sourceMaps": true,
11-
"watch": true
11+
"watch": true,
12+
"tnsArgs": [
13+
"--sync-all-files"
14+
]
1215
},
1316
{
1417
"name": "Attach on iOS",
@@ -26,7 +29,10 @@
2629
"platform": "android",
2730
"appRoot": "${workspaceRoot}",
2831
"sourceMaps": true,
29-
"watch": true
32+
"watch": true,
33+
"tnsArgs": [
34+
"--sync-all-files"
35+
]
3036
},
3137
{
3238
"name": "Attach on Android",

tns-core-modules/ui/tab-view/tab-view-common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ selectedIndexProperty.register(TabViewBase);
196196
export const itemsProperty = new Property<TabViewBase, TabViewItemDefinition[]>({
197197
name: "items", valueChanged: (target, oldValue, newValue) => {
198198
target.onItemsChanged(oldValue, newValue);
199-
selectedIndexProperty.coerce(target);
200199
}
201200
});
202201
itemsProperty.register(TabViewBase);

tns-core-modules/ui/tab-view/tab-view.android.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,25 +327,21 @@ export class TabView extends TabViewBase {
327327
}
328328

329329
public disposeNativeView() {
330-
// this._tabLayout.setItems(null, null);
331330
this._pagerAdapter.notifyDataSetChanged();
332331
(<any>this._pagerAdapter).owner = null;
333332
this._pagerAdapter = null;
334333

335-
// this._viewPager.setAdapter(null);
336334
this._tabLayout = null;
337335
(<any>this._viewPager).listener.owner = null;
338336
this._viewPager = null;
339337
super.disposeNativeView();
340338
}
341339

342-
private setAdapter(items: Array<TabViewItem>) {
340+
private setAdapterItems(items: Array<TabViewItem>) {
343341
(<any>this._pagerAdapter).items = items;
344342

345343
const length = items ? items.length : 0;
346344
if (length === 0) {
347-
// this._viewPager.setAdapter(null);
348-
// this._pagerAdapter = null;
349345
this._tabLayout.setItems(null, null);
350346
return;
351347
}
@@ -393,7 +389,8 @@ export class TabView extends TabViewBase {
393389
return null;
394390
}
395391
[itemsProperty.setNative](value: TabViewItem[]) {
396-
this.setAdapter(value);
392+
this.setAdapterItems(value);
393+
selectedIndexProperty.coerce(this);
397394
}
398395

399396
[tabBackgroundColorProperty.getDefault](): android.graphics.drawable.Drawable.ConstantState {

tns-core-modules/ui/tab-view/tab-view.ios.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ export class TabView extends TabViewBase {
386386
}
387387
[itemsProperty.setNative](value: TabViewItem[]) {
388388
this.setViewControllers(value);
389+
selectedIndexProperty.coerce(this);
389390
}
390391

391392
[tabTextColorProperty.getDefault](): UIColor {

tns-core-modules/ui/text-base/text-base.ios.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ export class TextBase extends TextBaseCommon {
4242
}
4343
[colorProperty.setNative](value: Color | UIColor) {
4444
const color = value instanceof Color ? value.ios : value;
45-
if (!this.formattedText) {
46-
let nativeView = this.nativeView;
47-
if (nativeView instanceof UIButton) {
48-
nativeView.setTitleColorForState(color, UIControlState.Normal);
49-
} else {
50-
nativeView.textColor = color;
51-
}
45+
const nativeView = this.nativeView;
46+
if (nativeView instanceof UIButton) {
47+
nativeView.setTitleColorForState(color, UIControlState.Normal);
48+
nativeView.titleLabel.textColor = color;
49+
} else {
50+
nativeView.textColor = color;
5251
}
5352
}
5453

@@ -58,10 +57,10 @@ export class TextBase extends TextBaseCommon {
5857
return nativeView.font;
5958
}
6059
[fontInternalProperty.setNative](value: Font | UIFont) {
61-
if (!this.formattedText) {
60+
if (!(value instanceof Font) || !this.formattedText) {
6261
let nativeView = this.nativeView;
6362
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
64-
let font = value instanceof Font ? value.getUIFont(nativeView.font) : value;
63+
const font = value instanceof Font ? value.getUIFont(nativeView.font) : value;
6564
nativeView.font = font;
6665
}
6766
}
@@ -170,14 +169,14 @@ export class TextBase extends TextBaseCommon {
170169
dict.set(NSKernAttributeName, style.letterSpacing * this.nativeView.font.pointSize);
171170
}
172171

173-
if (style.color) {
172+
const isTextView = this.nativeView instanceof UITextView;
173+
if (style.color && (dict.size > 0 || isTextView)) {
174174
dict.set(NSForegroundColorAttributeName, style.color.ios);
175175
}
176176

177177
const text = this.text;
178178
const string = (text === undefined || text === null) ? '' : text.toString();
179179
const source = getTransformedText(string, this.textTransform);
180-
const isTextView = this.nativeView instanceof UITextView;
181180
if (dict.size > 0 || isTextView) {
182181
if (isTextView) {
183182
// UITextView's font seems to change inside.

0 commit comments

Comments
 (0)