Skip to content

Commit 72ca461

Browse files
ADjenkovMartoYankov
authored andcommitted
feat(tab-content-view): change tabContentItem to View (NativeScript#7629)
1 parent acc3436 commit 72ca461

File tree

16 files changed

+111
-113
lines changed

16 files changed

+111
-113
lines changed

e2e/ui-tests-app/app/bottom-navigation/bottom-navigation-view-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class BottomNavigationViewModel extends Observable {
5252
const gridlayout = new GridLayout();
5353
label.text = "Content Item " + index;
5454
gridlayout.addChild(label);
55-
contentItem.view = gridlayout;
55+
contentItem.content = gridlayout;
5656

5757
return contentItem;
5858
}

e2e/ui-tests-app/app/tabs/tabs-binding-view-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class TabsBindingNavigationViewModel extends Observable {
5353
const gridlayout = new GridLayout();
5454
label.text = "Content Item " + index;
5555
gridlayout.addChild(label);
56-
contentItem.view = gridlayout;
56+
contentItem.content = gridlayout;
5757

5858
return contentItem;
5959
}

tests/app/ui/bottom-navigation/bottom-navigation-navigation-tests.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function _createContentItems(count: number): Array<TabContentItem> {
2323
const label = new Label();
2424
label.text = "Tab " + i;
2525
const tabEntry = new TabContentItem();
26-
tabEntry.view = label;
26+
tabEntry.content = label;
2727
items.push(tabEntry);
2828
}
2929

@@ -101,12 +101,12 @@ export function testBackNavigationToTabViewWithNestedFramesShouldWork() {
101101
let items = Array<TabContentItem>();
102102
let tabViewitem = new TabContentItem();
103103
// tabViewitem.title = "Item1";
104-
tabViewitem.view = _createFrameView();
104+
tabViewitem.content = _createFrameView();
105105
items.push(tabViewitem);
106106

107107
let tabViewitem2 = new TabContentItem();
108108
// tabViewitem2.title = "Item2";
109-
tabViewitem2.view = _createFrameView();
109+
tabViewitem2.content = _createFrameView();
110110
items.push(tabViewitem2);
111111

112112
tabView.items = items;
@@ -145,7 +145,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
145145
let items = Array<TabContentItem>();
146146
let tabViewitem = new TabContentItem();
147147
// tabViewitem.title = "List";
148-
tabViewitem.view = _createListView();
148+
tabViewitem.content = _createListView();
149149
items.push(tabViewitem);
150150

151151
let label = new Label();
@@ -155,7 +155,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
155155
aboutLayout.addChild(label);
156156
tabViewitem = new TabContentItem();
157157
// tabViewitem.title = "About";
158-
tabViewitem.view = aboutLayout;
158+
tabViewitem.content = aboutLayout;
159159
items.push(tabViewitem);
160160

161161
tabView.items = items;
@@ -184,7 +184,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
184184

185185
TKUnit.waitUntilReady(() => topFrame.currentPage === rootPage);
186186

187-
TKUnit.assert(tabView.items[0].view instanceof ListView, "ListView should be created when navigating back to the main page.");
187+
TKUnit.assert(tabView.items[0].content instanceof ListView, "ListView should be created when navigating back to the main page.");
188188
}
189189

190190
function tabViewIsFullyLoaded(tabView: BottomNavigation): boolean {
@@ -232,8 +232,8 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
232232
}
233233

234234
tabView.items.forEach((item, i) => {
235-
item.view.on("loaded", createLoadedFor(i));
236-
item.view.on("unloaded", createUnloadedFor(i));
235+
item.content.on("loaded", createLoadedFor(i));
236+
item.content.on("unloaded", createUnloadedFor(i));
237237
});
238238

239239
const tabViewPage = new Page();
@@ -252,8 +252,8 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
252252
TKUnit.assertEqual(topFrame.currentPage, tabViewPage);
253253

254254
for (let i = 0; i < itemCount; i++) {
255-
tabView.items[i].view.off("loaded");
256-
tabView.items[i].view.off("unloaded");
255+
tabView.items[i].content.off("loaded");
256+
tabView.items[i].content.off("unloaded");
257257
}
258258

259259
helper.goBack();
@@ -267,7 +267,7 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
267267

268268
function _clickTheFirstButtonInTheListViewNatively(tabView: BottomNavigation) {
269269
if (tabView.android) {
270-
const androidListView = <android.widget.ListView>tabView.items[0].view.nativeView;
270+
const androidListView = <android.widget.ListView>tabView.items[0].content.nativeView;
271271
// var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
272272
// var androidListView = <android.widget.ListView>viewPager.getChildAt(0);
273273
var stackLayout = <org.nativescript.widgets.StackLayout>androidListView.getChildAt(0);

tests/app/ui/bottom-navigation/bottom-navigation-root-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function createFrame(i: number, page: Page) {
4747
function createTabItem(i: number, frame: Frame) {
4848
const tabEntry = new TabContentItem();
4949
// tabEntry.title = "Tab " + i;
50-
tabEntry.view = frame;
50+
tabEntry.content = frame;
5151
tabEntry["index"] = i;
5252

5353
return tabEntry;

tests/app/ui/bottom-navigation/bottom-navigation-tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class BottomNavigationTest extends UITest<BottomNavigation> {
2727
const label = new Label();
2828
label.text = "Tab " + i;
2929
const tabEntry = new TabContentItem();
30-
tabEntry.view = label;
30+
tabEntry.content = label;
3131
items.push(tabEntry);
3232
}
3333

@@ -208,7 +208,7 @@ export class BottomNavigationTest extends UITest<BottomNavigation> {
208208
TKUnit.assertThrows(() => {
209209
let item = new TabContentItem();
210210
// item.title = "Tab 0";
211-
item.view = undefined;
211+
item.content = undefined;
212212
tabView.items = [item];
213213

214214
}, "Binding TabNavigation to a TabItem with undefined view should throw.");
@@ -221,7 +221,7 @@ export class BottomNavigationTest extends UITest<BottomNavigation> {
221221
TKUnit.assertThrows(() => {
222222
let item = new TabContentItem();
223223
// item.title = "Tab 0";
224-
item.view = null;
224+
item.content = null;
225225
tabView.items = [item];
226226

227227
}, "Binding TabNavigation to a TabItem with null view should throw.");

tests/app/ui/tabs/tabs-navigation-tests.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function _createContentItems(count: number): Array<TabContentItem> {
2323
const label = new Label();
2424
label.text = "Tab " + i;
2525
const tabEntry = new TabContentItem();
26-
tabEntry.view = label;
26+
tabEntry.content = label;
2727
items.push(tabEntry);
2828
}
2929

@@ -101,12 +101,12 @@ export function testBackNavigationToTabViewWithNestedFramesShouldWork() {
101101
let items = Array<TabContentItem>();
102102
let tabViewitem = new TabContentItem();
103103
// tabViewitem.title = "Item1";
104-
tabViewitem.view = _createFrameView();
104+
tabViewitem.content = _createFrameView();
105105
items.push(tabViewitem);
106106

107107
let tabViewitem2 = new TabContentItem();
108108
// tabViewitem2.title = "Item2";
109-
tabViewitem2.view = _createFrameView();
109+
tabViewitem2.content = _createFrameView();
110110
items.push(tabViewitem2);
111111

112112
tabView.items = items;
@@ -145,7 +145,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
145145
let items = Array<TabContentItem>();
146146
let tabViewitem = new TabContentItem();
147147
// tabViewitem.title = "List";
148-
tabViewitem.view = _createListView();
148+
tabViewitem.content = _createListView();
149149
items.push(tabViewitem);
150150

151151
let label = new Label();
@@ -155,7 +155,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
155155
aboutLayout.addChild(label);
156156
tabViewitem = new TabContentItem();
157157
// tabViewitem.title = "About";
158-
tabViewitem.view = aboutLayout;
158+
tabViewitem.content = aboutLayout;
159159
items.push(tabViewitem);
160160

161161
tabView.items = items;
@@ -184,7 +184,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
184184

185185
TKUnit.waitUntilReady(() => topFrame.currentPage === rootPage);
186186

187-
TKUnit.assert(tabView.items[0].view instanceof ListView, "ListView should be created when navigating back to the main page.");
187+
TKUnit.assert(tabView.items[0].content instanceof ListView, "ListView should be created when navigating back to the main page.");
188188
}
189189

190190
function tabViewIsFullyLoaded(tabView: Tabs): boolean {
@@ -232,8 +232,8 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
232232
}
233233

234234
tabView.items.forEach((item, i) => {
235-
item.view.on("loaded", createLoadedFor(i));
236-
item.view.on("unloaded", createUnloadedFor(i));
235+
item.content.on("loaded", createLoadedFor(i));
236+
item.content.on("unloaded", createUnloadedFor(i));
237237
});
238238

239239
const tabViewPage = new Page();
@@ -252,8 +252,8 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
252252
TKUnit.assertEqual(topFrame.currentPage, tabViewPage);
253253

254254
for (let i = 0; i < itemCount; i++) {
255-
tabView.items[i].view.off("loaded");
256-
tabView.items[i].view.off("unloaded");
255+
tabView.items[i].content.off("loaded");
256+
tabView.items[i].content.off("unloaded");
257257
}
258258

259259
helper.goBack();
@@ -267,7 +267,7 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
267267

268268
function _clickTheFirstButtonInTheListViewNatively(tabView: Tabs) {
269269
if (tabView.android) {
270-
const androidListView = <android.widget.ListView>tabView.items[0].view.nativeView;
270+
const androidListView = <android.widget.ListView>tabView.items[0].content.nativeView;
271271
// var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
272272
// var androidListView = <android.widget.ListView>viewPager.getChildAt(0);
273273
var stackLayout = <org.nativescript.widgets.StackLayout>androidListView.getChildAt(0);

tests/app/ui/tabs/tabs-root-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function createFrame(i: number, page: Page) {
3535
function createTabItem(i: number, frame: Frame) {
3636
const tabEntry = new TabContentItem();
3737
// tabEntry.title = "Tab " + i;
38-
tabEntry.view = frame;
38+
tabEntry.content = frame;
3939
tabEntry["index"] = i;
4040

4141
return tabEntry;

tests/app/ui/tabs/tabs-tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class TabsTest extends UITest<Tabs> {
2727
const label = new Label();
2828
label.text = "Tab " + i;
2929
const tabEntry = new TabContentItem();
30-
tabEntry.view = label;
30+
tabEntry.content = label;
3131
items.push(tabEntry);
3232
}
3333

@@ -210,7 +210,7 @@ export class TabsTest extends UITest<Tabs> {
210210
TKUnit.assertThrows(() => {
211211
let item = new TabContentItem();
212212
// item.title = "Tab 0";
213-
item.view = undefined;
213+
item.content = undefined;
214214
tabView.items = [item];
215215

216216
}, "Binding TabNavigation to a TabItem with undefined view should throw.");
@@ -223,7 +223,7 @@ export class TabsTest extends UITest<Tabs> {
223223
TKUnit.assertThrows(() => {
224224
let item = new TabContentItem();
225225
// item.title = "Tab 0";
226-
item.view = null;
226+
item.content = null;
227227
tabView.items = [item];
228228

229229
}, "Binding TabNavigation to a TabItem with null view should throw.");

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function initializeNativeClasses() {
8585
public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle): android.view.View {
8686
const tabItem = this.tab.items[this.index];
8787

88-
return tabItem.view.nativeViewProtected;
88+
return tabItem.nativeViewProtected;
8989
}
9090
}
9191

@@ -211,11 +211,10 @@ function createTabItemSpec(tabStripItem: TabStripItem): org.nativescript.widgets
211211
return tabItemSpec;
212212
}
213213

214-
function setElevation(grid: org.nativescript.widgets.GridLayout, bottomNavigationBar: org.nativescript.widgets.BottomNavigationBar) {
214+
function setElevation(bottomNavigationBar: org.nativescript.widgets.BottomNavigationBar) {
215215
const compat = <any>androidx.core.view.ViewCompat;
216216
if (compat.setElevation) {
217217
const val = DEFAULT_ELEVATION * layout.getDisplayDensity();
218-
compat.setElevation(grid, val);
219218
compat.setElevation(bottomNavigationBar, val);
220219
}
221220
}
@@ -288,7 +287,7 @@ export class BottomNavigation extends TabNavigationBase {
288287
nativeView.addView(bottomNavigationBar);
289288
(<any>nativeView).bottomNavigationBar = bottomNavigationBar;
290289

291-
setElevation(nativeView, bottomNavigationBar);
290+
setElevation(bottomNavigationBar);
292291

293292
const primaryColor = ad.resources.getPaletteColor(PRIMARY_COLOR, context);
294293
if (primaryColor) {
@@ -341,20 +340,20 @@ export class BottomNavigation extends TabNavigationBase {
341340
toUnload.forEach(index => {
342341
const item = items[index];
343342
if (items[index]) {
344-
item.unloadView(item.view);
343+
item.unloadView(item.content);
345344
}
346345
});
347346

348347
const newItem = items[newIndex];
349-
const selectedView = newItem && newItem.view;
348+
const selectedView = newItem && newItem.content;
350349
if (selectedView instanceof Frame) {
351350
selectedView._pushInFrameStackRecursive();
352351
}
353352

354353
toLoad.forEach(index => {
355354
const item = items[index];
356355
if (this.isLoaded && items[index]) {
357-
item.loadView(item.view);
356+
item.loadView(item.content);
358357
}
359358
});
360359
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class BottomNavigation extends TabNavigationBase {
260260
super.onLoaded();
261261

262262
const selectedIndex = this.selectedIndex;
263-
const selectedView = this.items && this.items[selectedIndex] && this.items[selectedIndex].view;
263+
const selectedView = this.items && this.items[selectedIndex] && this.items[selectedIndex].content;
264264
if (selectedView instanceof Frame) {
265265
selectedView._pushInFrameStackRecursive();
266266
}
@@ -295,18 +295,18 @@ export class BottomNavigation extends TabNavigationBase {
295295
const oldItem = items[oldIndex];
296296
if (oldItem) {
297297
oldItem.canBeLoaded = false;
298-
oldItem.unloadView(oldItem.view);
298+
oldItem.unloadView(oldItem.content);
299299
}
300300

301301
const newItem = items[newIndex];
302302
if (newItem && this.isLoaded) {
303-
const selectedView = items[newIndex].view;
303+
const selectedView = items[newIndex].content;
304304
if (selectedView instanceof Frame) {
305305
selectedView._pushInFrameStackRecursive();
306306
}
307307

308308
newItem.canBeLoaded = true;
309-
newItem.loadView(newItem.view);
309+
newItem.loadView(newItem.content);
310310
}
311311

312312
super.onSelectedIndexChanged(oldIndex, newIndex);
@@ -463,25 +463,25 @@ export class BottomNavigation extends TabNavigationBase {
463463
}
464464

465465
private getViewController(item: TabContentItem): UIViewController {
466-
let newController: UIViewController = item.view ? item.view.viewController : null;
466+
let newController: UIViewController = item.content ? item.content.viewController : null;
467467

468468
if (newController) {
469469
(<any>item).setViewController(newController, newController.view);
470470

471471
return newController;
472472
}
473473

474-
if (item.view.ios instanceof UIViewController) {
475-
newController = item.view.ios;
474+
if (item.content.ios instanceof UIViewController) {
475+
newController = item.content.ios;
476476
(<any>item).setViewController(newController, newController.view);
477-
} else if (item.view.ios && item.view.ios.controller instanceof UIViewController) {
478-
newController = item.view.ios.controller;
477+
} else if (item.content.ios && item.content.ios.controller instanceof UIViewController) {
478+
newController = item.content.ios.controller;
479479
(<any>item).setViewController(newController, newController.view);
480480
} else {
481-
newController = iosView.UILayoutViewController.initWithOwner(new WeakRef(item.view)) as UIViewController;
482-
newController.view.addSubview(item.view.nativeViewProtected);
483-
item.view.viewController = newController;
484-
(<any>item).setViewController(newController, item.view.nativeViewProtected);
481+
newController = iosView.UILayoutViewController.initWithOwner(new WeakRef(item.content)) as UIViewController;
482+
newController.view.addSubview(item.content.nativeViewProtected);
483+
item.content.viewController = newController;
484+
(<any>item).setViewController(newController, item.content.nativeViewProtected);
485485
}
486486

487487
return newController;

0 commit comments

Comments
 (0)