chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -1,70 +1,70 @@
import { View } from "../../core/view";
import { Image } from "../../image";
import { Label } from "../../label";
import { EventData } from "../../../data/observable"
import { EventData } from "../../../data/observable";
/**
* Represents a tab strip entry.
*/
export class TabStripItem extends View {
/**
* Gets or sets the title of the tab strip entry.
*/
title: string;
/**
* Gets or sets the title of the tab strip entry.
*/
title: string;
/**
* Gets or sets the CSS class name of the icon in the tab strip entry.
*/
iconClass: string;
/**
* Gets or sets the CSS class name of the icon in the tab strip entry.
*/
iconClass: string;
/**
* Gets or sets the icon source of the tab strip entry.
*/
iconSource: string;
/**
* Gets or sets the icon source of the tab strip entry.
*/
iconSource: string;
/**
* Gets or sets the label of the tab strip entry.
*/
label: Label;
/**
* Gets or sets the label of the tab strip entry.
*/
label: Label;
/**
* Gets or sets the image of the tab strip entry.
*/
image: Image;
/**
* Gets or sets the image of the tab strip entry.
*/
image: Image;
/**
* String value used when hooking to the tap event.
*/
public static tapEvent: string;
/**
* String value used when hooking to the tap event.
*/
public static tapEvent: string;
//@private
//@private
/**
* @private
*/
_index: number;
/**
* @private
*/
_index: number;
/**
* @private
*/
static selectEvent: string;
/**
* @private
*/
static selectEvent: string;
/**
* @private
*/
static unselectEvent: string;
//@endprivate
/**
* @private
*/
static unselectEvent: string;
//@endprivate
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void);
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void);
/**
* Raised when a tap event occurs.
*/
on(event: "tap", callback: (args: EventData) => void);
/**
* Raised when a tap event occurs.
*/
on(event: "tap", callback: (args: EventData) => void);
}

View File

