chore: default tabs

This commit is contained in:
Nathan Walker
2020-07-09 23:46:02 -07:00
parent 8100cf7089
commit 41f0573d8e
353 changed files with 55344 additions and 55344 deletions

View File

File diff suppressed because it is too large Load Diff

View File

@@ -13,141 +13,141 @@ import { TextTransform } from '../text-base';
* Represents a tab view entry.
*/
export class TabViewItem extends ViewBase {
/**
* Gets or sets the title of the TabViewItem.
*/
public title: string;
/**
* Gets or sets the title of the TabViewItem.
*/
public title: string;
/**
* Gets or sets the view of the TabViewItem.
*/
public view: View;
/**
* Gets or sets the view of the TabViewItem.
*/
public view: View;
/**
* Gets or sets the icon source of the TabViewItem. This could either be a a file name or resource id.
*/
public iconSource: string;
/**
* Gets or sets the icon source of the TabViewItem. This could either be a a file name or resource id.
*/
public iconSource: string;
/**
* Gets or sets the text transform of the tab titles.
*/
textTransform: TextTransform;
/**
* Gets or sets the text transform of the tab titles.
*/
textTransform: TextTransform;
/**
* @private
*/
canBeLoaded?: boolean;
/**
* @private
*/
canBeLoaded?: boolean;
}
/**
* Defines the data for the TabView.selectedIndexChanged event.
*/
export interface SelectedIndexChangedEventData extends EventData {
/**
* The old selected index.
*/
oldIndex: number;
/**
* The old selected index.
*/
oldIndex: number;
/**
* The new selected index.
*/
newIndex: number;
/**
* The new selected index.
*/
newIndex: number;
}
/**
* Represents a tab view.
*/
export class TabView extends View {
/**
* Gets or sets the items of the TabView.
*/
items: Array<TabViewItem>;
/**
* Gets or sets the items of the TabView.
*/
items: Array<TabViewItem>;
/**
* Gets or sets the selectedIndex of the TabView.
*/
selectedIndex: number;
/**
* Gets or sets the selectedIndex of the TabView.
*/
selectedIndex: number;
/**
* Gets or sets the font size of the tabs titles.
*/
tabTextFontSize: number;
/**
* Gets or sets the font size of the tabs titles.
*/
tabTextFontSize: number;
/**
* Gets or sets the text color of the tabs titles.
*/
tabTextColor: Color;
/**
* Gets or sets the text color of the tabs titles.
*/
tabTextColor: Color;
/**
* Gets or sets the background color of the tabs.
*/
tabBackgroundColor: Color;
/**
* Gets or sets the background color of the tabs.
*/
tabBackgroundColor: Color;
/**
* Gets or sets the text color of the selected tab title.
*/
selectedTabTextColor: Color;
/**
* Gets or sets the text color of the selected tab title.
*/
selectedTabTextColor: Color;
/**
* Gets or sets the color of the horizontal line drawn below the currently selected tab on Android.
*/
androidSelectedTabHighlightColor: Color;
/**
* Gets or sets the color of the horizontal line drawn below the currently selected tab on Android.
*/
androidSelectedTabHighlightColor: Color;
/**
* Gets the native [android widget](http://developer.android.com/reference/android/support/v4/view/ViewPager.html) that represents the user interface for this component. Valid only when running on Android OS.
*/
android: any /* android.view.View */; //androidx.core.view.ViewPager;
/**
* Gets the native [android widget](http://developer.android.com/reference/android/support/v4/view/ViewPager.html) that represents the user interface for this component. Valid only when running on Android OS.
*/
android: any /* android.view.View */; //androidx.core.view.ViewPager;
/**
* Gets the native iOS [UITabBarController](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/) that represents the user interface for this component. Valid only when running on iOS.
*/
ios: any /* UITabBarController */;
/**
* Gets the native iOS [UITabBarController](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/) that represents the user interface for this component. Valid only when running on iOS.
*/
ios: any /* UITabBarController */;
/**
* Gets or set the UIImageRenderingMode of the tab icons in iOS. Defaults to "automatic"
* Valid values are:
* - automatic
* - alwaysOriginal
* - alwaysTemplate
*/
iosIconRenderingMode: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate';
/**
* Gets or set the UIImageRenderingMode of the tab icons in iOS. Defaults to "automatic"
* Valid values are:
* - automatic
* - alwaysOriginal
* - alwaysTemplate
*/
iosIconRenderingMode: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate';
/**
* Gets or sets the number of tabs that should be retained to either side of the current tab in the view hierarchy in an idle state.
* Tabs beyond this limit will be recreated from the TabView when needed.
*/
androidOffscreenTabLimit: number;
/**
* Gets or sets the number of tabs that should be retained to either side of the current tab in the view hierarchy in an idle state.
* Tabs beyond this limit will be recreated from the TabView when needed.
*/
androidOffscreenTabLimit: number;
/**
* Gets or set the tabs vertical position.
* Valid values are:
* - top
* - bottom
*/
androidTabsPosition: 'top' | 'bottom';
/**
* Gets or set the tabs vertical position.
* Valid values are:
* - top
* - bottom
*/
androidTabsPosition: 'top' | 'bottom';
/**
* Gets or sets a value indicating whether swipe gesture is enabled for Android.
*/
androidSwipeEnabled: boolean;
/**
* Gets or sets a value indicating whether swipe gesture is enabled for Android.
*/
androidSwipeEnabled: boolean;
/**
* String value used when hooking to the selectedIndexChanged event.
*/
public static selectedIndexChangedEvent: string;
/**
* String value used when hooking to the selectedIndexChanged event.
*/
public static selectedIndexChangedEvent: string;
/**
* 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, thisArg?: any);
/**
* 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, thisArg?: any);
/**
* Raised when the selected index changes.
*/
on(event: 'selectedIndexChanged', callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
/**
* Raised when the selected index changes.
*/
on(event: 'selectedIndexChanged', callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
}
export const itemsProperty: Property<TabView, TabViewItem[]>;

View File

File diff suppressed because it is too large Load Diff

View File

@@ -13,242 +13,242 @@ export const traceCategory = 'TabView';
@CSSType('TabViewItem')
export abstract class TabViewItemBase extends ViewBase implements TabViewItemDefinition, AddChildFromBuilder {
private _title: string = '';
private _view: View;
private _iconSource: string;
private _title: string = '';
private _view: View;
private _iconSource: string;
get textTransform(): TextTransform {
return this.style.textTransform;
}
set textTransform(value: TextTransform) {
this.style.textTransform = value;
}
get textTransform(): TextTransform {
return this.style.textTransform;
}
set textTransform(value: TextTransform) {
this.style.textTransform = value;
}
public _addChildFromBuilder(name: string, value: any): void {
if (value instanceof View) {
this.view = value;
}
}
public _addChildFromBuilder(name: string, value: any): void {
if (value instanceof View) {
this.view = value;
}
}
get title(): string {
return this._title;
}
set title(value: string) {
if (this._title !== value) {
this._title = value;
this._update();
}
}
get title(): string {
return this._title;
}
set title(value: string) {
if (this._title !== value) {
this._title = value;
this._update();
}
}
get view(): View {
return this._view;
}
set view(value: View) {
if (this._view !== value) {
if (this._view) {
throw new Error('Changing the view of an already loaded TabViewItem is not currently supported.');
}
get view(): View {
return this._view;
}
set view(value: View) {
if (this._view !== value) {
if (this._view) {
throw new Error('Changing the view of an already loaded TabViewItem is not currently supported.');
}
this._view = value;
this._addView(value);
}
}
this._view = value;
this._addView(value);
}
}
get iconSource(): string {
return this._iconSource;
}
set iconSource(value: string) {
if (this._iconSource !== value) {
this._iconSource = value;
this._update();
}
}
get iconSource(): string {
return this._iconSource;
}
set iconSource(value: string) {
if (this._iconSource !== value) {
this._iconSource = value;
this._update();
}
}
public eachChild(callback: (child: ViewBase) => boolean) {
const view = this._view;
if (view) {
callback(view);
}
}
public eachChild(callback: (child: ViewBase) => boolean) {
const view = this._view;
if (view) {
callback(view);
}
}
public loadView(view: ViewBase): void {
const tabView = this.parent as TabViewBase;
if (tabView && tabView.items) {
// Don't load items until their fragments are instantiated.
if ((<TabViewItemDefinition>this).canBeLoaded) {
super.loadView(view);
}
}
}
public loadView(view: ViewBase): void {
const tabView = this.parent as TabViewBase;
if (tabView && tabView.items) {
// Don't load items until their fragments are instantiated.
if ((<TabViewItemDefinition>this).canBeLoaded) {
super.loadView(view);
}
}
}
public abstract _update();
public abstract _update();
}
export module knownCollections {
export const items = 'items';
export const items = 'items';
}
@CSSType('TabView')
export class TabViewBase extends View implements TabViewDefinition, AddChildFromBuilder, AddArrayFromBuilder {
public static selectedIndexChangedEvent = 'selectedIndexChanged';
public static selectedIndexChangedEvent = 'selectedIndexChanged';
public items: TabViewItemDefinition[];
public selectedIndex: number;
public androidOffscreenTabLimit: number;
public androidTabsPosition: 'top' | 'bottom';
public androidSwipeEnabled: boolean;
public iosIconRenderingMode: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate';
public items: TabViewItemDefinition[];
public selectedIndex: number;
public androidOffscreenTabLimit: number;
public androidTabsPosition: 'top' | 'bottom';
public androidSwipeEnabled: boolean;
public iosIconRenderingMode: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate';
get androidSelectedTabHighlightColor(): Color {
return this.style.androidSelectedTabHighlightColor;
}
set androidSelectedTabHighlightColor(value: Color) {
this.style.androidSelectedTabHighlightColor = value;
}
get androidSelectedTabHighlightColor(): Color {
return this.style.androidSelectedTabHighlightColor;
}
set androidSelectedTabHighlightColor(value: Color) {
this.style.androidSelectedTabHighlightColor = value;
}
get tabTextFontSize(): number {
return this.style.tabTextFontSize;
}
set tabTextFontSize(value: number) {
this.style.tabTextFontSize = value;
}
get tabTextFontSize(): number {
return this.style.tabTextFontSize;
}
set tabTextFontSize(value: number) {
this.style.tabTextFontSize = value;
}
get tabTextColor(): Color {
return this.style.tabTextColor;
}
set tabTextColor(value: Color) {
this.style.tabTextColor = value;
}
get tabTextColor(): Color {
return this.style.tabTextColor;
}
set tabTextColor(value: Color) {
this.style.tabTextColor = value;
}
get tabBackgroundColor(): Color {
return this.style.tabBackgroundColor;
}
set tabBackgroundColor(value: Color) {
this.style.tabBackgroundColor = value;
}
get tabBackgroundColor(): Color {
return this.style.tabBackgroundColor;
}
set tabBackgroundColor(value: Color) {
this.style.tabBackgroundColor = value;
}
get selectedTabTextColor(): Color {
return this.style.selectedTabTextColor;
}
set selectedTabTextColor(value: Color) {
this.style.selectedTabTextColor = value;
}
get selectedTabTextColor(): Color {
return this.style.selectedTabTextColor;
}
set selectedTabTextColor(value: Color) {
this.style.selectedTabTextColor = value;
}
public _addArrayFromBuilder(name: string, value: Array<any>) {
if (name === 'items') {
this.items = value;
}
}
public _addArrayFromBuilder(name: string, value: Array<any>) {
if (name === 'items') {
this.items = value;
}
}
public _addChildFromBuilder(name: string, value: any): void {
if (value instanceof TabViewItemBase) {
if (!this.items) {
this.items = new Array<TabViewItemBase>();
}
this.items.push(<TabViewItemBase>value);
this._addView(value);
selectedIndexProperty.coerce(this);
}
}
public _addChildFromBuilder(name: string, value: any): void {
if (value instanceof TabViewItemBase) {
if (!this.items) {
this.items = new Array<TabViewItemBase>();
}
this.items.push(<TabViewItemBase>value);
this._addView(value);
selectedIndexProperty.coerce(this);
}
}
get _selectedView(): View {
let selectedIndex = this.selectedIndex;
get _selectedView(): View {
let selectedIndex = this.selectedIndex;
return selectedIndex > -1 ? this.items[selectedIndex].view : null;
}
return selectedIndex > -1 ? this.items[selectedIndex].view : null;
}
get _childrenCount(): number {
const items = this.items;
get _childrenCount(): number {
const items = this.items;
return items ? items.length : 0;
}
return items ? items.length : 0;
}
public eachChild(callback: (child: ViewBase) => boolean) {
const items = this.items;
if (items) {
items.forEach((item, i) => {
callback(item);
});
}
}
public eachChild(callback: (child: ViewBase) => boolean) {
const items = this.items;
if (items) {
items.forEach((item, i) => {
callback(item);
});
}
}
public eachChildView(callback: (child: View) => boolean) {
const items = this.items;
if (items) {
items.forEach((item, i) => {
callback(item.view);
});
}
}
public eachChildView(callback: (child: View) => boolean) {
const items = this.items;
if (items) {
items.forEach((item, i) => {
callback(item.view);
});
}
}
public onItemsChanged(oldItems: TabViewItemDefinition[], newItems: TabViewItemDefinition[]): void {
if (oldItems) {
oldItems.forEach((item) => this._removeView(item));
}
public onItemsChanged(oldItems: TabViewItemDefinition[], newItems: TabViewItemDefinition[]): void {
if (oldItems) {
oldItems.forEach((item) => this._removeView(item));
}
if (newItems) {
newItems.forEach((item) => {
if (!item.view) {
throw new Error(`TabViewItem must have a view.`);
}
if (newItems) {
newItems.forEach((item) => {
if (!item.view) {
throw new Error(`TabViewItem must have a view.`);
}
this._addView(item);
});
}
}
this._addView(item);
});
}
}
public onSelectedIndexChanged(oldIndex: number, newIndex: number): void {
// to be overridden in platform specific files
this.notify(<SelectedIndexChangedEventData>{
eventName: TabViewBase.selectedIndexChangedEvent,
object: this,
oldIndex,
newIndex,
});
}
public onSelectedIndexChanged(oldIndex: number, newIndex: number): void {
// to be overridden in platform specific files
this.notify(<SelectedIndexChangedEventData>{
eventName: TabViewBase.selectedIndexChangedEvent,
object: this,
oldIndex,
newIndex,
});
}
}
export interface TabViewBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: 'selectedIndexChanged', callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: 'selectedIndexChanged', callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
}
export function traceMissingIcon(icon: string) {
Trace.write('Could not load tab bar icon: ' + icon, Trace.categories.Error, Trace.messageType.error);
Trace.write('Could not load tab bar icon: ' + icon, Trace.categories.Error, Trace.messageType.error);
}
export const selectedIndexProperty = new CoercibleProperty<TabViewBase, number>({
name: 'selectedIndex',
defaultValue: -1,
affectsLayout: isIOS,
valueChanged: (target, oldValue, newValue) => {
target.onSelectedIndexChanged(oldValue, newValue);
},
coerceValue: (target, value) => {
let items = target.items;
if (items) {
let max = items.length - 1;
if (value < 0) {
value = 0;
}
if (value > max) {
value = max;
}
} else {
value = -1;
}
name: 'selectedIndex',
defaultValue: -1,
affectsLayout: isIOS,
valueChanged: (target, oldValue, newValue) => {
target.onSelectedIndexChanged(oldValue, newValue);
},
coerceValue: (target, value) => {
let items = target.items;
if (items) {
let max = items.length - 1;
if (value < 0) {
value = 0;
}
if (value > max) {
value = max;
}
} else {
value = -1;
}
return value;
},
valueConverter: (v) => parseInt(v),
return value;
},
valueConverter: (v) => parseInt(v),
});
selectedIndexProperty.register(TabViewBase);
export const itemsProperty = new Property<TabViewBase, TabViewItemDefinition[]>({
name: 'items',
valueChanged: (target, oldValue, newValue) => {
target.onItemsChanged(oldValue, newValue);
},
name: 'items',
valueChanged: (target, oldValue, newValue) => {
target.onItemsChanged(oldValue, newValue);
},
});
itemsProperty.register(TabViewBase);
@@ -256,10 +256,10 @@ export const iosIconRenderingModeProperty = new Property<TabViewBase, 'automatic
iosIconRenderingModeProperty.register(TabViewBase);
export const androidOffscreenTabLimitProperty = new Property<TabViewBase, number>({
name: 'androidOffscreenTabLimit',
defaultValue: 1,
affectsLayout: isIOS,
valueConverter: (v) => parseInt(v),
name: 'androidOffscreenTabLimit',
defaultValue: 1,
affectsLayout: isIOS,
valueConverter: (v) => parseInt(v),
});
androidOffscreenTabLimitProperty.register(TabViewBase);
@@ -267,47 +267,47 @@ export const androidTabsPositionProperty = new Property<TabViewBase, 'top' | 'bo
androidTabsPositionProperty.register(TabViewBase);
export const androidSwipeEnabledProperty = new Property<TabViewBase, boolean>({
name: 'androidSwipeEnabled',
defaultValue: true,
valueConverter: booleanConverter,
name: 'androidSwipeEnabled',
defaultValue: true,
valueConverter: booleanConverter,
});
androidSwipeEnabledProperty.register(TabViewBase);
export const tabTextFontSizeProperty = new CssProperty<Style, number>({
name: 'tabTextFontSize',
cssName: 'tab-text-font-size',
valueConverter: (v) => parseFloat(v),
name: 'tabTextFontSize',
cssName: 'tab-text-font-size',
valueConverter: (v) => parseFloat(v),
});
tabTextFontSizeProperty.register(Style);
export const tabTextColorProperty = new CssProperty<Style, Color>({
name: 'tabTextColor',
cssName: 'tab-text-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
name: 'tabTextColor',
cssName: 'tab-text-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
});
tabTextColorProperty.register(Style);
export const tabBackgroundColorProperty = new CssProperty<Style, Color>({
name: 'tabBackgroundColor',
cssName: 'tab-background-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
name: 'tabBackgroundColor',
cssName: 'tab-background-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
});
tabBackgroundColorProperty.register(Style);
export const selectedTabTextColorProperty = new CssProperty<Style, Color>({
name: 'selectedTabTextColor',
cssName: 'selected-tab-text-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
name: 'selectedTabTextColor',
cssName: 'selected-tab-text-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
});
selectedTabTextColorProperty.register(Style);
export const androidSelectedTabHighlightColorProperty = new CssProperty<Style, Color>({
name: 'androidSelectedTabHighlightColor',
cssName: 'android-selected-tab-highlight-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
name: 'androidSelectedTabHighlightColor',
cssName: 'android-selected-tab-highlight-color',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
});
androidSelectedTabHighlightColorProperty.register(Style);