diff --git a/apps/automated/src/main.ts b/apps/automated/src/main.ts index 3a4e804c7..04498b7b1 100644 --- a/apps/automated/src/main.ts +++ b/apps/automated/src/main.ts @@ -220,3 +220,5 @@ if (typeof NSDate !== 'undefined') { console.log(`TIME TO LOAD APP: ${time} ms`); Application.run({ moduleName: 'app-root' }); + +// Application.android.on() diff --git a/packages/core/application/application-common.ts b/packages/core/application/application-common.ts index e9942fd58..cac2f2654 100644 --- a/packages/core/application/application-common.ts +++ b/packages/core/application/application-common.ts @@ -9,21 +9,23 @@ import { Builder } from '../ui/builder'; import * as bindableResources from '../ui/core/bindable/bindable-resources'; import type { View } from '../ui/core/view'; import type { Frame } from '../ui/frame'; -import { NavigationEntry } from '../ui/frame/frame-interfaces'; +import type { NavigationEntry } from '../ui/frame/frame-interfaces'; import type { StyleScope } from '../ui/styling/style-scope'; import type { AndroidApplication as IAndroidApplication, iOSApplication as IiOSApplication, } from './'; -import { +import type { ApplicationEventData, CssChangedEventData, DiscardedErrorEventData, + FontScaleChangedEventData, LaunchEventData, LoadAppCSSEventData, NativeScriptError, OrientationChangedEventData, SystemAppearanceChangedEventData, + UnhandledErrorEventData, } from './application-interfaces'; const ORIENTATION_CSS_CLASSES = [ @@ -41,14 +43,133 @@ const globalEvents = global.NativeScriptGlobals.events; // helper interface to correctly type Application event handlers interface ApplicationEvents { + off(eventNames: string, callback?: any, thisArg?: any): void; + notify(eventData: T): void; + hasListeners(eventName: string): boolean; + on( eventNames: string, callback: (args: ApplicationEventData) => void, thisArg?: any ): void; - off(eventNames: string, callback?: any, thisArg?: any): void; - notify(eventData: T): void; - hasListeners(eventName: string): boolean; + /** + * 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 class ApplicationCommon { @@ -70,10 +191,10 @@ export class ApplicationCommon { readonly cssChangedEvent = 'cssChanged'; // Application events go through the global events. - readonly on: ApplicationEvents['on'] = globalEvents.on.bind(globalEvents); - readonly off: ApplicationEvents['off'] = globalEvents.off.bind(globalEvents); - readonly notify: ApplicationEvents['notify'] = globalEvents.notify.bind(globalEvents); - readonly hasListeners: ApplicationEvents['hasListeners'] = + on: ApplicationEvents['on'] = globalEvents.on.bind(globalEvents); + off: ApplicationEvents['off'] = globalEvents.off.bind(globalEvents); + notify: ApplicationEvents['notify'] = globalEvents.notify.bind(globalEvents); + hasListeners: ApplicationEvents['hasListeners'] = globalEvents.hasListeners.bind(globalEvents); constructor() { diff --git a/packages/core/application/application-interfaces.ts b/packages/core/application/application-interfaces.ts index e9e404ab3..9ff08b329 100644 --- a/packages/core/application/application-interfaces.ts +++ b/packages/core/application/application-interfaces.ts @@ -1,4 +1,4 @@ -import type { ApplicationCommon } from '.'; +import type { ApplicationCommon } from './application-common'; import type { EventData, Observable } from '../data/observable'; import type { View } from '../ui/core/view'; diff --git a/packages/core/application/application.d.ts b/packages/core/application/application.d.ts index 4a1c39b95..53a86b592 100644 --- a/packages/core/application/application.d.ts +++ b/packages/core/application/application.d.ts @@ -3,130 +3,9 @@ export * from './application-common'; export * from './application-interfaces'; -export const Application: ApplicationCommon & ApplicationCommonEvents; +export const Application: ApplicationCommon; -export interface ApplicationCommonEvents { - /** - * 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 interface AndroidApplication extends ApplicationCommon { +export class AndroidApplication extends ApplicationCommon { readonly activityCreatedEvent; readonly activityDestroyedEvent; readonly activityStartedEvent; @@ -215,7 +94,7 @@ export interface AndroidApplication extends ApplicationCommon { ): void; } -export interface iOSApplication extends ApplicationCommon { +export class iOSApplication extends ApplicationCommon { get rootController(): UIViewController; get nativeApp(): UIApplication; get window(): UIWindow; diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts index 1743298d6..66d41582f 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -7,89 +7,8 @@ */ export type { NativeScriptConfig } from './config'; -export { iOSApplication, AndroidApplication } from './application'; -export type { - ApplicationEventData, - LaunchEventData, - OrientationChangedEventData, - UnhandledErrorEventData, - DiscardedErrorEventData, - CssChangedEventData, - LoadAppCSSEventData, - AndroidActivityEventData, - AndroidActivityBundleEventData, - AndroidActivityRequestPermissionsEventData, - AndroidActivityResultEventData, - AndroidActivityNewIntentEventData, - AndroidActivityBackPressedEventData, - SystemAppearanceChangedEventData, -} from './application'; - -// export * as Application from './application'; export * from './application'; - -// import { AndroidApplication, iOSApplication, systemAppearanceChanged, getMainEntry, getRootView, _resetRootView, getResources, setResources, setCssFileName, getCssFileName, loadAppCss, addCss, on, off, notify, hasListeners, run, orientation, getNativeApplication, hasLaunched, systemAppearance, setAutoSystemAppearanceChanged, setMaxRefreshRate } from './application'; -// export declare const Application: { -// launchEvent: string; -// displayedEvent: string; -// uncaughtErrorEvent: string; -// discardedErrorEvent: string; -// suspendEvent: string; -// resumeEvent: string; -// exitEvent: string; -// foregroundEvent: string; -// backgroundEvent: string; -// lowMemoryEvent: string; -// orientationChangedEvent: string; -// systemAppearanceChangedEvent: string; -// fontScaleChangedEvent: string; -// systemAppearanceChanged: typeof systemAppearanceChanged; -// setMaxRefreshRate: typeof setMaxRefreshRate; -// getMainEntry: typeof getMainEntry; -// getRootView: typeof getRootView; -// resetRootView: typeof _resetRootView; -// getResources: typeof getResources; -// setResources: typeof setResources; -// setCssFileName: typeof setCssFileName; -// getCssFileName: typeof getCssFileName; -// loadAppCss: typeof loadAppCss; -// addCss: typeof addCss; -// on: typeof on; -// off: typeof off; -// notify: typeof notify; -// hasListeners: typeof hasListeners; -// run: typeof run; -// orientation: typeof orientation; -// getNativeApplication: typeof getNativeApplication; -// hasLaunched: typeof hasLaunched; -// systemAppearance: typeof systemAppearance; -// setAutoSystemAppearanceChanged: typeof setAutoSystemAppearanceChanged; -// android: AndroidApplication; -// ios: iOSApplication; -// suspended: boolean; -// inBackground: boolean; -// }; - export * as ApplicationSettings from './application-settings'; -// import { setString, getString, clear, flush, getAllKeys, getBoolean, getNumber, hasKey, remove, setBoolean, setNumber } from './application-settings'; -// export declare const ApplicationSettings: { -// clear: typeof clear; -// flush: typeof flush; -// hasKey: typeof hasKey; -// remove: typeof remove; -// setString: typeof setString; -// getString: typeof getString; -// getAllKeys: typeof getAllKeys; -// getBoolean: typeof getBoolean; -// setBoolean: typeof setBoolean; -// getNumber: typeof getNumber; -// setNumber: typeof setNumber; -// }; -// export declare const AccessibilityEvents: { -// accessibilityBlurEvent: string; -// accessibilityFocusEvent: string; -// accessibilityFocusChangedEvent: string; -// }; import * as Accessibility from './accessibility'; export namespace AccessibilityEvents { export const accessibilityBlurEvent = Accessibility.accessibilityBlurEvent; @@ -145,14 +64,6 @@ export type { HttpContent, } from './http'; export * as Http from './http'; -// import { getFile, getImage, getJSON, getString as httpGetString } from './http'; -// export declare const Http: { -// getFile: typeof getFile; -// getImage: typeof getImage; -// getJSON: typeof getJSON; -// getString: typeof httpGetString; -// request: (options: import('./http').HttpRequestOptions) => Promise; -// }; export { ImageAsset } from './image-asset'; export type { ImageAssetOptions } from './image-asset'; export { ImageSource } from './image-source'; diff --git a/packages/core/index.ts b/packages/core/index.ts index 6a367cbd1..e4b25a6c9 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -2,100 +2,8 @@ /// // Init globals first (use import to ensure it's always at the top) import './globals'; - -export { iOSApplication, AndroidApplication } from './application'; -export type { - ApplicationEventData, - LaunchEventData, - OrientationChangedEventData, - UnhandledErrorEventData, - DiscardedErrorEventData, - CssChangedEventData, - LoadAppCSSEventData, - AndroidActivityEventData, - AndroidActivityBundleEventData, - AndroidActivityRequestPermissionsEventData, - AndroidActivityResultEventData, - AndroidActivityNewIntentEventData, - AndroidActivityBackPressedEventData, - SystemAppearanceChangedEventData, -} from './application'; - -// export * as Application from './application'; export * from './application'; - -// import { fontScaleChangedEvent, launchEvent, displayedEvent, uncaughtErrorEvent, discardedErrorEvent, suspendEvent, resumeEvent, exitEvent, lowMemoryEvent, orientationChangedEvent, systemAppearanceChanged, systemAppearanceChangedEvent, getMainEntry, getRootView, _resetRootView, getResources, setResources, setCssFileName, getCssFileName, loadAppCss, addCss, on, off, notify, hasListeners, run, orientation, getNativeApplication, hasLaunched, android as appAndroid, ios as iosApp, systemAppearance, setAutoSystemAppearanceChanged, ensureNativeApplication, setMaxRefreshRate } from './application'; -// import { inBackground, suspended, foregroundEvent, backgroundEvent } from './application/application-common'; - -// export const Application = { -// launchEvent, -// displayedEvent, -// uncaughtErrorEvent, -// discardedErrorEvent, -// suspendEvent, -// resumeEvent, -// exitEvent, -// foregroundEvent, -// backgroundEvent, -// lowMemoryEvent, -// orientationChangedEvent, -// systemAppearanceChangedEvent, -// systemAppearanceChanged, -// fontScaleChangedEvent, -// setMaxRefreshRate, - -// getMainEntry, -// getRootView, -// resetRootView: _resetRootView, -// getResources, -// setResources, -// setCssFileName, -// getCssFileName, -// loadAppCss, -// addCss, -// on, -// off, -// notify, -// hasListeners, -// run, -// orientation, -// getNativeApplication, -// hasLaunched, -// systemAppearance, -// setAutoSystemAppearanceChanged, -// get android() { -// ensureNativeApplication(); -// return appAndroid; -// }, -// get ios() { -// ensureNativeApplication(); -// return iosApp; -// }, -// get suspended() { -// return suspended; -// }, -// get inBackground() { -// return inBackground; -// }, -// }; - export * as ApplicationSettings from './application-settings'; -// // Export all methods from "application-settings" as ApplicationSettings -// import { setString, getString, clear, flush, getAllKeys, getBoolean, getNumber, hasKey, remove, setBoolean, setNumber } from './application-settings'; -// export const ApplicationSettings = { -// clear, -// flush, -// hasKey, -// remove, -// setString, -// getString, -// getAllKeys, -// getBoolean, -// setBoolean, -// getNumber, -// setNumber, -// }; - import * as Accessibility from './accessibility'; export namespace AccessibilityEvents { export const accessibilityBlurEvent = Accessibility.accessibilityBlurEvent; @@ -105,12 +13,6 @@ export namespace AccessibilityEvents { export const accessibilityPerformEscapeEvent = Accessibility.accessibilityPerformEscapeEvent; } -// export const AccessibilityEvents = { -// accessibilityBlurEvent, -// accessibilityFocusEvent, -// accessibilityFocusChangedEvent, -// accessibilityPerformEscapeEvent, -// }; export { AccessibilityLiveRegion, AccessibilityRole, @@ -120,20 +22,9 @@ export { } from './accessibility'; export { Color } from './color'; - export * as Connectivity from './connectivity'; -// import { connectionType, getConnectionType, startMonitoring, stopMonitoring } from './connectivity'; -// export const Connectivity = { -// connectionType, -// getConnectionType, -// startMonitoring, -// stopMonitoring, -// }; - export * from './core-types'; - export { CSSUtils } from './css/system-classes'; - export { ObservableArray, ChangeType } from './data/observable-array'; export type { ChangedData } from './data/observable-array'; export { @@ -164,20 +55,8 @@ export type { HttpContent, } from './http'; export * as Http from './http'; - -// Export all methods from "http" as Http -// import { getFile, getImage, getJSON, getString as httpGetString, request } from './http'; -// export const Http = { -// getFile, -// getImage, -// getJSON, -// getString: httpGetString, -// request, -// }; - export { ImageAsset } from './image-asset'; export type { ImageAssetOptions } from './image-asset'; - export { ImageSource } from './image-source'; export { ModuleNameResolver, _setResolver } from './module-name-resolver'; export type { ModuleListProvider, PlatformContext } from './module-name-resolver'; @@ -204,5 +83,4 @@ export { encoding } from './text'; export * from './trace'; export * from './ui'; export * as Utils from './utils'; - export { XmlParser, ParserEventType, ParserEvent } from './xml';