mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 11:17:04 +08:00
Fixes TabView icons changes. (#4666)
* Fixes TabView icons/title changes. * Access TabLayput trough parent * TabView icon change example
This commit is contained in:

committed by
GitHub

parent
d8f0430fef
commit
50d399101e
@ -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;
|
||||
}
|
||||
|
17
apps/app/ui-tests-app/tab-view/tab-view-icon-change.ts
Normal file
17
apps/app/ui-tests-app/tab-view/tab-view-icon-change.ts
Normal 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";
|
||||
}
|
||||
}
|
16
apps/app/ui-tests-app/tab-view/tab-view-icon-change.xml
Normal file
16
apps/app/ui-tests-app/tab-view/tab-view-icon-change.xml
Normal 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>
|
@ -19,11 +19,11 @@ const PRIMARY_COLOR = "colorPrimary";
|
||||
const DEFAULT_ELEVATION = 4;
|
||||
|
||||
interface PagerAdapter {
|
||||
new (owner: TabView, items: Array<TabViewItem>): android.support.v4.view.PagerAdapter;
|
||||
new(owner: TabView, items: Array<TabViewItem>): android.support.v4.view.PagerAdapter;
|
||||
}
|
||||
|
||||
interface PageChangedListener {
|
||||
new (owner: TabView): android.support.v4.view.ViewPager.SimpleOnPageChangeListener;
|
||||
new(owner: TabView): android.support.v4.view.ViewPager.SimpleOnPageChangeListener;
|
||||
}
|
||||
|
||||
let PagerAdapter: PagerAdapter;
|
||||
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user