mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
feat: Scoped Packages (#7911)
* 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
This commit is contained in:

committed by
GitHub

parent
6c7139477e
commit
cc97a16800
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "tab-navigation-base",
|
||||
"main": "tab-navigation-base",
|
||||
"types": "tab-navigation-base.d.ts"
|
||||
}
|
224
nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts
vendored
Normal file
224
nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts
vendored
Normal file
@ -0,0 +1,224 @@
|
||||
/**
|
||||
* Contains the TabNavigationBase class, which serves as the base class for tab navigation.
|
||||
* @module "ui/tab-navigation/tab-navigation-base"
|
||||
*/ /** */
|
||||
|
||||
import {
|
||||
View, ViewBase, Property, CoercibleProperty, isIOS, AddArrayFromBuilder, AddChildFromBuilder, EventData
|
||||
} from "../../core/view";
|
||||
import { TabStrip } from "../tab-strip";
|
||||
import { TabStripItem } from "../tab-strip-item";
|
||||
import { TabContentItem } from "../tab-content-item";
|
||||
|
||||
/**
|
||||
* Defines the data for the tab navigation selectedIndexChanged event.
|
||||
*/
|
||||
export interface SelectedIndexChangedEventData extends EventData {
|
||||
/**
|
||||
* The old selected index.
|
||||
*/
|
||||
oldIndex: number;
|
||||
|
||||
/**
|
||||
* The new selected index.
|
||||
*/
|
||||
newIndex: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as a base class for tab navigation.
|
||||
*/
|
||||
export class TabNavigationBase extends View {
|
||||
/**
|
||||
* Gets or sets the items of the tab navigation.
|
||||
*/
|
||||
items: Array<TabContentItem>;
|
||||
|
||||
/**
|
||||
* Gets or sets the tab strip of the tab navigation.
|
||||
*/
|
||||
tabStrip: TabStrip;
|
||||
|
||||
/**
|
||||
* Gets or sets the selectedIndex of the tab navigation.
|
||||
*/
|
||||
selectedIndex: number;
|
||||
|
||||
/**
|
||||
* Gets the native android widget that represents the user interface for this component. Valid only when running on Android OS.
|
||||
*/
|
||||
android: any /* android.view.View */; //android.support.v4.view.ViewPager;
|
||||
|
||||
/**
|
||||
* Gets the native iOS widget that represents the user interface for this component. Valid only when running on iOS.
|
||||
*/
|
||||
ios: any /* UITabBarController */;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Raised when the selected index changes.
|
||||
*/
|
||||
on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
onItemsChanged(oldItems: TabContentItem[], newItems: TabContentItem[]): void;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
onSelectedIndexChanged(oldIndex: number, newIndex: number): void;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarBackgroundColor(): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarBackgroundColor(value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarColor(): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarColor(value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarFontInternal(): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarFontInternal(value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarTextTransform(): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarTextTransform(value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarHighlightColor(): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarHighlightColor(value: any)
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarItemTitle(tabStripItem: TabStripItem, value: any): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarItemBackgroundColor(tabStripItem: TabStripItem): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarItemBackgroundColor(tabStripItem: TabStripItem, value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarItemColor(tabStripItem: TabStripItem): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarItemColor(tabStripItem: TabStripItem, value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarIconColor(tabStripItem: TabStripItem, value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarItemFontSize(tabStripItem: TabStripItem): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarItemFontSize(tabStripItem: TabStripItem, value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarItemFontInternal(tabStripItem: TabStripItem): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarItemFontInternal(tabStripItem: TabStripItem, value: any): void
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
getTabBarItemTextTransform(tabStripItem: TabStripItem): any
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method is intended to be overridden by inheritors and used as "protected"
|
||||
*/
|
||||
setTabBarItemTextTransform(tabStripItem: TabStripItem, value: any): void
|
||||
}
|
||||
|
||||
export function getIconSpecSize(size: { width: number, height: number }): { width: number, height: number }
|
||||
|
||||
export const itemsProperty: Property<TabNavigationBase, TabContentItem[]>;
|
||||
export const tabStripProperty: Property<TabNavigationBase, TabStrip>
|
||||
export const selectedIndexProperty: CoercibleProperty<TabNavigationBase, number>;
|
@ -0,0 +1,282 @@
|
||||
// Types
|
||||
import { TabNavigationBase as TabNavigationBaseDefinition, SelectedIndexChangedEventData } from ".";
|
||||
import { TabContentItem } from "../tab-content-item";
|
||||
import { TabStrip } from "../tab-strip";
|
||||
import { TabStripItem } from "../tab-strip-item";
|
||||
import { ViewBase, AddArrayFromBuilder, AddChildFromBuilder, EventData } from "../../core/view";
|
||||
|
||||
// Requires
|
||||
import { View, Property, CoercibleProperty, isIOS, Color } from "../../core/view";
|
||||
|
||||
// TODO: Impl trace
|
||||
// export const traceCategory = "TabView";
|
||||
|
||||
export module knownCollections {
|
||||
export const items = "items";
|
||||
}
|
||||
|
||||
export class TabNavigationBase extends View implements TabNavigationBaseDefinition, AddChildFromBuilder, AddArrayFromBuilder {
|
||||
public static selectedIndexChangedEvent = "selectedIndexChanged";
|
||||
|
||||
public items: TabContentItem[];
|
||||
public tabStrip: TabStrip;
|
||||
public selectedIndex: number;
|
||||
|
||||
public _addArrayFromBuilder(name: string, value: Array<any>) {
|
||||
if (name === "items") {
|
||||
this.items = value;
|
||||
}
|
||||
}
|
||||
|
||||
public _addChildFromBuilder(name: string, value: any): void {
|
||||
if (name === "TabContentItem") {
|
||||
if (!this.items) {
|
||||
this.items = new Array<TabContentItem>();
|
||||
}
|
||||
this.items.push(<TabContentItem>value);
|
||||
this._addView(value);
|
||||
// selectedIndexProperty.coerce(this);
|
||||
} else if (name === "TabStrip") {
|
||||
// Setting tabStrip will trigger onTabStripChanged
|
||||
this.tabStrip = value;
|
||||
}
|
||||
}
|
||||
|
||||
get _selectedView(): View {
|
||||
let selectedIndex = this.selectedIndex;
|
||||
|
||||
return selectedIndex > -1 ? this.items[selectedIndex].content : null;
|
||||
}
|
||||
|
||||
get _childrenCount(): number {
|
||||
const items = this.items;
|
||||
|
||||
return items ? items.length : 0;
|
||||
}
|
||||
|
||||
public eachChild(callback: (child: ViewBase) => boolean) {
|
||||
const items = this.items;
|
||||
if (items) {
|
||||
items.forEach((item, i) => {
|
||||
callback(item);
|
||||
});
|
||||
}
|
||||
|
||||
const tabStrip = this.tabStrip;
|
||||
if (tabStrip) {
|
||||
callback(tabStrip);
|
||||
}
|
||||
}
|
||||
|
||||
public eachChildView(callback: (child: View) => boolean) {
|
||||
const items = this.items;
|
||||
if (items) {
|
||||
items.forEach((item, i) => {
|
||||
callback(item.content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public onItemsChanged(oldItems: TabContentItem[], newItems: TabContentItem[]): void {
|
||||
if (oldItems) {
|
||||
oldItems.forEach(item => this._removeView(item));
|
||||
}
|
||||
|
||||
if (newItems) {
|
||||
newItems.forEach(item => {
|
||||
if (!item.content) {
|
||||
throw new Error(`TabContentItem must have a content (view).`);
|
||||
}
|
||||
|
||||
this._addView(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public onTabStripChanged(oldTabStrip: TabStrip, newTabStrip: TabStrip) {
|
||||
if (oldTabStrip && oldTabStrip.parent) {
|
||||
this._removeView(oldTabStrip);
|
||||
}
|
||||
|
||||
if (newTabStrip) {
|
||||
this._addView(newTabStrip);
|
||||
}
|
||||
}
|
||||
|
||||
public onSelectedIndexChanged(oldIndex: number, newIndex: number): void {
|
||||
// to be overridden in platform specific files
|
||||
this.notify(<SelectedIndexChangedEventData>{ eventName: TabNavigationBase.selectedIndexChangedEvent, object: this, oldIndex, newIndex });
|
||||
}
|
||||
|
||||
public getTabBarBackgroundColor(): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarBackgroundColor(value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarFontInternal(): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarFontInternal(value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarTextTransform(): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarTextTransform(value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarHighlightColor(): any {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public setTabBarHighlightColor(value: any) {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarColor(): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarColor(value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public setTabBarItemTitle(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarItemBackgroundColor(tabStripItem: TabStripItem): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarItemBackgroundColor(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarItemColor(tabStripItem: TabStripItem): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarItemColor(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public setTabBarIconColor(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarItemFontSize(tabStripItem: TabStripItem): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarItemFontSize(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarItemFontInternal(tabStripItem: TabStripItem): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
|
||||
public getTabBarItemTextTransform(tabStripItem: TabStripItem): any {
|
||||
// overridden by inheritors
|
||||
return null;
|
||||
}
|
||||
|
||||
public setTabBarItemTextTransform(tabStripItem: TabStripItem, value: any): void {
|
||||
// overridden by inheritors
|
||||
}
|
||||
}
|
||||
|
||||
export interface TabNavigationBase {
|
||||
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
|
||||
on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
|
||||
}
|
||||
|
||||
const MIN_ICON_SIZE = 24;
|
||||
const MAX_ICON_WIDTH = 31;
|
||||
const MAX_ICON_HEIGHT = 28;
|
||||
|
||||
export function getIconSpecSize(size: { width: number, height: number }): { width: number, height: number } {
|
||||
const inWidth = size.width;
|
||||
const inHeight = size.height;
|
||||
let outWidth = 0;
|
||||
let outHeight = 0;
|
||||
|
||||
if (inWidth < inHeight) {
|
||||
outWidth = MIN_ICON_SIZE;
|
||||
outHeight = (inHeight * MIN_ICON_SIZE) / inWidth;
|
||||
if (outHeight > MAX_ICON_HEIGHT) {
|
||||
outHeight = MAX_ICON_HEIGHT;
|
||||
outWidth = (inWidth * MAX_ICON_HEIGHT) / inHeight;
|
||||
}
|
||||
} else {
|
||||
outHeight = MIN_ICON_SIZE;
|
||||
outWidth = (inWidth * MIN_ICON_SIZE) / inHeight;
|
||||
if (outWidth > MAX_ICON_WIDTH) {
|
||||
outWidth = MAX_ICON_WIDTH;
|
||||
outHeight = (inHeight * MAX_ICON_WIDTH) / inWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return { width: outWidth, height: outHeight };
|
||||
}
|
||||
|
||||
export const selectedIndexProperty = new CoercibleProperty<TabNavigationBase, 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;
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
valueConverter: (v) => parseInt(v)
|
||||
});
|
||||
selectedIndexProperty.register(TabNavigationBase);
|
||||
|
||||
export const _tabs = new Array<WeakRef<TabNavigationBase>>();
|
||||
|
||||
export const itemsProperty = new Property<TabNavigationBase, TabContentItem[]>({
|
||||
name: "items", valueChanged: (target, oldValue, newValue) => {
|
||||
target.onItemsChanged(oldValue, newValue);
|
||||
}
|
||||
});
|
||||
itemsProperty.register(TabNavigationBase);
|
||||
|
||||
export const tabStripProperty = new Property<TabNavigationBase, TabStrip>({
|
||||
name: "tabStrip", valueChanged: (target, oldValue, newValue) => {
|
||||
target.onTabStripChanged(oldValue, newValue);
|
||||
}
|
||||
});
|
||||
tabStripProperty.register(TabNavigationBase);
|
Reference in New Issue
Block a user