Skip to content

Commit 121edfc

Browse files
committed
wip: fix tabstrip items binding
1 parent 3afa2fc commit 121edfc

5 files changed

Lines changed: 55 additions & 38 deletions

File tree

tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BottomNavigationBar.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,23 @@ private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, Tab
201201
if (tabItem.title != null && !tabItem.title.isEmpty()) {
202202
textView.setText(tabItem.title);
203203
textView.setVisibility(VISIBLE);
204+
205+
if (tabItem.typeFace != null) {
206+
textView.setTypeface(tabItem.typeFace);
207+
}
208+
209+
if (tabItem.fontSize != 0) {
210+
textView.setTextSize(tabItem.fontSize);
211+
}
212+
213+
if (tabItem.color != 0) {
214+
textView.setTextColor(tabItem.color);
215+
mTabStrip.setShouldUpdateTabsTextColor(false);
216+
}
204217
} else {
205218
textView.setVisibility(GONE);
206219
}
207220

208-
if (tabItem.typeFace != null) {
209-
textView.setTypeface(tabItem.typeFace);
210-
}
211-
212-
if (tabItem.fontSize != 0) {
213-
textView.setTextSize(tabItem.fontSize);
214-
}
215-
216-
if (tabItem.color != 0) {
217-
textView.setTextColor(tabItem.color);
218-
mTabStrip.setShouldUpdateTabsTextColor(false);
219-
}
220-
221221
if (tabItem.backgroundColor != 0) {
222222
ll.setBackgroundColor(tabItem.backgroundColor);
223223
}

tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabsBar.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, Tab
279279
if (tabItem.title != null && !tabItem.title.isEmpty()) {
280280
textView.setText(tabItem.title);
281281
textView.setVisibility(VISIBLE);
282+
283+
if (tabItem.typeFace != null) {
284+
textView.setTypeface(tabItem.typeFace);
285+
}
286+
287+
if (tabItem.fontSize != 0) {
288+
textView.setTextSize(tabItem.fontSize);
289+
}
290+
291+
if (tabItem.color != 0) {
292+
textView.setTextColor(tabItem.color);
293+
mTabStrip.setShouldUpdateTabsTextColor(false);
294+
}
282295
} else {
283296
textView.setVisibility(GONE);
284297
}
@@ -287,19 +300,6 @@ private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, Tab
287300
ll.setBackgroundColor(tabItem.backgroundColor);
288301
}
289302

