@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
187 lines (186 loc) • 8.19 kB
TypeScript
import type { CoreTypes } from '../core-types';
import type { EventData } from '../data/observable';
import type { View } from '../ui/core/view';
import type { NavigationEntry } from '../ui/frame/frame-interfaces';
import type { NativeWindow, WindowBase } from '.';
/**
* Events emitted by a NativeWindow instance.
*/
export declare const NativeWindowEvents: {
/** Fired when the window becomes the active/focused window. */
readonly activate: "activate";
/** Fired when the window loses focus. */
readonly deactivate: "deactivate";
/** Fired when the window enters the background. */
readonly background: "background";
/** Fired when the window enters the foreground. */
readonly foreground: "foreground";
/**
* Fired when the window session ends for good. Fires at most once per window;
* every listener on the window is dropped right after it is dispatched.
*/
readonly close: "close";
/** Fired when a native surface is bound to the window, both on first connect and on every re-attach. */
readonly attached: "attached";
/**
* Fired when the native surface goes away while the window session stays alive
* (iOS scene disconnect, Android activity recreation). The window stays registered
* and keeps its listeners, so the same instance is reused when `attached` fires again.
*/
readonly detached: "detached";
/** Fired after the window content has been displayed for the first time. */
readonly displayed: "displayed";
/** Fired when the root view content is set or changed. */
readonly contentLoaded: "contentLoaded";
/** Fired when the orientation of this window changes. */
readonly orientationChanged: "orientationChanged";
/** Fired when the system appearance of this window changes between light and dark. */
readonly systemAppearanceChanged: "systemAppearanceChanged";
/** Fired when the layout direction of this window changes between ltr and rtl. */
readonly layoutDirectionChanged: "layoutDirectionChanged";
/** Fired when the scene is about to connect (iOS only). */
readonly sceneWillConnect: "sceneWillConnect";
/** Fired when the scene becomes active (iOS only). */
readonly sceneDidActivate: "sceneDidActivate";
/** Fired when the scene is about to resign active state (iOS only). */
readonly sceneWillResignActive: "sceneWillResignActive";
/** Fired when the scene is about to enter the foreground (iOS only). */
readonly sceneWillEnterForeground: "sceneWillEnterForeground";
/** Fired when the scene has entered the background (iOS only). */
readonly sceneDidEnterBackground: "sceneDidEnterBackground";
/** Fired when the scene has disconnected (iOS only). */
readonly sceneDidDisconnect: "sceneDidDisconnect";
/** Fired when the scene is asked to open one or more URLs (iOS only). */
readonly sceneOpenURLContexts: "sceneOpenURLContexts";
/** Fired when the scene is asked to continue a handoff/universal link activity (iOS only). */
readonly sceneContinueUserActivity: "sceneContinueUserActivity";
/** Fired when a home screen quick action is directed at the scene (iOS only). */
readonly scenePerformActionForShortcutItem: "scenePerformActionForShortcutItem";
/** Fired when the activity is created (Android only). */
readonly activityCreated: "activityCreated";
/** Fired when the activity is destroyed (Android only). */
readonly activityDestroyed: "activityDestroyed";
/** Fired when the activity is started (Android only). */
readonly activityStarted: "activityStarted";
/** Fired when the activity is paused (Android only). */
readonly activityPaused: "activityPaused";
/** Fired when the activity is resumed (Android only). */
readonly activityResumed: "activityResumed";
/** Fired when the activity is stopped (Android only). */
readonly activityStopped: "activityStopped";
/** Fired when the activity state is being saved (Android only). */
readonly saveActivityState: "saveActivityState";
/** Fired when the activity receives a result (Android only). */
readonly activityResult: "activityResult";
/** Fired when the back button is pressed (Android only). */
readonly activityBackPressed: "activityBackPressed";
/** Fired when the activity receives a new intent (Android only). */
readonly activityNewIntent: "activityNewIntent";
/** Fired when permission results are received (Android only). */
readonly activityRequestPermissions: "activityRequestPermissions";
};
export type NativeWindowEventName = (typeof NativeWindowEvents)[keyof typeof NativeWindowEvents];
/**
* Application-level events related to window management.
*/
export declare const WindowEvents: {
/** Fired on Application when a new NativeWindow is created. */
readonly windowOpen: "windowOpen";
/** Fired on Application when a NativeWindow is closed/destroyed. */
readonly windowClose: "windowClose";
/** Fired on Application when another window takes over the primary role. */
readonly primaryWindowChanged: "primaryWindowChanged";
};
/**
* Base event data for window surface events.
*/
export interface WindowBaseEventData extends EventData {
/** The window that emitted the event. */
window: WindowBase;
}
/**
* Base event data for NativeWindow events.
*/
export interface NativeWindowEventData extends WindowBaseEventData {
/** The NativeWindow that emitted the event. */
window: NativeWindow;
}
/**
* Event data for the `orientationChanged` event of a NativeWindow.
*/
export interface WindowOrientationChangedEventData extends NativeWindowEventData {
/** The orientation the window is now in. */
newValue: 'portrait' | 'landscape' | 'unknown';
}
/**
* Event data for the `systemAppearanceChanged` event of a NativeWindow.
*/
export interface WindowSystemAppearanceChangedEventData extends NativeWindowEventData {
/** The system appearance the window is now showing. */
newValue: 'light' | 'dark';
}
/**
* Event data for the `layoutDirectionChanged` event of a NativeWindow.
*/
export interface WindowLayoutDirectionChangedEventData extends NativeWindowEventData {
/** The layout direction the window is now using. */
newValue: CoreTypes.LayoutDirectionType;
}
/**
* Event data fired on Application when a window opens.
*/
export interface WindowOpenEventData extends EventData {
/** The NativeWindow that was opened. */
window: NativeWindow;
}
/**
* Event data fired on Application when a window closes.
*/
export interface WindowCloseEventData extends EventData {
/** The NativeWindow that was closed. */
window: NativeWindow;
}
/**
* Event data fired on Application when the primary window changes.
*/
export interface PrimaryWindowChangedEventData extends EventData {
/** The NativeWindow that is now primary. */
window: NativeWindow;
}
/**
* Options for opening a new window.
*/
export interface WindowOpenOptions {
/**
* Data to pass to the new window.
* On iOS: serialized into NSUserActivity.userInfo.
* On Android: added as intent extras.
*/
data?: Record<string, any>;
}
/**
* Supplies the UI for a window that needs content. Called once per window that needs it.
*
* Return a `View`, a `NavigationEntry` or a module name to set the window content,
* `null` to take ownership and set the content asynchronously later, or `undefined`
* to fall back to the application main entry.
*/
export type WindowContentResolver = (request: WindowContentRequest) => View | NavigationEntry | string | null | undefined;
/**
* Describes the window asking for content.
*/
export interface WindowContentRequest {
/** The window that needs content. */
window: NativeWindow;
/** Whether the window is the application's primary window. */
isPrimary: boolean;
/** NSUserActivity.userInfo on iOS, intent extras on Android. */
data?: Record<string, any>;
ios?: {
connectionOptions?: UISceneConnectionOptions;
};
android?: {
intent?: android.content.Intent;
savedInstanceState?: android.os.Bundle;
};
}