4.NativeScript Modules

邹桐
2023-12-01

Modules

To let you access the native deviceand platform capabilities of your target platform, NativeScript uses a modulardesign pattern. All device, platform or user interface functionalities residein separate modules. To access the functionality provided by a module, you needto require the module.

In your project, the files for eachmodule reside in a dedicated subdirectory in the tns_modules directory.Each default module comes along with a package.json filewhich declares how the module should be called within your call and which filecontains its respective code.

  • JSON
{ "name" : "button",
  "main" : "button.js" }

Core Modules

  • application: Provides the application abstraction with all related methods.
  • console: Lets you print messages to the device console.
  • local-settings: Lets you save and restore any information related to your application.
  • http: Lets you send web requests and receive the responses.
  • image-source: Provides theImageSource class which encapsulates the common abstraction behind a platform-specific object that is used as a source for images (typically a Bitmap).
  • timer: Lets you to create, start, stop and react to timers.
  • trace: Lets you trace and print specific information based on categories.
  • ui/image-cache: Provides theCache class which handles image download requests and caches the already downloaded images.

DeviceFunctionality Modules

  • camera: Lets you take pictures with the device camera.
  • location: Lets you use the geolocation sensors of the device.
  • platform: Provides information about the device, its operating system and software.
  • fps-meter: Lets you capture the frames-per-second metrics of your application.
  • file-system: Lets you work with the device file system. Provides high-level abstractions for file system entities such as files, folders, known folders, paths, separators, etc.
  • ui/gestures: Provides theGesturesObserver class which lets you observe and respond to user gestures.

Data Modules

  • data/observable: Provides theObservable class which represents an observable object or data in the MVVM paradigm.
  • data/observable-array: Provides theObservableArray class which detects and responds to changes in a collection of objects.
  • data/virtual-array: Provides theVirtualArray class which is an advanced array-like class that helps loading items on demand.

UserInterface Modules

  • ui/core/dependency-observable: Provides theDependencyObservable class which represents an extended Observable object that uses Property instances for value backing mechanism.
  • ui/frame: Provides theFrame class which represents the logical View unit that is responsible for navigation within an application.
  • ui/page: Provides thePage class which represents a logical unit for navigation inside a Frame. NativeScript apps consist of pages.
  • color: Lets you create colors which you can use when you style the UI.
  • text/formatted-string: Provides theFormattedString and Span classes which you can use to create rich text formatted strings.
  • xml: Provides theXmlParser class which is a SAX parser using the easysax implementation.
  • ui/styling: Provides theStyle class which is responsible for the visual appearance of elements.
  • ui/border: Provides theBorder class which lets you draw borders around other elements.

Layouts

  • ui/layouts/stack-layout: Provides theStackLayout class which lets you arrange the children of the layout in single line.
  • ui/layouts/grid-layout: Provides theGridLayout class which lets you arrange the children of the layout in a flexible grid area with columns and rows.
  • ui/layouts/absolute-layout: Provides theAbsoluteLayout class which lets you arrange the children of the layout at arbitrary positions or draw them in multiple layers.
  • ui/layouts/wrap-layout: Provides theWrapLayout class which lets you arrange the children of the layout at sequential positions from left to right and then wrap the lines of children from top to bottom.

Widgets

  • ui/activity-indicator: Provides theActivityIndicator class which represents a widget for showing that a service is currently busy.
  • ui/button: Provides theButton class which is a standard button widget.
  • ui/label: Provides theLabel class which is a standard label widget.
  • ui/text-field: Provides theTextField class which represents an editable single-line box.
  • ui/text-view: Provides theTextView class which represents an editable multi-line line box.
  • ui/list-view: Provides theListView class which represents a standard list view widget.
  • ui/image: Provides theImage class, which represents an image widget.
  • ui/progress: Provides theProgress class which represents a progress or loading indicator.
  • ui/scroll-view: Provides theScrollView class which represents a scrollable area that can show content which is larger than the visible area.
  • ui/search-bar: Provides theSearchBar class which represents a standard search bar component.
  • ui/slider: Provides theSlider class which represents a standard slider component.
  • ui/switch: Provides theSwitch class which represents a standard switch component.
  • ui/tab-view: Provides theTabView class which represents a standard content component with tabs.
  • ui/web-view: Provides theWebView class which represents a standard browser widget.
  • ui/dialogs: Lets you show various dialogs such as alerts, prompts, confirmations and others.

 

 类似资料: