mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(tabs): current TabContentItem index not set (#7441)
This commit is contained in:
committed by
Manol Donev
parent
22e62daae5
commit
97a2af27f9
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user