290-
if (tabItem.typeFace != null) {
291-
textView.setTypeface(tabItem.typeFace);
292-
}
293-
294-
if (tabItem.fontSize != 0) {
295-
textView.setTextSize(tabItem.fontSize);
296-
}
297-
298-
if (tabItem.color != 0) {
299-
textView.setTextColor(tabItem.color);
300-
mTabStrip.setShouldUpdateTabsTextColor(false);
301-
}
302-
303303
if (imgView.getVisibility() == VISIBLE && textView.getVisibility() == VISIBLE) {
304304
ll.setMinimumHeight((int) (LARGE_MIN_HEIGHT * density));
305305
} else {

tns-core-modules/ui/bottom-navigation/bottom-navigation.android.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ function createTabItemSpec(tabStripItem: TabStripItem): org.nativescript.widgets
170170
const tabItemSpec = new org.nativescript.widgets.TabItemSpec();
171171

172172
if (tabStripItem.isLoaded) {
173-
const nestedLabel = tabStripItem.label;
174-
let title = nestedLabel.text;
173+
const titleLabel = tabStripItem.label;
174+
let title = titleLabel.text;
175175

176176
// TEXT-TRANSFORM
177-
const textTransform = nestedLabel.style.textTransform;
177+
const textTransform = titleLabel.style.textTransform;
178178
if (textTransform) {
179179
title = getTransformedText(title, textTransform);
180180
}
@@ -187,13 +187,13 @@ function createTabItemSpec(tabStripItem: TabStripItem): org.nativescript.widgets
187187
}
188188

189189
// COLOR
190-
const color = nestedLabel.style.color;
190+
const color = titleLabel.style.color;
191191
if (color) {
192192
tabItemSpec.color = color.android;
193193
}
194194

195195
// FONT
196-
const fontInternal = nestedLabel.style.fontInternal;
196+
const fontInternal = titleLabel.style.fontInternal;
197197
if (fontInternal) {
198198
tabItemSpec.fontSize = fontInternal.fontSize;
199199
tabItemSpec.typeFace = fontInternal.getAndroidTypeface();
@@ -229,7 +229,7 @@ function createTabItemSpec(tabStripItem: TabStripItem): org.nativescript.widgets
229229
function _getIcon(tabStripItem: TabStripItem): android.graphics.drawable.BitmapDrawable {
230230
const iconSource = tabStripItem.image && tabStripItem.image.src;
231231

232-
let is = new ImageSource();
232+
let is: ImageSource;
233233
if (isFontIconURI(iconSource)) {
234234
const fontIconCode = iconSource.split("//")[1];
235235
const target = tabStripItem.image ? tabStripItem.image : tabStripItem;
@@ -633,8 +633,8 @@ export class BottomNavigation extends TabNavigationBase {
633633
}
634634

635635
public setTabBarItemTextTransform(tabStripItem: TabStripItem, value: TextTransform): void {
636-
const nestedLabel = tabStripItem.label;
637-
const title = getTransformedText(nestedLabel.text, value);
636+
const titleLabel = tabStripItem.label;
637+
const title = getTransformedText(titleLabel.text, value);
638638
tabStripItem.nativeViewProtected.setText(title);
639639
}
640640

tns-core-modules/ui/tab-navigation-base/tab-strip-item/tab-strip-item.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import { AddChildFromBuilder } from "../../core/view";
1010

1111
// Requires
1212
import {
13-
View, ViewBase, CSSType, backgroundColorProperty, backgroundInternalProperty, colorProperty,
14-
fontSizeProperty, fontInternalProperty, PseudoClassHandler
13+
View, ViewBase, CSSType, backgroundColorProperty, backgroundInternalProperty, PseudoClassHandler
1514
} from "../../core/view";
16-
import { textTransformProperty, TextTransform } from "../../text-base";
1715

1816
export * from "../../core/view";
1917
export const traceCategory = "TabView";

tns-core-modules/ui/tab-navigation-base/tab-strip/tab-strip.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ export class TabStrip extends View implements TabStripDefinition, AddChildFromBu
5151
}
5252
}
5353

54+
public onItemsChanged(oldItems: TabStripItem[], newItems: TabStripItem[]): void {
55+
if (oldItems) {
56+
oldItems.forEach(item => this._removeView(item));
57+
}
58+
59+
if (newItems) {
60+
newItems.forEach(item => {
61+
this._addView(item);
62+
});
63+
}
64+
}
65+
5466
[backgroundColorProperty.getDefault](): Color {
5567
const parent = <TabNavigationBase>this.parent;
5668

@@ -112,7 +124,14 @@ export class TabStrip extends View implements TabStripDefinition, AddChildFromBu
112124

113125
return parent && parent.setTabBarHighlightColor(value);
114126
}
115-
}
127+
}
128+
129+
export const itemsProperty = new Property<TabStrip, TabStripItem[]>({
130+
name: "items", valueChanged: (target, oldValue, newValue) => {
131+
target.onItemsChanged(oldValue, newValue);
132+
}
133+
});
134+
itemsProperty.register(TabStrip);
116135

117136
export const iosIconRenderingModeProperty = new Property<TabStrip, "automatic" | "alwaysOriginal" | "alwaysTemplate">({ name: "iosIconRenderingMode", defaultValue: "automatic" });
118137
iosIconRenderingModeProperty.register(TabStrip);

0 commit comments

Comments
 (0)