Catalog / NativeScript Cheatsheet
NativeScript Cheatsheet
A quick reference guide for NativeScript, covering core concepts, UI elements, data binding, and common tasks.
Core Concepts
Application Structure
NativeScript applications are structured with a Key files and directories include:
|
NativeScript uses XML, CSS, and JavaScript/TypeScript to define the UI and logic of the application.
|
Modules and Plugins
Modules: |
NativeScript utilizes modules for extending the core functionality. Modules are typically installed via npm. Example: |
Plugins: |
Plugins provide access to native device features and third-party libraries. They are also installed via npm and often require platform-specific configuration. Example: |
Application Lifecycle
NativeScript applications go through a lifecycle similar to other mobile apps. Key events include:
These events can be handled in the Example:
|
UI Elements
Layouts
|
Arranges children in a single line, either horizontally or vertically. |
|
Arranges children in a grid using rows and columns. |
|
Arranges children using flexbox properties, offering flexible and responsive layouts. |
|
Positions children using absolute coordinates. |
|
Docks children to the edges of the layout. |
Basic UI Components
|
Displays text. Supports basic formatting and styling. |
|
A clickable button. Handles tap events. |
|
Allows single-line text input. |
|
Allows multi-line text input. |
|
Displays an image from a local file or URL. |
|
Displays a scrollable list of items. |
Styling
UI elements are styled using CSS. NativeScript supports a subset of CSS properties, including:
CSS can be applied inline, in a separate CSS file, or using platform-specific CSS files (e.g., |
Data Binding
Basic Data Binding
NativeScript supports data binding, allowing UI elements to be dynamically updated based on data changes. Data binding is typically used with MVVM (Model-View-ViewModel) architecture. Data binding is defined in the XML using the Example:
In the code-behind (e.g., TypeScript file), the
|
Two-Way Data Binding
Two-way data binding allows changes in the UI to update the underlying data, and vice versa. This is typically used with input elements like Two-way data binding is defined using the Example:
Changes made in the |
Event Binding
Event binding allows UI events (e.g., button tap) to trigger methods in the ViewModel. Event binding is defined using the Example:
In the ViewModel:
|
Common Tasks
Navigation
Using |
Navigation in NativeScript is typically handled using the
|
Passing Data |
Data can be passed during navigation using the
In the destination page, access the data using |
HTTP Requests
Making HTTP requests is done using the Example:
Common methods include |
Platform-Specific Code
NativeScript allows writing platform-specific code using the Example:
This allows you to use native APIs and features that are specific to each platform. |