NativeScript Core Modules compatibility package for building native iOS and Android apps using JavaScript and CSS
—
Comprehensive set of native UI components and layout containers for building mobile application interfaces. All components render as native iOS and Android controls, providing platform-specific look, feel, and performance.
Foundation classes that all UI elements inherit from, providing common functionality for styling, events, and layout.
/**
* Base class for all UI elements providing core functionality
*/
class ViewBase {
// Core properties
id: string;
className: string;
style: Style;
parent: ViewBase;
isLoaded: boolean;
// Event handling
on(eventName: string, callback: Function): void;
off(eventName: string, callback?: Function): void;
notify(data: EventData): void;
// Lifecycle methods
addEventListener(arg: string | EventData, callback?: Function): void;
removeEventListener(arg: string | EventData, callback?: Function): void;
}
/**
* Enhanced base class with layout and visual properties
*/
class View extends ViewBase {
// Layout properties
width: number | string;
height: number | string;
minWidth: number;
minHeight: number;
margin: string | number;
padding: string | number;
// Visual properties
visibility: "visible" | "hidden" | "collapse";
opacity: number;
backgroundColor: string;
color: string;
// Transform properties
translateX: number;
translateY: number;
scaleX: number;
scaleY: number;
rotate: number;
// Layout methods
measure(widthMeasureSpec: number, heightMeasureSpec: number): void;
layout(left: number, top: number, right: number, bottom: number): void;
getMeasuredWidth(): number;
getMeasuredHeight(): number;
}Layout containers that manage the positioning and sizing of child elements using different layout algorithms.
/**
* Base class for all layout containers
*/
class LayoutBase extends View {
addChild(view: View): void;
insertChild(child: View, atIndex: number): void;
removeChild(child: View): void;
removeChildren(): void;
getChildAt(index: number): View;
getChildIndex(child: View): number;
getChildrenCount(): number;
// Layout properties
padding: string | number;
paddingTop: number;
paddingRight: number;
paddingBottom: number;
paddingLeft: number;
}
/**
* Stack layout - arranges children in a single row or column
*/
class StackLayout extends LayoutBase {
orientation: "vertical" | "horizontal";
}
/**
* Grid layout - arranges children in rows and columns
*/
class GridLayout extends LayoutBase {
columns: string; // e.g., "*, 100, auto"
rows: string; // e.g., "*, 50, auto"
static setColumn(view: View, value: number): void;
static getColumn(view: View): number;
static setRow(view: View, value: number): void;
static getRow(view: View): number;
static setColumnSpan(view: View, value: number): void;
static setRowSpan(view: View, value: number): void;
}
/**
* Absolute layout - positions children using absolute coordinates
*/
class AbsoluteLayout extends LayoutBase {
static setLeft(view: View, value: number): void;
static setTop(view: View, value: number): void;
static getLeft(view: View): number;
static getTop(view: View): number;
}
/**
* Dock layout - docks children to sides and fills remaining space
*/
class DockLayout extends LayoutBase {
stretchLastChild: boolean;
static setDock(view: View, value: "left" | "top" | "right" | "bottom"): void;
static getDock(view: View): string;
}
/**
* Wrap layout - arranges children in rows, wrapping to new row when needed
*/
class WrapLayout extends LayoutBase {
orientation: "horizontal" | "vertical";
itemWidth: number;
itemHeight: number;
}
/**
* Flexbox layout - CSS flexbox-style layout
*/
class FlexboxLayout extends LayoutBase {
flexDirection: "row" | "row-reverse" | "column" | "column-reverse";
flexWrap: "nowrap" | "wrap" | "wrap-reverse";
justifyContent: "flex-start" | "flex-end" | "center" | "space-between" | "space-around";
alignItems: "flex-start" | "flex-end" | "center" | "baseline" | "stretch";
alignContent: "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "stretch";
}Layout Usage Examples:
import { StackLayout, GridLayout, Button, Label } from "tns-core-modules";
// Stack layout example
const stack = new StackLayout();
stack.orientation = "vertical";
const header = new Label();
header.text = "Welcome";
stack.addChild(header);
const button = new Button();
button.text = "Click Me";
stack.addChild(button);
// Grid layout example
const grid = new GridLayout();
grid.columns = "*, 100"; // flexible, fixed 100
grid.rows = "auto, *"; // auto-size, flexible
const title = new Label();
title.text = "Title";
GridLayout.setColumn(title, 0);
GridLayout.setRow(title, 0);
GridLayout.setColumnSpan(title, 2);
grid.addChild(title);Fundamental UI controls for user interaction and content display.
/**
* Clickable button control
*/
class Button extends View {
text: string;
textWrap: boolean;
// Events
static tapEvent: "tap";
}
/**
* Text display control
*/
class Label extends View {
text: string;
textWrap: boolean;
textAlignment: "left" | "center" | "right";
// Rich text support
formattedText: FormattedString;
}
/**
* Single-line text input control
*/
class TextField extends EditableTextBase {
text: string;
hint: string;
secure: boolean;
keyboardType: "datetime" | "phone" | "number" | "url" | "email";
returnKeyType: "done" | "next" | "go" | "search" | "send";
autocapitalizationType: "none" | "words" | "sentences" | "allCharacters";
autocorrect: boolean;
// Events
static textChangeEvent: "textChange";
static returnPressEvent: "returnPress";
dismissSoftInput(): void;
}
/**
* Multi-line text input control
*/
class TextView extends EditableTextBase {
text: string;
hint: string;
editable: boolean;
maxLines: number;
}
/**
* Base class for editable text controls
*/
class EditableTextBase extends View {
keyboardType: string;
returnKeyType: string;
autocapitalizationType: string;
autocorrect: boolean;
updateTextTrigger: "focusLost" | "textChanged";
dismissSoftInput(): void;
}
/**
* Image display control
*/
class Image extends View {
src: string | ImageSource;
imageSource: ImageSource;
isLoading: boolean;
stretch: "none" | "aspectFill" | "aspectFit" | "fill";
loadMode: "sync" | "async";
// Events
static isLoadingChangeEvent: "isLoadingChange";
}
/**
* Toggle switch control
*/
class Switch extends View {
checked: boolean;
// Events
static checkedChangeEvent: "checkedChange";
}
/**
* Numeric slider control
*/
class Slider extends View {
value: number;
minValue: number;
maxValue: number;
// Events
static valueChangeEvent: "valueChange";
}
/**
* Progress indicator control
*/
class Progress extends View {
value: number;
maxValue: number;
}
/**
* Loading indicator control
*/
class ActivityIndicator extends View {
busy: boolean;
}Sophisticated controls for complex user interactions and data display.
/**
* List view for displaying collections of data
*/
class ListView extends View {
items: any[] | ObservableArray<any>;
itemTemplate: string | Template;
itemTemplateSelector: Function;
separatorColor: string;
rowHeight: number;
// Events
static itemLoadingEvent: "itemLoading";
static itemTapEvent: "itemTap";
static loadMoreItemsEvent: "loadMoreItems";
refresh(): void;
scrollToIndex(index: number): void;
isItemAtIndexVisible(index: number): boolean;
}
/**
* Segmented control for selecting from options
*/
class SegmentedBar extends View {
items: SegmentedBarItem[];
selectedIndex: number;
selectedBackgroundColor: string;
// Events
static selectedIndexChangeEvent: "selectedIndexChange";
}
class SegmentedBarItem {
title: string;
}
/**
* Date picker control
*/
class DatePicker extends View {
year: number;
month: number;
day: number;
date: Date;
minDate: Date;
maxDate: Date;
// Events
static dateChangeEvent: "dateChange";
}
/**
* Time picker control
*/
class TimePicker extends View {
hour: number;
minute: number;
time: Date;
minHour: number;
maxHour: number;
minuteInterval: number;
// Events
static timeChangeEvent: "timeChange";
}
/**
* List picker for selecting from options
*/
class ListPicker extends View {
items: any[];
selectedIndex: number;
selectedValue: any;
// Events
static selectedIndexChangeEvent: "selectedIndexChange";
}
/**
* Web view for displaying web content
*/
class WebView extends View {
url: string;
src: string;
canGoBack: boolean;
canGoForward: boolean;
loadUrl(url: string): void;
goBack(): void;
goForward(): void;
reload(): void;
// Events
static loadStartedEvent: "loadStarted";
static loadFinishedEvent: "loadFinished";
}Controls for organizing content and managing navigation within applications.
/**
* Application page container
*/
class Page extends View {
content: View;
actionBar: ActionBar;
navigationContext: any;
frame: Frame;
// Events
static loadedEvent: "loaded";
static navigatedToEvent: "navigatedTo";
static navigatedFromEvent: "navigatedFrom";
// Modal methods
showModal(moduleName: string, context?: any, closeCallback?: Function, fullscreen?: boolean): void;
closeModal(...args: any[]): void;
}
/**
* Navigation frame container
*/
class Frame extends View {
currentPage: Page;
currentEntry: NavigationEntry;
backStack: BackstackEntry[];
animated: boolean;
navigate(entry: string | NavigationEntry): void;
goBack(to?: BackstackEntry): void;
canGoBack(): boolean;
// Events
static navigatingToEvent: "navigatingTo";
static navigatedToEvent: "navigatedTo";
}
interface NavigationEntry {
moduleName?: string;
context?: any;
animated?: boolean;
transition?: NavigationTransition;
backstackVisible?: boolean;
clearHistory?: boolean;
}
/**
* Action bar for page headers
*/
class ActionBar extends View {
title: string;
navigationButton: NavigationButton;
actionItems: ActionItems;
flat: boolean;
}
class ActionItem extends ViewBase {
text: string;
icon: string;
position: "left" | "right" | "popup";
// Events
static tapEvent: "tap";
}
/**
* Scrollable content container
*/
class ScrollView extends ContentView {
orientation: "horizontal" | "vertical";
scrollBarIndicatorVisible: boolean;
isScrollEnabled: boolean;
scrollToVerticalOffset(value: number, animated: boolean): void;
scrollToHorizontalOffset(value: number, animated: boolean): void;
// Events
static scrollEvent: "scroll";
}
/**
* Content container view
*/
class ContentView extends View {
content: View;
layoutView: View;
}Advanced Controls Usage Examples:
import { ListView, Page, ObservableArray } from "tns-core-modules";
// ListView with data binding
const listView = new ListView();
const items = new ObservableArray([
{ name: "Item 1", description: "First item" },
{ name: "Item 2", description: "Second item" }
]);
listView.items = items;
listView.on(ListView.itemTapEvent, (args) => {
console.log("Tapped item:", args.index);
});
// Page with navigation
const page = new Page();
page.on(Page.navigatedToEvent, (args) => {
console.log("Navigated to page");
});
// Modal dialog
page.showModal("modal-page", { data: "context" }, (result) => {
console.log("Modal closed with result:", result);
});Install with Tessl CLI
npx tessl i tessl/npm-tns-core-modules