@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
287 lines (286 loc) • 13.2 kB
TypeScript
import type { View } from '../ui/core/view';
import type { NavigationEntry } from '../ui/frame/frame-interfaces';
import { ApplicationCommon } from './application-common';
import type { iOSApplication as IiOSApplication } from './application';
import { IOSNativeWindow } from '../native-window/native-window.ios';
import { NativeWindow } from '../native-window/native-window-common';
import type { WindowOpenOptions } from '../native-window/native-window-interfaces';
import { CommonA11YServiceEnabledObservable } from '../accessibility/accessibility-common';
import { CoreTypes } from '../core-types';
declare class NotificationObserver extends NSObject {
private _onReceiveCallback;
static initWithCallback(onReceiveCallback: (notification: NSNotification) => void): NotificationObserver;
onReceive(notification: NSNotification): void;
static ObjCExposedMethods: {
onReceive: {
returns: interop.Type<void>;
params: (typeof NSNotification)[];
};
};
}
declare class CADisplayLinkTarget extends NSObject {
private _owner;
static initWithOwner(owner: WeakRef<iOSApplication>): CADisplayLinkTarget;
onDisplayed(link: CADisplayLink): void;
static ObjCExposedMethods: {
onDisplayed: {
returns: interop.Type<void>;
params: (typeof CADisplayLink)[];
};
};
}
export declare class iOSApplication extends ApplicationCommon implements IiOSApplication {
private _delegate;
private _delegateHandlers;
private _rootView;
/** Set when `shouldDelayLaunchEvent` defers the primary window's content until the app first becomes active. */
private _pendingWindowContentResolve;
private _sceneDelegate;
/**
* User-provided callback to intercept scene configuration.
* Called for every new scene session. Return a UISceneConfiguration to handle
* the scene yourself, or return null/undefined to let NativeScript handle it
* (only for UIWindowSceneSessionRoleApplication scenes).
* @internal
*/
_onSceneConfiguration: ((application: UIApplication, connectingSceneSession: UISceneSession, options: UISceneConnectionOptions) => UISceneConfiguration | null | undefined) | null;
private _mirroredWindow;
private _foregroundWindows;
private _activeWindows;
private _notificationObservers;
private _softRebootAppDelegate;
private _softRebootSceneDelegates;
displayedOnce: boolean;
displayedLinkTarget: CADisplayLinkTarget;
displayedLink: CADisplayLink;
/**
* Delays the 'launch' event, and with it the creation of the first window's content, until the
* app first becomes active, instead of raising it while the app finishes launching.
*
* Applies to non-scene apps only. It has no effect in a scene-based app, where each window's
* content is resolved as its scene connects.
*
* @deprecated Use the 'ready' event for application initialization, and
* Application.setWindowContentResolver() to provide window UI.
*/
shouldDelayLaunchEvent: boolean;
/**
* @internal - should not be constructed by the user.
*/
constructor();
getRootView(): View;
resetRootView(entry?: NavigationEntry | string): void;
run(entry?: string | NavigationEntry): void;
private runAsMainApp;
private runAsEmbeddedApp;
/**
* After an in-process soft reboot (NativeScriptRuntime.reloadApplication /
* restartWithConfig), the Objective-C delegate classes created by the
* previous JS isolate still exist and UIKit keeps dispatching to their
* now-inert instances: their method callbacks bail out because the isolate
* that implemented them is gone. Notification-center observers are
* re-registered by the new isolate, but delegate-based dispatch (custom
* UIApplicationDelegate methods like push-token/openURL callbacks, and the
* UIScene delegates used by scene-lifecycle apps) stays pinned to the old
* bundle. Recreate those delegates from this bundle's classes and re-point
* UIKit at them.
*/
private _reattachNativeDelegatesAfterSoftReboot;
private getViewController;
private setViewControllerView;
setMaxRefreshRate(options?: {
min?: number;
max?: number;
preferred?: number;
}): void;
get rootController(): UIViewController;
get nativeApp(): UIApplication;
get window(): UIWindow;
get delegate(): UIApplicationDelegate & {
prototype: UIApplicationDelegate;
};
set delegate(value: UIApplicationDelegate | unknown);
/**
* NativeScript's default implementation of the `UIApplicationDelegate`
* `applicationConfigurationForConnectingSceneSessionOptions` method.
*
* It is installed automatically on the application delegate class unless that class
* already implements the method. A delegate that does implement it can handle the
* scenes it cares about and forward the rest here:
*
* ```ts
* applicationConfigurationForConnectingSceneSessionOptions(app, session, options) {
* if (session.role === myCustomRole) {
* return myConfig;
* }
* return Application.ios.defaultSceneConfiguration(app, session, options);
* }
* ```
*
* `onSceneConfiguration` is consulted first. Scenes with the
* `UIWindowSceneSessionRoleApplication` role then get a configuration backed by
* NativeScript's SceneDelegate; every other role gets a bare configuration that
* NativeScript does not manage.
*/
defaultSceneConfiguration(application: UIApplication, connectingSceneSession: UISceneSession, options: UISceneConnectionOptions): UISceneConfiguration;
/**
* NativeScript's default implementation of the `UIApplicationDelegate`
* `applicationDidDiscardSceneSessions` method, which retires the `NativeWindow`s
* belonging to the discarded sessions.
*
* It is installed automatically on the application delegate class unless that class
* already implements the method, in which case forward to it from there so window
* bookkeeping stays correct.
*/
defaultDiscardSceneSessions(application: UIApplication, sceneSessions: NSSet<UISceneSession>): void;
addDelegateHandler<T extends keyof UIApplicationDelegate>(methodName: T, handler: (typeof UIApplicationDelegate.prototype)[T]): void;
getNativeApplication(): UIApplication;
addNotificationObserver(notificationName: string, onReceiveCallback: (notification: NSNotification) => void): NotificationObserver;
removeNotificationObserver(observer: any, notificationName: string): void;
protected getSystemAppearance(): 'light' | 'dark';
private getSystemAppearanceValue;
protected getLayoutDirection(): CoreTypes.LayoutDirectionType;
private getLayoutDirectionValue;
protected getOrientation(): "portrait" | "landscape" | "unknown";
private getOrientationValue;
private notifyAppStarted;
_onLivesync(context?: ModuleContext): void;
private setWindowContent;
/**
* Attaches content to the raw `UIWindow`. Every launch path registers a primary
* NativeWindow, so this only runs when no window is left to own the content.
*/
private setWindowContentFallback;
private didFinishLaunchingWithOptions;
private didBecomeActive;
private didEnterBackground;
private willTerminate;
private didReceiveMemoryWarning;
private didChangeStatusBarOrientation;
/**
* Keeps the app-level root view state (`getRootView()`, the global root view and the
* `initRootView` event) following whatever the primary window shows.
*/
private mirrorPrimaryWindow;
private onPrimaryWindowContentLoaded;
private adoptRootView;
/**
* @internal - hands the discarded sessions' ids to the window registry, which decides
* which of them name a window that is actually finished with.
*/
_onSceneSessionsDiscarded(sessions: NSSet<UISceneSession>): void;
/**
* @internal - Get a NativeWindow by its scene.
*/
_getWindowForScene(scene: UIWindowScene): IOSNativeWindow | undefined;
/**
* @internal - Feeds a window's foreground state into the application-level
* 'foreground'/'background' events, which describe the app as a whole: they are raised
* when the first application-role window enters the foreground and when the last one
* leaves it. Windows in any other role never speak for the app.
*/
_setWindowInForeground(nativeWindow: NativeWindow | undefined, inForeground: boolean, scene?: UIScene): void;
/**
* @internal - Feeds a window's active state into the application-level 'resume'/'suspend'
* events, raised when the first application-role window becomes active and when the last
* active one resigns.
*/
_setWindowActive(nativeWindow: NativeWindow | undefined, active: boolean, scene?: UIScene): void;
/**
* @returns whether the set flipped between empty and non-empty, which is the only point
* at which app-level state changes.
*/
private _trackWindowState;
protected _onWindowRegistered(nativeWindow: NativeWindow): void;
protected _onPrimaryWindowPromoted(nativeWindow: NativeWindow): void;
/**
* Register a callback to intercept scene configuration.
*
* Called for every new scene session. Return a `UISceneConfiguration` to handle
* the scene yourself (e.g. CarPlay, external display), or return `null`/`undefined`
* to let NativeScript handle it with the default SceneDelegate.
*
* NativeScript only auto-manages `UIWindowSceneSessionRoleApplication` scenes.
* All other scene roles are ignored unless you provide a configuration here.
*
* @example
* ```ts
* Application.ios.onSceneConfiguration = (app, session, options) => {
* if (session.role === CPTemplateApplicationSceneSessionRoleApplication) {
* const config = UISceneConfiguration.configurationWithNameSessionRole('CarPlay', session.role);
* config.delegateClass = MyCarPlaySceneDelegate;
* return config;
* }
* // Return null to let NativeScript handle the default window scene
* return null;
* };
* ```
*/
set onSceneConfiguration(handler: ((application: UIApplication, connectingSceneSession: UISceneSession, options: UISceneConnectionOptions) => UISceneConfiguration | null | undefined) | null);
get onSceneConfiguration(): ((application: UIApplication, connectingSceneSession: UISceneSession, options: UISceneConnectionOptions) => UISceneConfiguration | null | undefined) | null;
get sceneDelegate(): UIWindowSceneDelegate;
set sceneDelegate(value: UIWindowSceneDelegate);
/**
* Multi-window support
*/
/**
* Opens a new window (scene).
*
* @param options Options for the new window. `options.data` is serialized into the
* activating scene's `NSUserActivity.userInfo`.
*/
openWindow(options?: WindowOpenOptions): void;
/**
* Closes a secondary window/scene.
* Accepts a NativeWindow, View, UIWindow, UIWindowScene, or string id.
*/
closeWindow(target?: NativeWindow | View | UIWindow | UIWindowScene | string): void;
/**
* @deprecated Use `getWindows()` instead.
*/
getAllWindows(): UIWindow[];
/**
* @deprecated Use `getWindows()` instead.
*/
getAllScenes(): UIScene[];
/**
* @deprecated Use `getWindows()` instead.
*/
getWindowScenes(): UIWindowScene[];
/**
* @deprecated Use `primaryWindow?.ios?.uiWindow` instead.
*/
getPrimaryWindow(): UIWindow;
/**
* @deprecated Use `primaryWindow?.ios?.scene` instead.
*/
getPrimaryScene(): UIWindowScene | null;
supportsScenes(): boolean;
supportsMultipleScenes(): boolean;
isUsingSceneLifecycle(): boolean;
configureForScenes(): void;
private _resolveScene;
private createSceneWithLegacyAPI;
/**
* Creates a simple view controller with a NativeScript view for a scene window.
* @param window The UIWindow to set content for
* @param view The NativeScript View to set as root content
*/
setWindowRootView(window: UIWindow, view: View): void;
get ios(): this;
}
export * from './application-common';
export * from './application-interfaces';
export declare const Application: iOSApplication;
export declare const AndroidApplication: any;
export declare function getCurrentFontScale(): number;
export declare function updateAccessibilityProperties(view: View): void;
export declare const sendAccessibilityEvent: () => void;
export declare function isAccessibilityServiceEnabled(): boolean;
export declare function getAndroidAccessibilityManager(): null;
export declare class AccessibilityServiceEnabledObservable extends CommonA11YServiceEnabledObservable {
constructor();
}
export declare function ensureA11yClasses(): void;
export declare function updateCurrentHelperClasses(applyRootCssClass: (cssClasses: string[], newCssClass: string) => void): void;
export declare function initAccessibilityCssHelper(): void;