fix(tabs): current TabContentItem index not set (#7441)

This commit is contained in:
Alexander Djenkov
2019-07-03 22:32:16 +03:00
committed by Manol Donev
parent 22e62daae5
commit 97a2af27f9
3 changed files with 20 additions and 8 deletions

View File

@@ -6,10 +6,10 @@ const layoutWithMultiFrame = "Layout w/ multi frame";
const pageWithFrame = "Page w/ frame";
const pageWithFrameNonDefaultTransition = "Frame to NestedFrame (non-default transition)";
const pageWithMultiFrame = "Page w/ multi frame";
const pageTabTopWithFrames = "Page w/ tabs (top)";
const pageTabBottomWithFrames = "Page w/ tabs (bottom)";
const tabTopRootWithFrames = "Root tabs (top)";
const tabBottomRootWithFrames = "Root tabs (bottom)";
const pageTabTopWithFrames = "Page w/ tabview (top)";
const pageTabBottomWithFrames = "Page w/ tabview (bottom)";
const tabTopRootWithFrames = "Root tabview (top)";
const tabBottomRootWithFrames = "Root tabview (bottom)";
const layoutHome = "layout home page";
const layoutHomeSecondary = "layout home secondary page";
const frameHome = "frame home page";

View File

@@ -3,7 +3,8 @@ import { TabContentItem as TabContentItemDefinition } from ".";
import { TabNavigationBase } from "../tab-navigation-base";
// Requires
import { TabContentItemBase } from "./tab-content-item-common";
import { TabContentItemBase, traceCategory } from "./tab-content-item-common";
import { traceEnabled, traceWrite, traceMessageType } from "../../core/view";
export * from "./tab-content-item-common";
@@ -49,6 +50,11 @@ export class TabContentItem extends TabContentItemBase {
const tabView = <TabNavigationBase>this.parent;
let tabFragment = null;
const fragmentManager = tabView._getFragmentManager();
if (typeof this.index === "undefined") {
traceWrite(`Current TabContentItem index is not set`, traceCategory, traceMessageType.error);
}
for (let fragment of (<Array<any>>fragmentManager.getFragments().toArray())) {
if (fragment.index === this.index) {
tabFragment = fragment;

View File

@@ -229,7 +229,7 @@ function initializeNativeClasses() {
}
}
}
PagerAdapter = FragmentPagerAdapter;
}
@@ -451,7 +451,7 @@ export class Tabs extends TabsBase {
public _onRootViewReset(): void {
super._onRootViewReset();
// call this AFTER the super call to ensure descendants apply their rootview-reset logic first
// i.e. in a scenario with tab frames let the frames cleanup their fragments first, and then
// cleanup the tab fragments to avoid
@@ -508,6 +508,13 @@ export class Tabs extends TabsBase {
private setItems(items: Array<TabContentItem>) {
if (this.shouldUpdateAdapter(items)) {
(<any>this._pagerAdapter).items = items;
if (items && items.length) {
items.forEach((item: TabContentItem, i) => {
(<any>item).index = i;
});
}
this._pagerAdapter.notifyDataSetChanged();
}
}
@@ -523,7 +530,6 @@ export class Tabs extends TabsBase {
const tabItems = new Array<org.nativescript.widgets.TabItemSpec>();
items.forEach((item: TabStripItem, i, arr) => {
const tabItemSpec = createTabItemSpec(item);
(<any>item).index = i;
(<any>item).tabItemSpec = tabItemSpec;
tabItems.push(tabItemSpec);
});