@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
224 lines (223 loc) • 9.45 kB
TypeScript
import type { View } from '../ui/core/view';
import type { NavigationEntry } from '../ui/frame/frame-interfaces';
import type { AndroidApplication as IAndroidApplication, iOSApplication as IiOSApplication } from './';
import type { ApplicationEventData, CssChangedEventData, DiscardedErrorEventData, FontScaleChangedEventData, LaunchEventData, OrientationChangedEventData, SystemAppearanceChangedEventData, UnhandledErrorEventData } from './application-interfaces';
interface ApplicationEvents {
off(eventNames: string, callback?: any, thisArg?: any): void;
notify<T = ApplicationEventData>(eventData: T): void;
hasListeners(eventName: string): boolean;
on(eventNames: string, callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when application css is changed.
*/
on(event: 'cssChanged', callback: (args: CssChangedEventData) => void, thisArg?: any): void;
/**
* Event raised then livesync operation is performed.
*/
on(event: 'livesync', callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when application css is changed.
*/
on(event: 'cssChanged', callback: (args: CssChangedEventData) => void, thisArg?: any): void;
/**
* This event is raised on application launchEvent.
*/
on(event: 'launch', callback: (args: LaunchEventData) => void, thisArg?: any): void;
/**
* This event is raised after the application has performed most of its startup actions.
* Its intent is to be suitable for measuring app startup times.
* @experimental
*/
on(event: 'displayed', callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when the Application is suspended.
*/
on(event: 'suspend', callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when the Application is resumed after it has been suspended.
*/
on(event: 'resume', callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when the Application is about to exit.
*/
on(event: 'exit', callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when there is low memory on the target device.
*/
on(event: 'lowMemory', callback: (args: ApplicationEventData) => void, thisArg?: any): void;
/**
* This event is raised when an uncaught error occurs while the application is running.
*/
on(event: 'uncaughtError', callback: (args: UnhandledErrorEventData) => void, thisArg?: any): void;
/**
* This event is raised when an discarded error occurs while the application is running.
*/
on(event: 'discardedError', callback: (args: DiscardedErrorEventData) => void, thisArg?: any): void;
/**
* This event is raised when the orientation of the application changes.
*/
on(event: 'orientationChanged', callback: (args: OrientationChangedEventData) => void, thisArg?: any): void;
/**
* This event is raised when the operating system appearance changes
* between light and dark theme (for Android);
* between light and dark mode (for iOS) and vice versa.
*/
on(event: 'systemAppearanceChanged', callback: (args: SystemAppearanceChangedEventData) => void, thisArg?: any): void;
on(event: 'fontScaleChanged', callback: (args: FontScaleChangedEventData) => void, thisArg?: any): void;
}
export declare class ApplicationCommon {
readonly launchEvent = "launch";
readonly suspendEvent = "suspend";
readonly displayedEvent = "displayed";
readonly backgroundEvent = "background";
readonly foregroundEvent = "foreground";
readonly resumeEvent = "resume";
readonly exitEvent = "exit";
readonly lowMemoryEvent = "lowMemory";
readonly uncaughtErrorEvent = "uncaughtError";
readonly discardedErrorEvent = "discardedError";
readonly orientationChangedEvent = "orientationChanged";
readonly systemAppearanceChangedEvent = "systemAppearanceChanged";
readonly fontScaleChangedEvent = "fontScaleChanged";
readonly livesyncEvent = "livesync";
readonly loadAppCssEvent = "loadAppCss";
readonly cssChangedEvent = "cssChanged";
readonly initRootViewEvent = "initRootView";
/**
* @deprecated Use `Application.android.on()` instead.
*/
static on: ApplicationEvents['on'];
/**
* @deprecated Use `Application.android.once()` instead.
*/
static once: ApplicationEvents['on'];
/**
* @deprecated Use `Application.android.off()` instead.
*/
static off: ApplicationEvents['off'];
/**
* @deprecated Use `Application.android.notify()` instead.
*/
static notify: ApplicationEvents['notify'];
/**
* @deprecated Use `Application.android.hasListeners()` instead.
*/
static hasListeners: ApplicationEvents['hasListeners'];
on: ApplicationEvents['on'];
once: ApplicationEvents['on'];
off: ApplicationEvents['off'];
notify: ApplicationEvents['notify'];
hasListeners: ApplicationEvents['hasListeners'];
/**
* @internal - should not be constructed by the user.
*/
constructor();
/**
* @internal
*/
livesync(rootView: View, context?: ModuleContext): void;
/**
* Applies the the `newCssClass` to the `rootView` and removes all other css classes from `cssClasses`
* previously applied to the `rootView`.
* @param rootView
* @param cssClasses
* @param newCssClass
* @param skipCssUpdate
*/
applyCssClass(rootView: View, cssClasses: string[], newCssClass: string, skipCssUpdate?: boolean): void;
private addCssClass;
private removeCssClass;
private increaseStyleScopeApplicationCssSelectorVersion;
private setRootViewCSSClasses;
/**
* iOS Only
* Dynamically change the preferred frame rate
* For devices (iOS 15+) which support min/max/preferred frame rate you can specify ranges
* For devices (iOS < 15), you can specify the max frame rate
* see: https://developer.apple.com/documentation/quartzcore/optimizing_promotion_refresh_rates_for_iphone_13_pro_and_ipad_pro
* To use, ensure your Info.plist has:
* ```xml
* <key>CADisableMinimumFrameDurationOnPhone</key>
* <true/>
* ```
* @param options { min?: number; max?: number; preferred?: number }
*/
setMaxRefreshRate(options?: {
min?: number;
max?: number;
preferred?: number;
}): void;
protected mainEntry: NavigationEntry;
/**
* @returns The main entry of the application
*/
getMainEntry(): NavigationEntry;
protected notifyLaunch(additionalLanchEventData?: any): View | null;
createRootView(view?: View, fireLaunchEvent?: boolean, additionalLanchEventData?: any): View;
getRootView(): View;
resetRootView(entry?: NavigationEntry | string): void;
initRootView(rootView: View): void;
/**
* Get application level static resources.
*/
getResources(): any;
/**
* Set application level static resources.
*/
setResources(res: any): void;
private cssFile;
/**
* Sets css file name for the application.
*/
setCssFileName(cssFileName: string): void;
/**
* Gets css file name for the application.
*/
getCssFileName(): string;
/**
* Loads immediately the app.css.
* By default the app.css file is loaded shortly after "loaded".
* For the Android snapshot the CSS can be parsed during the snapshot generation,
* as the CSS does not depend on runtime APIs, and loadAppCss will be called explicitly.
*/
loadAppCss(): void;
addCss(cssText: string, attributeScoped?: boolean): void;
run(entry?: string | NavigationEntry): void;
private _orientation;
protected getOrientation(): 'portrait' | 'landscape' | 'unknown';
protected setOrientation(value: 'portrait' | 'landscape' | 'unknown'): void;
orientation(): 'portrait' | 'landscape' | 'unknown';
orientationChanged(rootView: View, newOrientation: 'portrait' | 'landscape' | 'unknown'): void;
getNativeApplication(): any;
hasLaunched(): boolean;
private _systemAppearance;
protected getSystemAppearance(): 'dark' | 'light' | null;
protected setSystemAppearance(value: 'dark' | 'light'): void;
systemAppearance(): 'dark' | 'light' | null;
/**
* Boolean to enable/disable systemAppearanceChanged
*/
autoSystemAppearanceChanged: boolean;
/**
* enable/disable systemAppearanceChanged
*/
setAutoSystemAppearanceChanged(value: boolean): void;
/**
* Updates root view classes including those of modals
* @param rootView the root view
* @param newSystemAppearance the new appearance change
*/
systemAppearanceChanged(rootView: View, newSystemAppearance: 'dark' | 'light'): void;
private _inBackground;
get inBackground(): boolean;
setInBackground(value: boolean, additonalData?: any): void;
private _suspended;
get suspended(): boolean;
setSuspended(value: boolean, additonalData?: any): void;
started: boolean;
get android(): IAndroidApplication;
get ios(): IiOSApplication;
get AndroidApplication(): IAndroidApplication;
get iOSApplication(): IiOSApplication;
}
export {};