Fixes TabView icons changes. (#4666)

* Fixes TabView icons/title changes.

* Access TabLayput trough parent

* TabView icon change example
This commit is contained in:
Alexander Vakrilov
2017-08-08 13:06:56 +03:00
committed by GitHub
parent d8f0430fef
commit 50d399101e
4 changed files with 46 additions and 7 deletions

View File

@ -19,6 +19,7 @@ export function loadExamples() {
examples.set("tabmore", "tab-view/tab-view-more");
examples.set("tabViewCss", "tab-view/tab-view-css");
examples.set("tab-view-icons", "tab-view/tab-view-icon");
examples.set("tab-view-icon-change", "tab-view/tab-view-icon-change");
examples.set("text-transform", "tab-view/text-transform");
return examples;
}

View File

@ -0,0 +1,17 @@
import { EventData } from "tns-core-modules/data/observable";
import { Button } from "tns-core-modules/ui/button";
import { TabView, SelectedIndexChangedEventData } from "tns-core-modules/ui/tab-view";
export function onSelectedIndexChanged(args: SelectedIndexChangedEventData) {
const tabView = args.object as TabView;
const newItem = tabView.items[args.newIndex];
if (newItem) {
newItem.iconSource = "res://icon";
}
const oldItem = tabView.items[args.oldIndex];
if (oldItem) {
oldItem.iconSource = "res://testlogo";
}
}

View File

@ -0,0 +1,16 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<TabView id="tab-view" selectedIndexChanged="onSelectedIndexChanged" iosIconRenderingMode="alwaysOriginal">
<TabView.items>
<TabViewItem iconSource="res://icon">
<TabViewItem.view>
<Label text="first tab"/>
</TabViewItem.view>
</TabViewItem>
<TabViewItem iconSource="res://testlogo">
<TabViewItem.view>
<Label text="second tab"/>
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
</Page>

View File

@ -208,9 +208,10 @@ export class TabViewItem extends TabViewItemBase {
public _update(): void {
const tv = this.nativeViewProtected;
if (tv) {
const tabLayout = <org.nativescript.widgets.TabLayout>tv.getParent();
tabLayout.updateItemAt(this.index, this.tabItemSpec);
const tabView = this.parent as TabView;
if (tv && tabView) {
this.tabItemSpec = createTabItemSpec(this);
tabView.updateAndroidItemAt(this.index, this.tabItemSpec);
}
}
@ -382,6 +383,10 @@ export class TabView extends TabViewBase {
this._pagerAdapter.notifyDataSetChanged();
}
public updateAndroidItemAt(index: number, spec: org.nativescript.widgets.TabItemSpec) {
this._tabLayout.updateItemAt(index, spec);
}
[androidOffscreenTabLimitProperty.getDefault](): number {
return this._viewPager.getOffscreenPageLimit();
}