@@ -7,271 +7,335 @@ import { Color } from "../../../color";
import { AddChildFromBuilder, PseudoClassHandler } from "../../core/view";
// Requires
import {
View, CSSType
} from "../../core/view";
import { View, CSSType } from "../../core/view";
import { ViewBase } from "../../core/view-base";
import { backgroundColorProperty, backgroundInternalProperty } from "../../styling/style-properties";
import {
backgroundColorProperty,
backgroundInternalProperty,
} from "../../styling/style-properties";
import { isIOS } from "../../../platform";
import { Image } from "../../image";
import { Label } from "../../label";
import { textTransformProperty, TextTransform } from "../../text-base";
@CSSType("TabStripItem")
export class TabStripItem extends View implements TabStripItemDefinition, AddChildFromBuilder {
public static tapEvent = "tap";
public static selectEvent = "select";
public static unselectEvent = "unselect";
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;
public _index: number;
public image: Image;
public label: Label;
public _index: number;
private _title: string;
private _iconSource: string;
private _iconClass: string;
private _title: string;
private _iconSource: string;
private _iconClass: string;
private _highlightedHandler: () => void;
private _normalHandler: () => void;
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 _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;
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;
}
get title(): string {
if (this.isLoaded) {
return this.label.text;
}
return this._title;
}
return this._title;
}
set title(value: string) {
this._title = value;
set title(value: string) {
this._title = value;
if (this.isLoaded) {
this.label.text = value;
}
}
if (this.isLoaded) {
this.label.text = value;
}
}
get iconClass(): string {
if (this.isLoaded) {
return this.image.className;
}
get iconClass(): string {
if (this.isLoaded) {
return this.image.className;
}
return this._iconClass;
}
return this._iconClass;
}
set iconClass(value: string) {
this._iconClass = value;
set iconClass(value: string) {
this._iconClass = value;
if (this.isLoaded) {
this.image.className = value;
}
}
if (this.isLoaded) {
this.image.className = value;
}
}
get iconSource(): string {
if (this.isLoaded) {
return this.image.src;
}
get iconSource(): string {
if (this.isLoaded) {
return this.image.src;
}
return this._iconSource;
}
return this._iconSource;
}
set iconSource(value: string) {
this._iconSource = value;
set iconSource(value: string) {
this._iconSource = value;
if (this.isLoaded) {
this.image.src = value;
}
}
if (this.isLoaded) {
this.image.src = value;
}
}
public onLoaded() {
if (!this.image) {
const image = new Image();
image.src = this.iconSource;
image.className = this.iconClass;
this.image = image;
this._addView(this.image);
}
public onLoaded() {
if (!this.image) {
const image = new Image();
image.src = this.iconSource;
image.className = this.iconClass;
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);
}
if (!this.label) {
const label = new Label();
label.text = this.title;
this.label = label;
this._addView(this.label);
}
super.onLoaded();
super.onLoaded();
this._labelColorHandler = this._labelColorHandler || ((args: PropertyChangeData) => {
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
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);
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;
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);
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;
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);
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;
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);
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;
this._imageColorHandler =
this._imageColorHandler ||
((args: PropertyChangeData) => {
const parent = <TabStrip>this.parent;
const tabStripParent =
parent && <TabNavigationBase>parent.parent;
return tabStripParent && tabStripParent.setTabBarIconColor(this, args.value);
});
this.image.style.on("colorChange", this._imageColorHandler);
return (
tabStripParent &&
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;
this._imageFontHandler =
this._imageFontHandler ||
((args: PropertyChangeData) => {
const parent = <TabStrip>this.parent;
const tabStripParent =
parent && <TabNavigationBase>parent.parent;
return tabStripParent && tabStripParent.setTabBarIconColor(this, args.value);
});
this.image.style.on("fontInternalChange", this._imageFontHandler);
return (
tabStripParent &&
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;
this._imageSrcHandler =
this._imageSrcHandler ||
((args: PropertyChangeData) => {
const parent = <TabStrip>this.parent;
const tabStripParent =
parent && <TabNavigationBase>parent.parent;
return tabStripParent && tabStripParent.setTabBarIconSource(this, args.value);
});
this.image.on("srcChange", this._imageSrcHandler);
}
return (
tabStripParent &&
tabStripParent.setTabBarIconSource(this, args.value)
);
});
this.image.on("srcChange", this._imageSrcHandler);
}
public onUnloaded() {
super.onUnloaded();
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.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);
}
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);
}
public eachChild(callback: (child: ViewBase) => boolean) {
if (this.label) {
callback(this.label);
}
if (this.image) {
callback(this.image);
}
}
if (this.image) {
callback(this.image);
}
}
public _addChildFromBuilder(name: string, value: any): void {
if (value instanceof Image) {
this.image = <Image>value;
this.iconSource = (<Image>value).src;
this.iconClass = (<Image>value).className;
this._addView(value);
// selectedIndexProperty.coerce(this);
}
public _addChildFromBuilder(name: string, value: any): void {
if (value instanceof Image) {
this.image = <Image>value;
this.iconSource = (<Image>value).src;
this.iconClass = (<Image>value).className;
this._addView(value);
// selectedIndexProperty.coerce(this);
}
if (value instanceof Label) {
this.label = <Label>value;
this.title = (<Label>value).text;
this._addView(value);
// selectedIndexProperty.coerce(this);
}
}
if (value instanceof 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();
}
}
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");
});
@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._normalHandler =
this._normalHandler ||
(() => {
this._goToVisualState("normal");
});
this.on(TabStripItem.selectEvent, this._highlightedHandler);
this.on(TabStripItem.unselectEvent, this._normalHandler);
this.on(TabStripItem.selectEvent, this._highlightedHandler);
this.on(TabStripItem.unselectEvent, this._normalHandler);
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
if (this._index === tabStripParent.selectedIndex &&
!(isIOS && tabStripParent.cssType.toLowerCase() === "tabs")) {
// HACK: tabStripParent instanceof Tabs creates a circular dependency
// HACK: tabStripParent.cssType === "Tabs" is a hacky workaround
this._goToVisualState("highlighted");
}
} else {
this.off(TabStripItem.selectEvent, this._highlightedHandler);
this.off(TabStripItem.unselectEvent, this._normalHandler);
}
}
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
if (
this._index === tabStripParent.selectedIndex &&
!(isIOS && tabStripParent.cssType.toLowerCase() === "tabs")
) {
// HACK: tabStripParent instanceof Tabs creates a circular dependency
// HACK: tabStripParent.cssType === "Tabs" is a hacky workaround
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;
[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.getTabBarBackgroundColor();
}
[backgroundColorProperty.setNative](value: Color) {
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
return tabStripParent && tabStripParent.setTabBarItemBackgroundColor(this, value);
}
return (
tabStripParent &&
tabStripParent.setTabBarItemBackgroundColor(this, value)
);
}
[textTransformProperty.getDefault](): TextTransform {
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
[textTransformProperty.getDefault](): TextTransform {
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
return tabStripParent && tabStripParent.getTabBarItemTextTransform(this);
}
[textTransformProperty.setNative](value: TextTransform) {
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
return (
tabStripParent && tabStripParent.getTabBarItemTextTransform(this)
);
}
[textTransformProperty.setNative](value: TextTransform) {
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
return tabStripParent && tabStripParent.setTabBarItemTextTransform(this, value);
}
return (
tabStripParent &&
tabStripParent.setTabBarItemTextTransform(this, value)
);
}
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
// disable the background CSS properties
}
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
// disable the background CSS properties
}
}