UNPKG

@nativescript/core

Version:

A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.

154 lines (153 loc) 9.33 kB
import { CoreTypes } from '../core-types'; import type { View } from '../ui/core/view'; import type { NavigationEntry } from '../ui/frame/frame-interfaces'; import type { NativeWindowEventData, WindowLayoutDirectionChangedEventData, WindowOrientationChangedEventData, WindowSystemAppearanceChangedEventData } from './native-window-interfaces'; import type { AndroidActivityEventData, AndroidActivityBundleEventData, AndroidActivityResultEventData, AndroidActivityBackPressedEventData, AndroidActivityNewIntentEventData, AndroidActivityRequestPermissionsEventData, SceneEventData, SceneOpenURLContextsEventData, SceneContinueUserActivityEventData, ScenePerformActionForShortcutItemEventData } from '../application/application-interfaces'; import type { WindowRole } from './window-base'; import { WindowBase } from './window-base'; /** * Cross-platform NativeWindow base class. * * Wraps a platform window surface (iOS UIWindowScene+UIWindow, Android Activity) * and manages per-window root view lifecycle, CSS classes, and events. * * Platform-specific subclasses implement the abstract methods. */ export declare abstract class NativeWindow extends WindowBase { protected _rootView: View; protected _orientation: 'portrait' | 'landscape' | 'unknown'; protected _systemAppearance: 'dark' | 'light' | null; protected _layoutDirection: CoreTypes.LayoutDirectionType | null; constructor(id?: string, isPrimary?: boolean, role?: WindowRole); get rootView(): View; /** * Set the content of this window. * Accepts a View, a NavigationEntry, or a module name string. */ setContent(content: View | NavigationEntry | string): void; /** * @internal – take ownership of a root view the platform pipeline built and attached itself. * * The pipeline already ran `_setupAsRootView` and `Application.initRootView` on this view and * installed it on the native surface, so neither `_applyRootViewSettings` nor `_setNativeContent` * may run here — both would redo that work. */ _adoptRootView(view: View): void; /** * @internal – give up the root view without tearing it down. * * Called when another window takes the view over: the view is being moved, not * destroyed, so — unlike {@link _onDestroy} — nothing here unloads, resets or tears * down the view. It stays loaded and usable in its new window. */ _releaseRootView(): void; /** * Platform hook: unhook the released view from the native surface. The view itself * must survive — it is on its way into another window. */ protected _onReleaseRootView(rootView: View): void; /** * Becomes the owner of `view`, releasing it from whichever window held it before. */ private _takeRootView; /** * Platform-specific: apply the view to the native window surface. */ protected abstract _setNativeContent(view: View): void; /** * Get the current orientation of this window. * * Read from the native surface while the window is attached; a detached window * reports the last value it saw. * * A read that catches a change the platform has not reported yet goes through * {@link _setOrientation}, so the change is never swallowed by the reading. */ orientation(): 'portrait' | 'landscape' | 'unknown'; /** * Get the current system appearance of this window. * * Read from the native surface while the window is attached; a detached window * reports the last value it saw. * * A read that catches a change the platform has not reported yet goes through * {@link _setSystemAppearance}, so the change is never swallowed by the reading. */ systemAppearance(): 'light' | 'dark' | null; /** * Get the current layout direction of this window. * * Read from the native surface while the window is attached; a detached window * reports the last value it saw. * * A read that catches a change the platform has not reported yet goes through * {@link _setLayoutDirection}, so the change is never swallowed by the reading. */ layoutDirection(): CoreTypes.LayoutDirectionType | null; on(event: 'contentLoaded', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'activate', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'deactivate', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'background', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'foreground', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'close', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'attached', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'detached', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'displayed', callback: (data: NativeWindowEventData) => void, thisArg?: any): void; on(event: 'orientationChanged', callback: (data: WindowOrientationChangedEventData) => void, thisArg?: any): void; on(event: 'systemAppearanceChanged', callback: (data: WindowSystemAppearanceChangedEventData) => void, thisArg?: any): void; on(event: 'layoutDirectionChanged', callback: (data: WindowLayoutDirectionChangedEventData) => void, thisArg?: any): void; on(event: 'activityCreated', callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any): void; on(event: 'activityDestroyed', callback: (args: AndroidActivityEventData) => void, thisArg?: any): void; on(event: 'activityStarted', callback: (args: AndroidActivityEventData) => void, thisArg?: any): void; on(event: 'activityPaused', callback: (args: AndroidActivityEventData) => void, thisArg?: any): void; on(event: 'activityResumed', callback: (args: AndroidActivityEventData) => void, thisArg?: any): void; on(event: 'activityStopped', callback: (args: AndroidActivityEventData) => void, thisArg?: any): void; on(event: 'saveActivityState', callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any): void; on(event: 'activityResult', callback: (args: AndroidActivityResultEventData) => void, thisArg?: any): void; on(event: 'activityBackPressed', callback: (args: AndroidActivityBackPressedEventData) => void, thisArg?: any): void; on(event: 'activityNewIntent', callback: (args: AndroidActivityNewIntentEventData) => void, thisArg?: any): void; on(event: 'activityRequestPermissions', callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any): void; on(event: 'sceneWillConnect', callback: (args: SceneEventData) => void, thisArg?: any): void; on(event: 'sceneDidActivate', callback: (args: SceneEventData) => void, thisArg?: any): void; on(event: 'sceneWillResignActive', callback: (args: SceneEventData) => void, thisArg?: any): void; on(event: 'sceneWillEnterForeground', callback: (args: SceneEventData) => void, thisArg?: any): void; on(event: 'sceneDidEnterBackground', callback: (args: SceneEventData) => void, thisArg?: any): void; on(event: 'sceneDidDisconnect', callback: (args: SceneEventData) => void, thisArg?: any): void; on(event: 'sceneOpenURLContexts', callback: (args: SceneOpenURLContextsEventData) => void, thisArg?: any): void; on(event: 'sceneContinueUserActivity', callback: (args: SceneContinueUserActivityEventData) => void, thisArg?: any): void; on(event: 'scenePerformActionForShortcutItem', callback: (args: ScenePerformActionForShortcutItemEventData) => void, thisArg?: any): void; on(eventName: string, callback: (data: NativeWindowEventData) => void, thisArg?: any): void; protected abstract _getOrientation(): 'portrait' | 'landscape' | 'unknown'; protected abstract _getSystemAppearance(): 'light' | 'dark' | null; protected abstract _getLayoutDirection(): CoreTypes.LayoutDirectionType | null; /** * Applies platform, orientation, appearance, and layout direction CSS classes * to the root view. */ protected _applyRootViewSettings(rootView: View): void; private _setRootViewCSSClasses; /** * @internal – called by platform when orientation changes for this window. */ _setOrientation(value: 'portrait' | 'landscape' | 'unknown'): void; /** * @internal – called by platform when system appearance changes for this window. */ _setSystemAppearance(value: 'dark' | 'light'): void; /** * @internal – called by platform when layout direction changes for this window. */ _setLayoutDirection(value: CoreTypes.LayoutDirectionType): void; private _notifyValueChanged; private _applyCssClass; private _increaseStyleScopeVersion; /** * @internal – the native surface went away but the window session lives on. * * The window stays registered and keeps its listeners, so app code that subscribed * to it keeps working once a surface re-attaches. The root view keeps pointing back at * this window for the same reason — it is still this window's content. */ _detach(): void; protected _onDestroy(): void; }