mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
244 lines
8.6 KiB
TypeScript
244 lines
8.6 KiB
TypeScript
// Types
|
|
import { TabStripItem as TabStripItemDefinition } from ".";
|
|
import { PropertyChangeData } from "../../../data/observable";
|
|
import { TabNavigationBase } from "../tab-navigation-base";
|
|
import { TabStrip } from "../tab-strip";
|
|
import { Image } from "../../image/image";
|
|
import { Label } from "../../label/label";
|
|
import { Color } from "../../../color";
|
|
import { AddChildFromBuilder } from "../../core/view";
|
|
|
|
// Requires
|
|
import {
|
|
View, ViewBase, CSSType, backgroundColorProperty, backgroundInternalProperty, PseudoClassHandler
|
|
} from "../../core/view";
|
|
import { Tabs } from "../../tabs";
|
|
import { isIOS } from "../../../platform";
|
|
|
|
export * from "../../core/view";
|
|
export const traceCategory = "TabView";
|
|
|
|
@CSSType("TabStripItem")
|
|
export class TabStripItem extends View implements TabStripItemDefinition, AddChildFromBuilder {
|
|
public static tapEvent = "tap";
|
|
public static selectEvent = "select";
|
|
public static unselectEvent = "unselect";
|
|
|
|
public image: Image;
|
|
public label: Label;
|
|
|
|
private _title: string;
|
|
private _iconSource: string;
|
|
|
|
private _highlightedHandler: () => void;
|
|
private _normalHandler: () => void;
|
|
|
|
private _labelColorHandler: (args: PropertyChangeData) => void;
|
|
private _labelFontHandler: (args: PropertyChangeData) => void;
|
|
private _labelTextTransformHandler: (args: PropertyChangeData) => void;
|
|
private _labelTextHandler: (args: PropertyChangeData) => void;
|
|
|
|
private _imageColorHandler: (args: PropertyChangeData) => void;
|
|
private _imageFontHandler: (args: PropertyChangeData) => void;
|
|
private _imageSrcHandler: (args: PropertyChangeData) => void;
|
|
|
|
get title(): string {
|
|
if (this.isLoaded) {
|
|
return this.label.text;
|
|
}
|
|
|
|
return this._title;
|
|
}
|
|
|
|
set title(value: string) {
|
|
this._title = value;
|
|
|
|
if (this.isLoaded) {
|
|
this.label.text = value;
|
|
}
|
|
}
|
|
|
|
get iconSource(): string {
|
|
if (this.isLoaded) {
|
|
return this.image.src;
|
|
}
|
|
|
|
return this._iconSource;
|
|
}
|
|
|
|
set iconSource(value: string) {
|
|
this._iconSource = value;
|
|
|
|
if (this.isLoaded) {
|
|
this.image.src = value;
|
|
}
|
|
}
|
|
|
|
public onLoaded() {
|
|
if (!this.image) {
|
|
const image = new Image();
|
|
image.src = this.iconSource;
|
|
this.image = image;
|
|
this._addView(this.image);
|
|
}
|
|
|
|
if (!this.label) {
|
|
const label = new Label();
|
|
label.text = this.title;
|
|
this.label = label;
|
|
this._addView(this.label);
|
|
}
|
|
|
|
super.onLoaded();
|
|
|
|
this._labelColorHandler = this._labelColorHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && tabStripParent.setTabBarItemColor(this, args.value);
|
|
});
|
|
this.label.style.on("colorChange", this._labelColorHandler);
|
|
|
|
this._labelFontHandler = this._labelFontHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && tabStripParent.setTabBarItemFontInternal(this, args.value);
|
|
});
|
|
this.label.style.on("fontInternalChange", this._labelFontHandler);
|
|
|
|
this._labelTextTransformHandler = this._labelTextTransformHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && tabStripParent.setTabBarItemTextTransform(this, args.value);
|
|
});
|
|
this.label.style.on("textTransformChange", this._labelTextTransformHandler);
|
|
|
|
this._labelTextHandler = this._labelTextHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && tabStripParent.setTabBarItemTitle(this, args.value);
|
|
});
|
|
this.label.on("textChange", this._labelTextHandler);
|
|
|
|
this._imageColorHandler = this._imageColorHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && (<any>tabStripParent).setTabBarIconColor(this, args.value);
|
|
});
|
|
this.image.style.on("colorChange", this._imageColorHandler);
|
|
|
|
this._imageFontHandler = this._imageFontHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && (<any>tabStripParent).setTabBarIconColor(this, args.value);
|
|
});
|
|
this.image.style.on("fontInternalChange", this._imageFontHandler);
|
|
|
|
this._imageSrcHandler = this._imageSrcHandler || ((args: PropertyChangeData) => {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && (<any>tabStripParent).setTabBarIconColor(this, args.value);
|
|
});
|
|
this.image.on("srcChange", this._imageSrcHandler);
|
|
}
|
|
|
|
public onUnloaded() {
|
|
super.onUnloaded();
|
|
|
|
this.label.style.off("colorChange", this._labelColorHandler);
|
|
this.label.style.off("fontInternalChange", this._labelFontHandler);
|
|
this.label.style.off("textTransformChange", this._labelTextTransformHandler);
|
|
this.label.style.off("textChange", this._labelTextHandler);
|
|
|
|
this.image.style.off("colorChange", this._imageColorHandler);
|
|
this.image.style.off("fontInternalChange", this._imageFontHandler);
|
|
this.image.style.off("srcChange", this._imageSrcHandler);
|
|
}
|
|
|
|
public eachChild(callback: (child: ViewBase) => boolean) {
|
|
if (this.label) {
|
|
callback(this.label);
|
|
}
|
|
|
|
if (this.image) {
|
|
callback(this.image);
|
|
}
|
|
}
|
|
|
|
public _addChildFromBuilder(name: string, value: any): void {
|
|
if (name === "Image") {
|
|
this.image = <Image>value;
|
|
this.iconSource = (<Image>value).src;
|
|
this._addView(value);
|
|
// selectedIndexProperty.coerce(this);
|
|
}
|
|
|
|
if (name === "Label") {
|
|
this.label = <Label>value;
|
|
this.title = (<Label>value).text;
|
|
this._addView(value);
|
|
// selectedIndexProperty.coerce(this);
|
|
}
|
|
}
|
|
|
|
public requestLayout(): void {
|
|
// Default implementation for non View instances (like TabViewItem).
|
|
const parent = this.parent;
|
|
if (parent) {
|
|
parent.requestLayout();
|
|
}
|
|
}
|
|
|
|
@PseudoClassHandler("normal", "highlighted", "pressed", "active")
|
|
_updateTabStateChangeHandler(subscribe: boolean) {
|
|
if (subscribe) {
|
|
this._highlightedHandler = this._highlightedHandler || (() => {
|
|
this._goToVisualState("highlighted");
|
|
});
|
|
|
|
this._normalHandler = this._normalHandler || (() => {
|
|
this._goToVisualState("normal");
|
|
});
|
|
|
|
this.on(TabStripItem.selectEvent, this._highlightedHandler);
|
|
this.on(TabStripItem.unselectEvent, this._normalHandler);
|
|
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
if ((<any>this).index === tabStripParent.selectedIndex &&
|
|
!(isIOS && tabStripParent instanceof Tabs)) {
|
|
this._goToVisualState("highlighted");
|
|
}
|
|
} else {
|
|
this.off(TabStripItem.selectEvent, this._highlightedHandler);
|
|
this.off(TabStripItem.unselectEvent, this._normalHandler);
|
|
}
|
|
}
|
|
|
|
[backgroundColorProperty.getDefault](): Color {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && tabStripParent.getTabBarBackgroundColor();
|
|
}
|
|
[backgroundColorProperty.setNative](value: Color) {
|
|
const parent = <TabStrip>this.parent;
|
|
const tabStripParent = parent && <TabNavigationBase>parent.parent;
|
|
|
|
return tabStripParent && tabStripParent.setTabBarItemBackgroundColor(this, value);
|
|
}
|
|
|
|
[backgroundInternalProperty.getDefault](): any {
|
|
return null;
|
|
}
|
|
[backgroundInternalProperty.setNative](value: any) {
|
|
// disable the background CSS properties
|
|
}
|
|
}
|