FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add TabView.androidOffscreenTabLimit property by hamorphis · Pull Request #3047 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
54 changes: 54 additions & 0 deletions tests/app/ui/tab-view/tab-view-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,60 @@ export class TabViewTest extends testModule.UITest<tabViewModule.TabView> {
TKUnit.assertEqual(actualOldIndex, expectedOldIndex, "expectedOldIndex");
TKUnit.assertEqual(actualNewIndex, expectedNewIndex, "expectedNewIndex");
}

public testAndroidOffscreenTabLimit_Default = function () {
let tabView = this.testView;
if (!tabView.android){
return;
}

// The default setting is 1.
// tabView.androidOffscreenTabLimit = 1;
tabView.items = this._createItems(20);
this.waitUntilTestElementIsLoaded();
for (let index = 0, length = tabView.items.length; index < length; index++){
tabViewTestsNative.selectNativeTab(tabView, index);
TKUnit.waitUntilReady(function () {
return tabView.selectedIndex === index;
}, helper.ASYNC);
}

let viewsWithParent = 0;
let viewsWithoutParent = 0;
for (let i = 0, length = tabView.items.length; i < length; i++){
if (tabView.items[i].view.parent) {
viewsWithParent++;
}
else {
viewsWithoutParent++;
}
}

TKUnit.assertTrue(viewsWithoutParent > viewsWithParent, "Most of the views should be recycled!");
}

public testAndroidOffscreenTabLimit_KeepAllAlive = function () {
let tabView = this.testView;
if (!tabView.android){
return;
}

tabView.androidOffscreenTabLimit = 20;

tabView.items = this._createItems(20);
this.waitUntilTestElementIsLoaded();
for (let index = 0, length = tabView.items.length; index < length; index++){
tabViewTestsNative.selectNativeTab(tabView, index);
TKUnit.waitUntilReady(function () {
return tabView.selectedIndex === index;
}, helper.ASYNC);
}

for (let i = 0, length = tabView.items.length; i < length; i++){
TKUnit.assertNotNull(tabView.items[i].view.parent, `tabView.items[${i}].view should have a parent!`);
}
}

/*
public testBindingIsRefreshedWhenTabViewItemIsUnselectedAndThenSelectedAgain() {

Expand Down
7 changes: 7 additions & 0 deletions tns-core-modules/ui/tab-view/tab-view-common.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ export class TabView extends View implements definition.TabView, AddArrayFromBui
//
}

get androidOffscreenTabLimit(): number {
return undefined;
}
set androidOffscreenTabLimit(value: number) {
//
}

public _onSelectedIndexPropertyChangedSetNativeValue(data: PropertyChangeData) {
var index = this.selectedIndex;
if (types.isUndefined(index)) {
Expand Down
17 changes: 17 additions & 0 deletions tns-core-modules/ui/tab-view/tab-view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export class TabView extends common.TabView {
}

this._viewPager = new android.support.v4.view.ViewPager(this._context);
if (this._androidOffscreenTabLimit !== 1) {
this._viewPager.setOffscreenPageLimit(this._androidOffscreenTabLimit);
}
this._viewPager.setId(this._androidViewId);
var lp = new org.nativescript.widgets.CommonLayoutParams();
lp.row = 1;
Expand Down Expand Up @@ -332,6 +335,20 @@ export class TabView extends common.TabView {
public _getAndroidTabView(): org.nativescript.widgets.TabLayout {
return this._tabLayout;
}

private _androidOffscreenTabLimit: number = 1;
get androidOffscreenTabLimit(): number {
return this._androidOffscreenTabLimit;
}
set androidOffscreenTabLimit(value: number) {
if (value !== this._androidOffscreenTabLimit) {
this._androidOffscreenTabLimit = value;
if (this._viewPager) {
this._viewPager.setOffscreenPageLimit(value);
}
}
}

}

export class TabViewStyler implements style.Styler {
Expand Down
6 changes: 6 additions & 0 deletions tns-core-modules/ui/tab-view/tab-view.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ declare module "ui/tab-view" {
*/
iosIconRenderingMode: string;

/**
* Gets or sets the number of tabs that should be retained to either side of the current tab in the view hierarchy in an idle state.
* Tabs beyond this limit will be recreated from the TabView when needed.
*/
androidOffscreenTabLimit: number;

/**
* String value used when hooking to the selectedIndexChanged event.
*/
Expand Down

Back | FazBrowse Home | New Git URL