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 pageWithFrame = "Page w/ frame";
|
||||||
const pageWithFrameNonDefaultTransition = "Frame to NestedFrame (non-default transition)";
|
const pageWithFrameNonDefaultTransition = "Frame to NestedFrame (non-default transition)";
|
||||||
const pageWithMultiFrame = "Page w/ multi frame";
|
const pageWithMultiFrame = "Page w/ multi frame";
|
||||||
const pageTabTopWithFrames = "Page w/ tabs (top)";
|
const pageTabTopWithFrames = "Page w/ tabview (top)";
|
||||||
const pageTabBottomWithFrames = "Page w/ tabs (bottom)";
|
const pageTabBottomWithFrames = "Page w/ tabview (bottom)";
|
||||||
const tabTopRootWithFrames = "Root tabs (top)";
|
const tabTopRootWithFrames = "Root tabview (top)";
|
||||||
const tabBottomRootWithFrames = "Root tabs (bottom)";
|
const tabBottomRootWithFrames = "Root tabview (bottom)";
|
||||||
const layoutHome = "layout home page";
|
const layoutHome = "layout home page";
|
||||||
const layoutHomeSecondary = "layout home secondary page";
|
const layoutHomeSecondary = "layout home secondary page";
|
||||||
const frameHome = "frame home page";
|
const frameHome = "frame home page";
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { TabContentItem as TabContentItemDefinition } from ".";
|
|||||||
import { TabNavigationBase } from "../tab-navigation-base";
|
import { TabNavigationBase } from "../tab-navigation-base";
|
||||||
|
|
||||||
// Requires
|
// 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";
|
export * from "./tab-content-item-common";
|
||||||
|
|
||||||
@@ -49,6 +50,11 @@ export class TabContentItem extends TabContentItemBase {
|
|||||||
const tabView = <TabNavigationBase>this.parent;
|
const tabView = <TabNavigationBase>this.parent;
|
||||||
let tabFragment = null;
|
let tabFragment = null;
|
||||||
const fragmentManager = tabView._getFragmentManager();
|
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())) {
|
for (let fragment of (<Array<any>>fragmentManager.getFragments().toArray())) {
|
||||||
if (fragment.index === this.index) {
|
if (fragment.index === this.index) {
|
||||||
tabFragment = fragment;
|
tabFragment = fragment;
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ function initializeNativeClasses() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PagerAdapter = FragmentPagerAdapter;
|
PagerAdapter = FragmentPagerAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ export class Tabs extends TabsBase {
|
|||||||
|
|
||||||
public _onRootViewReset(): void {
|
public _onRootViewReset(): void {
|
||||||
super._onRootViewReset();
|
super._onRootViewReset();
|
||||||
|
|
||||||
// call this AFTER the super call to ensure descendants apply their rootview-reset logic first
|
// 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
|
// i.e. in a scenario with tab frames let the frames cleanup their fragments first, and then
|
||||||
// cleanup the tab fragments to avoid
|
// cleanup the tab fragments to avoid
|
||||||
@@ -508,6 +508,13 @@ export class Tabs extends TabsBase {
|
|||||||
private setItems(items: Array<TabContentItem>) {
|
private setItems(items: Array<TabContentItem>) {
|
||||||
if (this.shouldUpdateAdapter(items)) {
|
if (this.shouldUpdateAdapter(items)) {
|
||||||
(<any>this._pagerAdapter).items = items;
|
(<any>this._pagerAdapter).items = items;
|
||||||
|
|
||||||
|
if (items && items.length) {
|
||||||
|
items.forEach((item: TabContentItem, i) => {
|
||||||
|
(<any>item).index = i;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this._pagerAdapter.notifyDataSetChanged();
|
this._pagerAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,7 +530,6 @@ export class Tabs extends TabsBase {
|
|||||||
const tabItems = new Array<org.nativescript.widgets.TabItemSpec>();
|
const tabItems = new Array<org.nativescript.widgets.TabItemSpec>();
|
||||||
items.forEach((item: TabStripItem, i, arr) => {
|
items.forEach((item: TabStripItem, i, arr) => {
|
||||||
const tabItemSpec = createTabItemSpec(item);
|
const tabItemSpec = createTabItemSpec(item);
|
||||||
(<any>item).index = i;
|
|
||||||
(<any>item).tabItemSpec = tabItemSpec;
|
(<any>item).tabItemSpec = tabItemSpec;
|
||||||
tabItems.push(tabItemSpec);
|
tabItems.push(tabItemSpec);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user