mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +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("tabmore", "tab-view/tab-view-more");
|
||||||
examples.set("tabViewCss", "tab-view/tab-view-css");
|
examples.set("tabViewCss", "tab-view/tab-view-css");
|
||||||
examples.set("tab-view-icons", "tab-view/tab-view-icon");
|
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");
|
examples.set("text-transform", "tab-view/text-transform");
|
||||||
return examples;
|
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;
|
const DEFAULT_ELEVATION = 4;
|
||||||
|
|
||||||
interface PagerAdapter {
|
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 {
|
interface PageChangedListener {
|
||||||
new (owner: TabView): android.support.v4.view.ViewPager.SimpleOnPageChangeListener;
|
new(owner: TabView): android.support.v4.view.ViewPager.SimpleOnPageChangeListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
let PagerAdapter: PagerAdapter;
|
let PagerAdapter: PagerAdapter;
|
||||||
@@ -87,7 +87,7 @@ function initializeNativeClasses() {
|
|||||||
container.removeView(nativeView);
|
container.removeView(nativeView);
|
||||||
|
|
||||||
// Note: this.owner._removeView will clear item.view.nativeView.
|
// Note: this.owner._removeView will clear item.view.nativeView.
|
||||||
// So call this after the native instance is removed form the container.
|
// So call this after the native instance is removed form the container.
|
||||||
// if (item.view.parent === this.owner) {
|
// if (item.view.parent === this.owner) {
|
||||||
// this.owner._removeView(item.view);
|
// this.owner._removeView(item.view);
|
||||||
// }
|
// }
|
||||||
@@ -208,9 +208,10 @@ export class TabViewItem extends TabViewItemBase {
|
|||||||
|
|
||||||
public _update(): void {
|
public _update(): void {
|
||||||
const tv = this.nativeViewProtected;
|
const tv = this.nativeViewProtected;
|
||||||
if (tv) {
|
const tabView = this.parent as TabView;
|
||||||
const tabLayout = <org.nativescript.widgets.TabLayout>tv.getParent();
|
if (tv && tabView) {
|
||||||
tabLayout.updateItemAt(this.index, this.tabItemSpec);
|
this.tabItemSpec = createTabItemSpec(this);
|
||||||
|
tabView.updateAndroidItemAt(this.index, this.tabItemSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +314,7 @@ export class TabView extends TabViewBase {
|
|||||||
const listener = new PageChangedListener(this);
|
const listener = new PageChangedListener(this);
|
||||||
(<any>viewPager).addOnPageChangeListener(listener);
|
(<any>viewPager).addOnPageChangeListener(listener);
|
||||||
(<any>viewPager).listener = listener;
|
(<any>viewPager).listener = listener;
|
||||||
|
|
||||||
const adapter = new PagerAdapter(this, null);
|
const adapter = new PagerAdapter(this, null);
|
||||||
viewPager.setAdapter(adapter);
|
viewPager.setAdapter(adapter);
|
||||||
(<any>viewPager).adapter = adapter;
|
(<any>viewPager).adapter = adapter;
|
||||||
@@ -382,6 +383,10 @@ export class TabView extends TabViewBase {
|
|||||||
this._pagerAdapter.notifyDataSetChanged();
|
this._pagerAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public updateAndroidItemAt(index: number, spec: org.nativescript.widgets.TabItemSpec) {
|
||||||
|
this._tabLayout.updateItemAt(index, spec);
|
||||||
|
}
|
||||||
|
|
||||||
[androidOffscreenTabLimitProperty.getDefault](): number {
|
[androidOffscreenTabLimitProperty.getDefault](): number {
|
||||||
return this._viewPager.getOffscreenPageLimit();
|
return this._viewPager.getOffscreenPageLimit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user