chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -4,8 +4,10 @@ import "../globals";
// Types
import { AndroidApplication, iOSApplication } from ".";
import {
CssChangedEventData, DiscardedErrorEventData,
LoadAppCSSEventData, UnhandledErrorEventData
CssChangedEventData,
DiscardedErrorEventData,
LoadAppCSSEventData,
UnhandledErrorEventData,
} from "./application-interfaces";
import { EventData } from "../data/observable/observable-interfaces";
import { View } from "../ui/core/view";
@@ -13,13 +15,17 @@ import { View } from "../ui/core/view";
// Requires
import { Observable } from "../data/observable";
import {
trace as profilingTrace,
time,
uptime,
level as profilingLevel,
trace as profilingTrace,
time,
uptime,
level as profilingLevel,
} from "../profiling";
import * as bindableResources from "../ui/core/bindable/bindable-resources";
import { CLASS_PREFIX, pushToSystemCssClasses, removeSystemCssClass } from "../css/system-classes";
import {
CLASS_PREFIX,
pushToSystemCssClasses,
removeSystemCssClass,
} from "../css/system-classes";
import { DeviceOrientation, SystemAppearance } from "../ui/enums/enums";
export { Observable };
@@ -28,22 +34,22 @@ export * from "./application-interfaces";
const events = new Observable();
let launched = false;
function setLaunched() {
launched = true;
events.off("launch", setLaunched);
launched = true;
events.off("launch", setLaunched);
}
events.on("launch", setLaunched);
if (profilingLevel() > 0) {
events.on("displayed", () => {
const duration = uptime();
const end = time();
const start = end - duration;
profilingTrace(`Displayed in ${duration.toFixed(2)}ms`, start, end);
});
events.on("displayed", () => {
const duration = uptime();
const end = time();
const start = end - duration;
profilingTrace(`Displayed in ${duration.toFixed(2)}ms`, start, end);
});
}
export function hasLaunched(): boolean {
return launched;
return launched;
}
export const launchEvent = "launch";
@@ -58,24 +64,24 @@ export const orientationChangedEvent = "orientationChanged";
export const systemAppearanceChangedEvent = "systemAppearanceChanged";
const ORIENTATION_CSS_CLASSES = [
`${CLASS_PREFIX}${DeviceOrientation.portrait}`,
`${CLASS_PREFIX}${DeviceOrientation.landscape}`,
`${CLASS_PREFIX}${DeviceOrientation.unknown}`
`${CLASS_PREFIX}${DeviceOrientation.portrait}`,
`${CLASS_PREFIX}${DeviceOrientation.landscape}`,
`${CLASS_PREFIX}${DeviceOrientation.unknown}`,
];
const SYSTEM_APPEARANCE_CSS_CLASSES = [
`${CLASS_PREFIX}${SystemAppearance.light}`,
`${CLASS_PREFIX}${SystemAppearance.dark}`
`${CLASS_PREFIX}${SystemAppearance.light}`,
`${CLASS_PREFIX}${SystemAppearance.dark}`,
];
let cssFile: string = "./app.css";
export function getResources() {
return bindableResources.get();
return bindableResources.get();
}
export function setResources(res: any) {
bindableResources.set(res);
bindableResources.set(res);
}
export let android: AndroidApplication = undefined;
@@ -84,110 +90,164 @@ export let ios: iOSApplication = undefined;
export const on: typeof events.on = events.on.bind(events);
export const off: typeof events.off = events.off.bind(events);
export const notify: typeof events.notify = events.notify.bind(events);
export const hasListeners: typeof events.hasListeners = events.hasListeners.bind(events);
export const hasListeners: typeof events.hasListeners = events.hasListeners.bind(
events
);
let app: iOSApplication | AndroidApplication;
export function setApplication(instance: iOSApplication | AndroidApplication): void {
app = instance;
export function setApplication(
instance: iOSApplication | AndroidApplication
): void {
app = instance;
}
export function livesync(rootView: View, context?: ModuleContext) {
events.notify(<EventData>{ eventName: "livesync", object: app });
const liveSyncCore = global.__onLiveSyncCore;
let reapplyAppStyles = false;
events.notify(<EventData>{ eventName: "livesync", object: app });
const liveSyncCore = global.__onLiveSyncCore;
let reapplyAppStyles = false;
// ModuleContext is available only for Hot Module Replacement
if (context && context.path) {
const styleExtensions = ["css", "scss"];
const appStylesFullFileName = getCssFileName();
const appStylesFileName = appStylesFullFileName.substring(0, appStylesFullFileName.lastIndexOf(".") + 1);
reapplyAppStyles = styleExtensions.some(ext => context.path === appStylesFileName.concat(ext));
}
// ModuleContext is available only for Hot Module Replacement
if (context && context.path) {
const styleExtensions = ["css", "scss"];
const appStylesFullFileName = getCssFileName();
const appStylesFileName = appStylesFullFileName.substring(
0,
appStylesFullFileName.lastIndexOf(".") + 1
);
reapplyAppStyles = styleExtensions.some(
(ext) => context.path === appStylesFileName.concat(ext)
);
}
// Handle application styles
if (rootView && reapplyAppStyles) {
rootView._onCssStateChange();
} else if (liveSyncCore) {
liveSyncCore(context);
}
// Handle application styles
if (rootView && reapplyAppStyles) {
rootView._onCssStateChange();
} else if (liveSyncCore) {
liveSyncCore(context);
}
}
export function setCssFileName(cssFileName: string) {
cssFile = cssFileName;
events.notify(<CssChangedEventData>{ eventName: "cssChanged", object: app, cssFile: cssFileName });
cssFile = cssFileName;
events.notify(<CssChangedEventData>{
eventName: "cssChanged",
object: app,
cssFile: cssFileName,
});
}
export function getCssFileName(): string {
return cssFile;
return cssFile;
}
export function loadAppCss(): void {
try {
events.notify(<LoadAppCSSEventData>{ eventName: "loadAppCss", object: app, cssFile: getCssFileName() });
} catch (e) {
throw new Error(`The app CSS file ${getCssFileName()} couldn't be loaded!`);
}
try {
events.notify(<LoadAppCSSEventData>{
eventName: "loadAppCss",
object: app,
cssFile: getCssFileName(),
});
} catch (e) {
throw new Error(
`The app CSS file ${getCssFileName()} couldn't be loaded!`
);
}
}
function addCssClass(rootView: View, cssClass: string) {
pushToSystemCssClasses(cssClass);
rootView.cssClasses.add(cssClass);
pushToSystemCssClasses(cssClass);
rootView.cssClasses.add(cssClass);
}
function removeCssClass(rootView: View, cssClass: string) {
removeSystemCssClass(cssClass);
rootView.cssClasses.delete(cssClass);
removeSystemCssClass(cssClass);
rootView.cssClasses.delete(cssClass);
}
function increaseStyleScopeApplicationCssSelectorVersion(rootView: View) {
const styleScope = rootView._styleScope || ((<any>rootView).currentPage && (<any>rootView).currentPage._styleScope);
const styleScope =
rootView._styleScope ||
((<any>rootView).currentPage &&
(<any>rootView).currentPage._styleScope);
if (styleScope) {
styleScope._increaseApplicationCssSelectorVersion();
}
if (styleScope) {
styleScope._increaseApplicationCssSelectorVersion();
}
}
function applyCssClass(rootView: View, cssClasses: string[], newCssClass: string) {
if (!rootView.cssClasses.has(newCssClass)) {
cssClasses.forEach(cssClass => removeCssClass(rootView, cssClass));
addCssClass(rootView, newCssClass);
increaseStyleScopeApplicationCssSelectorVersion(rootView);
rootView._onCssStateChange();
}
function applyCssClass(
rootView: View,
cssClasses: string[],
newCssClass: string
) {
if (!rootView.cssClasses.has(newCssClass)) {
cssClasses.forEach((cssClass) => removeCssClass(rootView, cssClass));
addCssClass(rootView, newCssClass);
increaseStyleScopeApplicationCssSelectorVersion(rootView);
rootView._onCssStateChange();
}
}
export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void {
if (!rootView) {
return;
}
export function orientationChanged(
rootView: View,
newOrientation: "portrait" | "landscape" | "unknown"
): void {
if (!rootView) {
return;
}
const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`;
applyCssClass(rootView, ORIENTATION_CSS_CLASSES, newOrientationCssClass);
const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`;
applyCssClass(rootView, ORIENTATION_CSS_CLASSES, newOrientationCssClass);
const rootModalViews = <Array<View>>rootView._getRootModalViews();
rootModalViews.forEach(rootModalView => {
applyCssClass(rootModalView, ORIENTATION_CSS_CLASSES, newOrientationCssClass);
});
const rootModalViews = <Array<View>>rootView._getRootModalViews();
rootModalViews.forEach((rootModalView) => {
applyCssClass(
rootModalView,
ORIENTATION_CSS_CLASSES,
newOrientationCssClass
);
});
}
export function systemAppearanceChanged(rootView: View, newSystemAppearance: "dark" | "light"): void {
if (!rootView) {
return;
}
export function systemAppearanceChanged(
rootView: View,
newSystemAppearance: "dark" | "light"
): void {
if (!rootView) {
return;
}
const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`;
applyCssClass(rootView, SYSTEM_APPEARANCE_CSS_CLASSES, newSystemAppearanceCssClass);
const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`;
applyCssClass(
rootView,
SYSTEM_APPEARANCE_CSS_CLASSES,
newSystemAppearanceCssClass
);
const rootModalViews = <Array<View>>rootView._getRootModalViews();
rootModalViews.forEach(rootModalView => {
applyCssClass(rootModalView, SYSTEM_APPEARANCE_CSS_CLASSES, newSystemAppearanceCssClass);
});
const rootModalViews = <Array<View>>rootView._getRootModalViews();
rootModalViews.forEach((rootModalView) => {
applyCssClass(
rootModalView,
SYSTEM_APPEARANCE_CSS_CLASSES,
newSystemAppearanceCssClass
);
});
}
global.__onUncaughtError = function (error: NativeScriptError) {
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
events.notify(<UnhandledErrorEventData>{
eventName: uncaughtErrorEvent,
object: app,
android: error,
ios: error,
error: error,
});
};
global.__onDiscardedError = function (error: NativeScriptError) {
events.notify(<DiscardedErrorEventData>{ eventName: discardedErrorEvent, object: app, error: error });
events.notify(<DiscardedErrorEventData>{
eventName: discardedErrorEvent,
object: app,
error: error,
});
};

View File

@@ -3,77 +3,82 @@ import { EventData } from "../data/observable/observable-interfaces";
import { View } from "../ui/core/view";
export interface ApplicationEventData extends EventData {
ios?: any;
android?: any;
eventName: string;
object: any;
ios?: any;
android?: any;
eventName: string;
object: any;
}
export interface LaunchEventData extends ApplicationEventData {
root?: View;
savedInstanceState?: any /* android.os.Bundle */;
root?: View;
savedInstanceState?: any /* android.os.Bundle */;
}
export interface OrientationChangedEventData extends ApplicationEventData {
newValue: "portrait" | "landscape" | "unknown";
newValue: "portrait" | "landscape" | "unknown";
}
export interface SystemAppearanceChangedEventData extends ApplicationEventData {
newValue: "light" | "dark";
newValue: "light" | "dark";
}
export interface UnhandledErrorEventData extends ApplicationEventData {
ios?: NativeScriptError;
android?: NativeScriptError;
error: NativeScriptError;
ios?: NativeScriptError;
android?: NativeScriptError;
error: NativeScriptError;
}
export interface DiscardedErrorEventData extends ApplicationEventData {
error: NativeScriptError;
error: NativeScriptError;
}
export interface CssChangedEventData extends EventData {
cssFile?: string;
cssText?: string;
cssFile?: string;
cssText?: string;
}
export interface AndroidActivityEventData {
activity: any /* androidx.appcompat.app.AppCompatActivity */;
eventName: string;
object: any;
activity: any /* androidx.appcompat.app.AppCompatActivity */;
eventName: string;
object: any;
}
export interface AndroidActivityBundleEventData extends AndroidActivityEventData {
bundle: any /* android.os.Bundle */;
export interface AndroidActivityBundleEventData
extends AndroidActivityEventData {
bundle: any /* android.os.Bundle */;
}
export interface AndroidActivityRequestPermissionsEventData extends AndroidActivityEventData {
requestCode: number;
permissions: Array<string>;
grantResults: Array<number>;
export interface AndroidActivityRequestPermissionsEventData
extends AndroidActivityEventData {
requestCode: number;
permissions: Array<string>;
grantResults: Array<number>;
}
export interface AndroidActivityResultEventData extends AndroidActivityEventData {
requestCode: number;
resultCode: number;
intent: any /* android.content.Intent */;
export interface AndroidActivityResultEventData
extends AndroidActivityEventData {
requestCode: number;
resultCode: number;
intent: any /* android.content.Intent */;
}
export interface AndroidActivityNewIntentEventData extends AndroidActivityEventData {
intent: any /* android.content.Intent */;
export interface AndroidActivityNewIntentEventData
extends AndroidActivityEventData {
intent: any /* android.content.Intent */;
}
export interface AndroidActivityBackPressedEventData extends AndroidActivityEventData {
cancel: boolean;
export interface AndroidActivityBackPressedEventData
extends AndroidActivityEventData {
cancel: boolean;
}
/**
* @deprecated
*/
* @deprecated
*/
export interface RootViewControllerImpl {
contentController: any;
contentController: any;
}
export interface LoadAppCSSEventData extends EventData {
cssFile: string;
}
cssFile: string;
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
import { NavigationEntry } from "../ui/frame";
import { View } from '../ui/core/view';
import { Observable, EventData } from '../data/observable';
import { View } from "../ui/core/view";
import { Observable, EventData } from "../data/observable";
/**
* String value used when hooking to launch event.
@@ -56,82 +56,82 @@ export const systemAppearanceChangedEvent: string;
* Event data containing information for the application events.
*/
export interface ApplicationEventData extends EventData {
/**
* Gets the native iOS event arguments. Valid only when running on iOS.
*/
ios?: any;
/**
* Gets the native iOS event arguments. Valid only when running on iOS.
*/
ios?: any;
/**
* Gets the native Android event arguments. Valid only when running on Android.
*/
android?: any;
/**
* Gets the native Android event arguments. Valid only when running on Android.
*/
android?: any;
/**
* The name of the event.
*/
eventName: string;
/**
* The name of the event.
*/
eventName: string;
/**
* The instance that has raised the event.
*/
object: any;
/**
* The instance that has raised the event.
*/
object: any;
}
/**
* Event data containing information for launch event.
*/
export interface LaunchEventData extends ApplicationEventData {
/**
* The root view for this Window on iOS or Activity for Android.
* If not set a new Frame will be created as a root view in order to maintain backwards compatibility.
*/
root?: View;
/**
* The root view for this Window on iOS or Activity for Android.
* If not set a new Frame will be created as a root view in order to maintain backwards compatibility.
*/
root?: View;
savedInstanceState?: any /* android.os.Bundle */;
savedInstanceState?: any /* android.os.Bundle */;
}
/**
* Event data containing information for orientation changed event.
*/
export interface OrientationChangedEventData extends ApplicationEventData {
/**
* New orientation value.
*/
newValue: "portrait" | "landscape" | "unknown";
/**
* New orientation value.
*/
newValue: "portrait" | "landscape" | "unknown";
}
/**
* Event data containing information for system appearance changed event.
*/
export interface SystemAppearanceChangedEventData extends ApplicationEventData {
/**
* New system appearance value.
*/
newValue: "light" | "dark";
/**
* New system appearance value.
*/
newValue: "light" | "dark";
}
/**
* Event data containing information about unhandled application errors.
*/
export interface UnhandledErrorEventData extends ApplicationEventData {
ios?: NativeScriptError;
android?: NativeScriptError;
error: NativeScriptError;
ios?: NativeScriptError;
android?: NativeScriptError;
error: NativeScriptError;
}
/**
* Event data containing information about discarded application errors.
*/
export interface DiscardedErrorEventData extends ApplicationEventData {
error: NativeScriptError;
error: NativeScriptError;
}
/**
* Event data containing information about application css change.
*/
export interface CssChangedEventData extends EventData {
cssFile?: string;
cssText?: string;
cssFile?: string;
cssText?: string;
}
/**
@@ -173,16 +173,20 @@ export function getCssFileName(): string;
export function loadAppCss();
/**
* Adds new values to the application styles.
* @param cssText - A valid styles which will be added to the current application styles.
* @param attributeScoped - Whether the styles are attribute scoped. Adding attribute scoped styles will not perform a full application styling refresh.
*/
* Adds new values to the application styles.
* @param cssText - A valid styles which will be added to the current application styles.
* @param attributeScoped - Whether the styles are attribute scoped. Adding attribute scoped styles will not perform a full application styling refresh.
*/
export function addCss(cssText: string, attributeScoped?: boolean): void;
/**
* This event is raised when application css is changed.
*/
export function on(event: "cssChanged", callback: (args: CssChangedEventData) => void, thisArg?: any);
export function on(
event: "cssChanged",
callback: (args: CssChangedEventData) => void,
thisArg?: any
);
/**
* Event raised then livesync operation is performed.
@@ -212,7 +216,11 @@ export function _resetRootView(entry?: NavigationEntry | string);
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
export function on(eventNames: string, callback: (data: any) => void, thisArg?: any);
export function on(
eventNames: string,
callback: (data: any) => void,
thisArg?: any
);
/**
* Shortcut alias to the removeEventListener method.
@@ -237,56 +245,96 @@ export function hasListeners(eventName: string): boolean;
/**
* This event is raised on application launchEvent.
*/
export function on(event: "launch", callback: (args: LaunchEventData) => void, thisArg?: any);
export function on(
event: "launch",
callback: (args: LaunchEventData) => void,
thisArg?: any
);
/**
* 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
*/
export function on(event: "displayed", callback: (args: EventData) => void, thisArg?: any);
export function on(
event: "displayed",
callback: (args: EventData) => void,
thisArg?: any
);
/**
* This event is raised when the Application is suspended.
*/
export function on(event: "suspend", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(
event: "suspend",
callback: (args: ApplicationEventData) => void,
thisArg?: any
);
/**
* This event is raised when the Application is resumed after it has been suspended.
*/
export function on(event: "resume", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(
event: "resume",
callback: (args: ApplicationEventData) => void,
thisArg?: any
);
/**
* This event is raised when the Application is about to exit.
*/
export function on(event: "exit", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(
event: "exit",
callback: (args: ApplicationEventData) => void,
thisArg?: any
);
/**
* This event is raised when there is low memory on the target device.
*/
export function on(event: "lowMemory", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(
event: "lowMemory",
callback: (args: ApplicationEventData) => void,
thisArg?: any
);
/**
* This event is raised when an uncaught error occurs while the application is running.
*/
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
export function on(
event: "uncaughtError",
callback: (args: UnhandledErrorEventData) => void,
thisArg?: any
);
/**
* This event is raised when an discarded error occurs while the application is running.
*/
export function on(event: "discardedError", callback: (args: DiscardedErrorEventData) => void, thisArg?: any);
export function on(
event: "discardedError",
callback: (args: DiscardedErrorEventData) => void,
thisArg?: any
);
/**
* This event is raised when the orientation of the application changes.
*/
export function on(event: "orientationChanged", callback: (args: OrientationChangedEventData) => void, thisArg?: any);
export function on(
event: "orientationChanged",
callback: (args: OrientationChangedEventData) => void,
thisArg?: any
);
/**
* 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.
*/
export function on(event: "systemAppearanceChanged", callback: (args: SystemAppearanceChangedEventData) => void, thisArg?: any);
export function on(
event: "systemAppearanceChanged",
callback: (args: SystemAppearanceChangedEventData) => void,
thisArg?: any
);
/**
* Gets the orientation of the application.
@@ -319,277 +367,336 @@ export let ios: iOSApplication;
* Data for the Android activity events.
*/
export interface AndroidActivityEventData {
/**
* The activity.
*/
activity: any /* androidx.appcompat.app.AppCompatActivity */;
/**
* The activity.
*/
activity: any /* androidx.appcompat.app.AppCompatActivity */;
/**
* The name of the event.
*/
eventName: string;
/**
* The name of the event.
*/
eventName: string;
/**
* The instance that has raised the event.
*/
object: any;
/**
* The instance that has raised the event.
*/
object: any;
}
/**
* Data for the Android activity events with bundle.
*/
export interface AndroidActivityBundleEventData extends AndroidActivityEventData {
/**
* The bundle.
*/
bundle: any /* android.os.Bundle */;
export interface AndroidActivityBundleEventData
extends AndroidActivityEventData {
/**
* The bundle.
*/
bundle: any /* android.os.Bundle */;
}
/**
* Data for the Android activity onRequestPermissions callback
*/
export interface AndroidActivityRequestPermissionsEventData extends AndroidActivityEventData {
/**
* The request code.
*/
requestCode: number;
export interface AndroidActivityRequestPermissionsEventData
extends AndroidActivityEventData {
/**
* The request code.
*/
requestCode: number;
/**
* The Permissions.
*/
permissions: Array<string>;
/**
* The Permissions.
*/
permissions: Array<string>;
/**
* The Granted.
*/
grantResults: Array<number>;
/**
* The Granted.
*/
grantResults: Array<number>;
}
/**
* Data for the Android activity result event.
*/
export interface AndroidActivityResultEventData extends AndroidActivityEventData {
/**
* The request code.
*/
requestCode: number;
export interface AndroidActivityResultEventData
extends AndroidActivityEventData {
/**
* The request code.
*/
requestCode: number;
/**
* The result code.
*/
resultCode: number;
/**
* The result code.
*/
resultCode: number;
/**
* The intent.
*/
intent: any /* android.content.Intent */;
/**
* The intent.
*/
intent: any /* android.content.Intent */;
}
/**
* Data for the Android activity newIntent event.
*/
export interface AndroidActivityNewIntentEventData extends AndroidActivityEventData {
/**
* The intent.
*/
intent: any /* android.content.Intent */;
export interface AndroidActivityNewIntentEventData
extends AndroidActivityEventData {
/**
* The intent.
*/
intent: any /* android.content.Intent */;
}
/**
* Data for the Android activity back pressed event.
*/
export interface AndroidActivityBackPressedEventData extends AndroidActivityEventData {
/**
* In the event handler, set this value to true if you want to cancel the back navigation and do something else instead.
*/
cancel: boolean;
export interface AndroidActivityBackPressedEventData
extends AndroidActivityEventData {
/**
* In the event handler, set this value to true if you want to cancel the back navigation and do something else instead.
*/
cancel: boolean;
}
/**
* The abstraction of an Android-specific application object.
*/
export class AndroidApplication extends Observable {
/**
* The [android Application](http://developer.android.com/reference/android/app/Application.html) object instance provided to the init of the module.
*/
nativeApp: any /* android.app.Application */;
/**
* The [android Application](http://developer.android.com/reference/android/app/Application.html) object instance provided to the init of the module.
*/
nativeApp: any /* android.app.Application */;
/**
* The application's [android Context](http://developer.android.com/reference/android/content/Context.html) object instance.
*/
context: any /* android.content.Context */;
/**
* The application's [android Context](http://developer.android.com/reference/android/content/Context.html) object instance.
*/
context: any /* android.content.Context */;
/**
* The currently active (loaded) [android Activity](http://developer.android.com/reference/android/app/Activity.html). This property is automatically updated upon Activity events.
*/
foregroundActivity: any /* androidx.appcompat.app.AppCompatActivity */;
/**
* The currently active (loaded) [android Activity](http://developer.android.com/reference/android/app/Activity.html). This property is automatically updated upon Activity events.
*/
foregroundActivity: any /* androidx.appcompat.app.AppCompatActivity */;
/**
* The main (start) Activity for the application.
*/
startActivity: any /* androidx.appcompat.app.AppCompatActivity */;
/**
* The main (start) Activity for the application.
*/
startActivity: any /* androidx.appcompat.app.AppCompatActivity */;
/**
* Gets the orientation of the application.
* Available values: "portrait", "landscape", "unknown".
*/
orientation: "portrait" | "landscape" | "unknown";
/**
* Gets the orientation of the application.
* Available values: "portrait", "landscape", "unknown".
*/
orientation: "portrait" | "landscape" | "unknown";
/**
* Gets the system appearance.
* Available values: "dark", "light".
*/
systemAppearance: "dark" | "light";
/**
* Gets the system appearance.
* Available values: "dark", "light".
*/
systemAppearance: "dark" | "light";
/**
* The name of the application package.
*/
packageName: string;
/**
* The name of the application package.
*/
packageName: string;
/**
* True if the main application activity is not running (suspended), false otherwise.
*/
paused: boolean;
/**
* True if the main application activity is not running (suspended), false otherwise.
*/
paused: boolean;
/**
* Initialized the android-specific application object with the native android.app.Application instance.
* This is useful when creating custom application types.
* @param nativeApp - the android.app.Application instance that started the app.
*/
init: (nativeApp) => void;
/**
* Initialized the android-specific application object with the native android.app.Application instance.
* This is useful when creating custom application types.
* @param nativeApp - the android.app.Application instance that started the app.
*/
init: (nativeApp) => void;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: AndroidActivityEventData) => void, thisArg?: any);
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(
eventNames: string,
callback: (data: AndroidActivityEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityCreated.
*/
on(event: "activityCreated", callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityCreated.
*/
on(
event: "activityCreated",
callback: (args: AndroidActivityBundleEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityDestroyed.
*/
on(event: "activityDestroyed", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityDestroyed.
*/
on(
event: "activityDestroyed",
callback: (args: AndroidActivityEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityStarted.
*/
on(event: "activityStarted", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityStarted.
*/
on(
event: "activityStarted",
callback: (args: AndroidActivityEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityPaused.
*/
on(event: "activityPaused", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityPaused.
*/
on(
event: "activityPaused",
callback: (args: AndroidActivityEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityResumed.
*/
on(event: "activityResumed", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityResumed.
*/
on(
event: "activityResumed",
callback: (args: AndroidActivityEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityStopped.
*/
on(event: "activityStopped", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityStopped.
*/
on(
event: "activityStopped",
callback: (args: AndroidActivityEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application SaveActivityState.
*/
on(event: "saveActivityState", callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any);
/**
* This event is raised on android application SaveActivityState.
*/
on(
event: "saveActivityState",
callback: (args: AndroidActivityBundleEventData) => void,
thisArg?: any
);
/**
* This event is raised on android application ActivityResult.
*/
on(event: "activityResult", callback: (args: AndroidActivityResultEventData) => void, thisArg?: any);
/**
* This event is raised on android application ActivityResult.
*/
on(
event: "activityResult",
callback: (args: AndroidActivityResultEventData) => void,
thisArg?: any
);
/**
* This event is raised on the back button is pressed in an android application.
*/
on(event: "activityBackPressed", callback: (args: AndroidActivityBackPressedEventData) => void, thisArg?: any);
/**
* This event is raised on the back button is pressed in an android application.
*/
on(
event: "activityBackPressed",
callback: (args: AndroidActivityBackPressedEventData) => void,
thisArg?: any
);
/**
* This event is raised when the Android app was launched by an Intent with data.
*/
on(event: "activityNewIntent", callback: (args: AndroidActivityNewIntentEventData) => void, thisArg?: any);
/**
* This event is raised when the Android app was launched by an Intent with data.
*/
on(
event: "activityNewIntent",
callback: (args: AndroidActivityNewIntentEventData) => void,
thisArg?: any
);
/**
* This event is raised when the Android activity requests permissions.
*/
on(event: "activityRequestPermissions", callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any);
/**
* This event is raised when the Android activity requests permissions.
*/
on(
event: "activityRequestPermissions",
callback: (args: AndroidActivityRequestPermissionsEventData) => void,
thisArg?: any
);
/**
* String value used when hooking to activityCreated event.
*/
public static activityCreatedEvent: string;
/**
* String value used when hooking to activityCreated event.
*/
public static activityCreatedEvent: string;
/**
* String value used when hooking to activityDestroyed event.
*/
public static activityDestroyedEvent: string;
/**
* String value used when hooking to activityDestroyed event.
*/
public static activityDestroyedEvent: string;
/**
* String value used when hooking to activityStarted event.
*/
public static activityStartedEvent: string;
/**
* String value used when hooking to activityStarted event.
*/
public static activityStartedEvent: string;
/**
* String value used when hooking to activityPaused event.
*/
public static activityPausedEvent: string;
/**
* String value used when hooking to activityPaused event.
*/
public static activityPausedEvent: string;
/**
* String value used when hooking to activityResumed event.
*/
public static activityResumedEvent: string;
/**
* String value used when hooking to activityResumed event.
*/
public static activityResumedEvent: string;
/**
* String value used when hooking to activityStopped event.
*/
public static activityStoppedEvent: string;
/**
* String value used when hooking to activityStopped event.
*/
public static activityStoppedEvent: string;
/**
* String value used when hooking to saveActivityState event.
*/
public static saveActivityStateEvent: string;
/**
* String value used when hooking to saveActivityState event.
*/
public static saveActivityStateEvent: string;
/**
* String value used when hooking to activityResult event.
*/
public static activityResultEvent: string;
/**
* String value used when hooking to activityResult event.
*/
public static activityResultEvent: string;
/**
* String value used when hooking to activityBackPressed event.
*/
public static activityBackPressedEvent: string;
/**
* String value used when hooking to activityBackPressed event.
*/
public static activityBackPressedEvent: string;
/**
* String value used when hooking to activityNewIntent event.
*/
public static activityNewIntentEvent: string;
/**
* String value used when hooking to activityNewIntent event.
*/
public static activityNewIntentEvent: string;
/**
* String value used when hooking to requestPermissions event.
*/
public static activityRequestPermissionsEvent: string;
/**
* String value used when hooking to requestPermissions event.
*/
public static activityRequestPermissionsEvent: string;
/**
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
* @param intentFilter A string containing the intent filter.
* @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
*/
registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: any /* android.content.Context */, intent: any /* android.content.Intent */) => void): void;
/**
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
* @param intentFilter A string containing the intent filter.
* @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
*/
registerBroadcastReceiver(
intentFilter: string,
onReceiveCallback: (
context: any /* android.content.Context */,
intent: any /* android.content.Intent */
) => void
): void;
/**
* Unregister a previously registered BroadcastReceiver.
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
* @param intentFilter A string containing the intent filter with which the receiver was originally registered.
*/
unregisterBroadcastReceiver(intentFilter: string): void;
/**
* Unregister a previously registered BroadcastReceiver.
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
* @param intentFilter A string containing the intent filter with which the receiver was originally registered.
*/
unregisterBroadcastReceiver(intentFilter: string): void;
}
/* tslint:disable */
@@ -597,64 +704,67 @@ export class AndroidApplication extends Observable {
* The abstraction of an iOS-specific application object.
*/
export class iOSApplication {
/* tslint:enable */
/**
* The root view controller for the application.
*/
rootController: any /* UIViewController */;
/* tslint:enable */
/**
* The root view controller for the application.
*/
rootController: any /* UIViewController */;
/* tslint:enable */
/**
* The key window.
*/
window: any /* UIWindow */;
/* tslint:enable */
/**
* The key window.
*/
window: any /* UIWindow */;
/**
* The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class.
*/
delegate: any /* typeof UIApplicationDelegate */;
/**
* The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class.
*/
delegate: any /* typeof UIApplicationDelegate */;
/**
* Gets or sets the orientation of the application.
* Available values: "portrait", "landscape", "unknown".
*/
orientation: "portrait" | "landscape" | "unknown";
/**
* Gets or sets the orientation of the application.
* Available values: "portrait", "landscape", "unknown".
*/
orientation: "portrait" | "landscape" | "unknown";
/**
* Gets the system appearance.
* Available values: "dark", "light", null.
* Null for iOS <= 11.
*/
systemAppearance: "dark" | "light" | null;
/**
* Gets the system appearance.
* Available values: "dark", "light", null.
* Null for iOS <= 11.
*/
systemAppearance: "dark" | "light" | null;
/**
* The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html).
*/
nativeApp: any /* UIApplication */;
/**
* The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html).
*/
nativeApp: any /* UIApplication */;
/**
* Adds an observer to the default notification center for the specified notification.
* For more information, please visit 'https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/#//apple_ref/occ/instm/NSNotificationCenter/addObserver:selector:name:object:'
* @param notificationName A string containing the name of the notification.
* @param onReceiveCallback A callback function that will be called each time the observer receives a notification.
*/
addNotificationObserver(notificationName: string, onReceiveCallback: (notification: any /* NSNotification */) => void): any;
/**
* Adds an observer to the default notification center for the specified notification.
* For more information, please visit 'https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/#//apple_ref/occ/instm/NSNotificationCenter/addObserver:selector:name:object:'
* @param notificationName A string containing the name of the notification.
* @param onReceiveCallback A callback function that will be called each time the observer receives a notification.
*/
addNotificationObserver(
notificationName: string,
onReceiveCallback: (notification: any /* NSNotification */) => void
): any;
/**
* Removes the observer for the specified notification from the default notification center.
* For more information, please visit 'https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/#//apple_ref/occ/instm/NSNotificationCenter/addObserver:selector:name:object:'
* @param observer The observer that was returned from the addNotificationObserver method.
* @param notificationName A string containing the name of the notification.
* @param onReceiveCallback A callback function that will be called each time the observer receives a notification.
*/
removeNotificationObserver(observer: any, notificationName: string): void;
/**
* Removes the observer for the specified notification from the default notification center.
* For more information, please visit 'https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/#//apple_ref/occ/instm/NSNotificationCenter/addObserver:selector:name:object:'
* @param observer The observer that was returned from the addNotificationObserver method.
* @param notificationName A string containing the name of the notification.
* @param onReceiveCallback A callback function that will be called each time the observer receives a notification.
*/
removeNotificationObserver(observer: any, notificationName: string): void;
}
/**
* @deprecated
*/
* @deprecated
*/
export interface RootViewControllerImpl {
contentController: any;
contentController: any;
}
export function getNativeApplication(): any;
@@ -665,5 +775,5 @@ export function getNativeApplication(): any;
export function hasLaunched(): boolean;
export interface LoadAppCSSEventData extends EventData {
cssFile: string;
cssFile: string;
}

View File

@@ -1,21 +1,33 @@
// Types
import { iOSApplication as iOSApplicationDefinition } from ".";
import {
ApplicationEventData,
CssChangedEventData,
LaunchEventData,
LoadAppCSSEventData,
OrientationChangedEventData,
SystemAppearanceChangedEventData
ApplicationEventData,
CssChangedEventData,
LaunchEventData,
LoadAppCSSEventData,
OrientationChangedEventData,
SystemAppearanceChangedEventData,
} from "./application-interfaces";
import { View } from "../ui/core/view";
import { NavigationEntry } from "../ui/frame/frame-interfaces";
// Require
import {
displayedEvent, exitEvent, getCssFileName, launchEvent, livesync, lowMemoryEvent, notify, on,
orientationChanged, orientationChangedEvent, resumeEvent, setApplication, suspendEvent,
systemAppearanceChanged, systemAppearanceChangedEvent
displayedEvent,
exitEvent,
getCssFileName,
launchEvent,
livesync,
lowMemoryEvent,
notify,
on,
orientationChanged,
orientationChangedEvent,
resumeEvent,
setApplication,
suspendEvent,
systemAppearanceChanged,
systemAppearanceChangedEvent,
} from "./application-common";
// First reexport so that app module is initialized.
export * from "./application-common";
@@ -23,10 +35,10 @@ export * from "./application-common";
// TODO: Remove this and get it from global to decouple builder for angular
import { Builder } from "../ui/builder";
import {
CLASS_PREFIX,
getSystemCssClasses,
pushToSystemCssClasses,
ROOT_VIEW_CSS_CLASS
CLASS_PREFIX,
getSystemCssClasses,
pushToSystemCssClasses,
ROOT_VIEW_CSS_CLASS,
} from "../css/system-classes";
import { IOSHelper } from "../ui/core/view/view-helper";
import { device } from "../platform";
@@ -41,292 +53,388 @@ const majorVersion = ios.MajorVersion;
// NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430
// TODO: Refactor the UIResponder to use Typescript extends when this issue is resolved:
// https://github.com/NativeScript/ios-runtime/issues/1012
const Responder = (<any>UIResponder).extend({
get window() {
return iosApp ? iosApp.window : undefined;
},
set window(setWindow) {
// NOOP
}
}, {
protocols: [UIApplicationDelegate]
}
const Responder = (<any>UIResponder).extend(
{
get window() {
return iosApp ? iosApp.window : undefined;
},
set window(setWindow) {
// NOOP
},
},
{
protocols: [UIApplicationDelegate],
}
);
class NotificationObserver extends NSObject {
private _onReceiveCallback: (notification: NSNotification) => void;
private _onReceiveCallback: (notification: NSNotification) => void;
public static initWithCallback(onReceiveCallback: (notification: NSNotification) => void): NotificationObserver {
const observer = <NotificationObserver>super.new();
observer._onReceiveCallback = onReceiveCallback;
public static initWithCallback(
onReceiveCallback: (notification: NSNotification) => void
): NotificationObserver {
const observer = <NotificationObserver>super.new();
observer._onReceiveCallback = onReceiveCallback;
return observer;
}
return observer;
}
public onReceive(notification: NSNotification): void {
this._onReceiveCallback(notification);
}
public onReceive(notification: NSNotification): void {
this._onReceiveCallback(notification);
}
public static ObjCExposedMethods = {
"onReceive": { returns: interop.types.void, params: [NSNotification] }
};
public static ObjCExposedMethods = {
onReceive: { returns: interop.types.void, params: [NSNotification] },
};
}
let displayedOnce = false;
let displayedLinkTarget;
let displayedLink;
class CADisplayLinkTarget extends NSObject {
onDisplayed(link: CADisplayLink) {
link.invalidate();
const ios = UIApplication.sharedApplication;
const object = iosApp;
displayedOnce = true;
notify(<ApplicationEventData>{ eventName: displayedEvent, object, ios });
displayedLinkTarget = null;
displayedLink = null;
}
public static ObjCExposedMethods = {
"onDisplayed": { returns: interop.types.void, params: [CADisplayLink] }
};
onDisplayed(link: CADisplayLink) {
link.invalidate();
const ios = UIApplication.sharedApplication;
const object = iosApp;
displayedOnce = true;
notify(<ApplicationEventData>{
eventName: displayedEvent,
object,
ios,
});
displayedLinkTarget = null;
displayedLink = null;
}
public static ObjCExposedMethods = {
onDisplayed: { returns: interop.types.void, params: [CADisplayLink] },
};
}
/* tslint:disable */
export class iOSApplication implements iOSApplicationDefinition {
/* tslint:enable */
private _backgroundColor = (majorVersion <= 12 || !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
private _delegate: typeof UIApplicationDelegate;
private _window: UIWindow;
private _observers: Array<NotificationObserver>;
private _orientation: "portrait" | "landscape" | "unknown";
private _rootView: View;
private _systemAppearance: "light" | "dark";
/* tslint:enable */
private _backgroundColor =
majorVersion <= 12 || !UIColor.systemBackgroundColor
? UIColor.whiteColor
: UIColor.systemBackgroundColor;
private _delegate: typeof UIApplicationDelegate;
private _window: UIWindow;
private _observers: Array<NotificationObserver>;
private _orientation: "portrait" | "landscape" | "unknown";
private _rootView: View;
private _systemAppearance: "light" | "dark";
constructor() {
this._observers = new Array<NotificationObserver>();
this.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, this.didFinishLaunchingWithOptions.bind(this));
this.addNotificationObserver(UIApplicationDidBecomeActiveNotification, this.didBecomeActive.bind(this));
this.addNotificationObserver(UIApplicationDidEnterBackgroundNotification, this.didEnterBackground.bind(this));
this.addNotificationObserver(UIApplicationWillTerminateNotification, this.willTerminate.bind(this));
this.addNotificationObserver(UIApplicationDidReceiveMemoryWarningNotification, this.didReceiveMemoryWarning.bind(this));
this.addNotificationObserver(UIApplicationDidChangeStatusBarOrientationNotification, this.didChangeStatusBarOrientation.bind(this));
}
constructor() {
this._observers = new Array<NotificationObserver>();
this.addNotificationObserver(
UIApplicationDidFinishLaunchingNotification,
this.didFinishLaunchingWithOptions.bind(this)
);
this.addNotificationObserver(
UIApplicationDidBecomeActiveNotification,
this.didBecomeActive.bind(this)
);
this.addNotificationObserver(
UIApplicationDidEnterBackgroundNotification,
this.didEnterBackground.bind(this)
);
this.addNotificationObserver(
UIApplicationWillTerminateNotification,
this.willTerminate.bind(this)
);
this.addNotificationObserver(
UIApplicationDidReceiveMemoryWarningNotification,
this.didReceiveMemoryWarning.bind(this)
);
this.addNotificationObserver(
UIApplicationDidChangeStatusBarOrientationNotification,
this.didChangeStatusBarOrientation.bind(this)
);
}
get orientation(): "portrait" | "landscape" | "unknown" {
if (!this._orientation) {
const statusBarOrientation = UIApplication.sharedApplication.statusBarOrientation;
this._orientation = this.getOrientationValue(statusBarOrientation);
}
get orientation(): "portrait" | "landscape" | "unknown" {
if (!this._orientation) {
const statusBarOrientation =
UIApplication.sharedApplication.statusBarOrientation;
this._orientation = this.getOrientationValue(statusBarOrientation);
}
return this._orientation;
}
return this._orientation;
}
get rootController(): UIViewController {
return this._window.rootViewController;
}
get rootController(): UIViewController {
return this._window.rootViewController;
}
get systemAppearance(): "light" | "dark" | null {
// userInterfaceStyle is available on UITraitCollection since iOS 12.
if (majorVersion <= 11) {
return null;
}
get systemAppearance(): "light" | "dark" | null {
// userInterfaceStyle is available on UITraitCollection since iOS 12.
if (majorVersion <= 11) {
return null;
}
if (!this._systemAppearance) {
const userInterfaceStyle = this.rootController.traitCollection.userInterfaceStyle;
this._systemAppearance = getSystemAppearanceValue(userInterfaceStyle);
}
if (!this._systemAppearance) {
const userInterfaceStyle = this.rootController.traitCollection
.userInterfaceStyle;
this._systemAppearance = getSystemAppearanceValue(
userInterfaceStyle
);
}
return this._systemAppearance;
}
return this._systemAppearance;
}
get nativeApp(): UIApplication {
return UIApplication.sharedApplication;
}
get nativeApp(): UIApplication {
return UIApplication.sharedApplication;
}
get window(): UIWindow {
return this._window;
}
get window(): UIWindow {
return this._window;
}
get delegate(): typeof UIApplicationDelegate {
return this._delegate;
}
get delegate(): typeof UIApplicationDelegate {
return this._delegate;
}
set delegate(value: typeof UIApplicationDelegate) {
if (this._delegate !== value) {
this._delegate = value;
}
}
set delegate(value: typeof UIApplicationDelegate) {
if (this._delegate !== value) {
this._delegate = value;
}
}
get rootView(): View {
return this._rootView;
}
get rootView(): View {
return this._rootView;
}
public addNotificationObserver(notificationName: string, onReceiveCallback: (notification: NSNotification) => void): NotificationObserver {
const observer = NotificationObserver.initWithCallback(onReceiveCallback);
NSNotificationCenter.defaultCenter.addObserverSelectorNameObject(observer, "onReceive", notificationName, null);
this._observers.push(observer);
public addNotificationObserver(
notificationName: string,
onReceiveCallback: (notification: NSNotification) => void
): NotificationObserver {
const observer = NotificationObserver.initWithCallback(
onReceiveCallback
);
NSNotificationCenter.defaultCenter.addObserverSelectorNameObject(
observer,
"onReceive",
notificationName,
null
);
this._observers.push(observer);
return observer;
}
return observer;
}
public removeNotificationObserver(observer: any, notificationName: string) {
const index = this._observers.indexOf(observer);
if (index >= 0) {
this._observers.splice(index, 1);
NSNotificationCenter.defaultCenter.removeObserverNameObject(observer, notificationName, null);
}
}
public removeNotificationObserver(observer: any, notificationName: string) {
const index = this._observers.indexOf(observer);
if (index >= 0) {
this._observers.splice(index, 1);
NSNotificationCenter.defaultCenter.removeObserverNameObject(
observer,
notificationName,
null
);
}
}
@profile()
private didFinishLaunchingWithOptions(notification: NSNotification) {
if (!displayedOnce) {
displayedLinkTarget = CADisplayLinkTarget.new();
displayedLink = CADisplayLink.displayLinkWithTargetSelector(displayedLinkTarget, "onDisplayed");
displayedLink.addToRunLoopForMode(NSRunLoop.mainRunLoop, NSDefaultRunLoopMode);
displayedLink.addToRunLoopForMode(NSRunLoop.mainRunLoop, UITrackingRunLoopMode);
}
@profile()
private didFinishLaunchingWithOptions(notification: NSNotification) {
if (!displayedOnce) {
displayedLinkTarget = CADisplayLinkTarget.new();
displayedLink = CADisplayLink.displayLinkWithTargetSelector(
displayedLinkTarget,
"onDisplayed"
);
displayedLink.addToRunLoopForMode(
NSRunLoop.mainRunLoop,
NSDefaultRunLoopMode
);
displayedLink.addToRunLoopForMode(
NSRunLoop.mainRunLoop,
UITrackingRunLoopMode
);
}
this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
// TODO: Expose Window module so that it can we styled from XML & CSS
this._window.backgroundColor = this._backgroundColor;
this._window = UIWindow.alloc().initWithFrame(
UIScreen.mainScreen.bounds
);
// TODO: Expose Window module so that it can we styled from XML & CSS
this._window.backgroundColor = this._backgroundColor;
this.notifyAppStarted(notification);
}
this.notifyAppStarted(notification);
}
public notifyAppStarted(notification?: NSNotification) {
const args: LaunchEventData = {
eventName: launchEvent,
object: this,
ios: notification && notification.userInfo && notification.userInfo.objectForKey("UIApplicationLaunchOptionsLocalNotificationKey") || null
};
public notifyAppStarted(notification?: NSNotification) {
const args: LaunchEventData = {
eventName: launchEvent,
object: this,
ios:
(notification &&
notification.userInfo &&
notification.userInfo.objectForKey(
"UIApplicationLaunchOptionsLocalNotificationKey"
)) ||
null,
};
notify(args);
notify(<LoadAppCSSEventData>{ eventName: "loadAppCss", object: <any>this, cssFile: getCssFileName() });
notify(args);
notify(<LoadAppCSSEventData>{
eventName: "loadAppCss",
object: <any>this,
cssFile: getCssFileName(),
});
// this._window will be undefined when NS app is embedded in a native one
if (this._window) {
this.setWindowContent(args.root);
} else {
this._window = UIApplication.sharedApplication.delegate.window;
}
}
// this._window will be undefined when NS app is embedded in a native one
if (this._window) {
this.setWindowContent(args.root);
} else {
this._window = UIApplication.sharedApplication.delegate.window;
}
}
@profile()
private didBecomeActive(notification: NSNotification) {
const ios = UIApplication.sharedApplication;
const object = this;
notify(<ApplicationEventData>{ eventName: resumeEvent, object, ios });
const rootView = this._rootView;
if (rootView && !rootView.isLoaded) {
rootView.callLoaded();
}
}
@profile()
private didBecomeActive(notification: NSNotification) {
const ios = UIApplication.sharedApplication;
const object = this;
notify(<ApplicationEventData>{ eventName: resumeEvent, object, ios });
const rootView = this._rootView;
if (rootView && !rootView.isLoaded) {
rootView.callLoaded();
}
}
private didEnterBackground(notification: NSNotification) {
notify(<ApplicationEventData>{ eventName: suspendEvent, object: this, ios: UIApplication.sharedApplication });
const rootView = this._rootView;
if (rootView && rootView.isLoaded) {
rootView.callUnloaded();
}
}
private didEnterBackground(notification: NSNotification) {
notify(<ApplicationEventData>{
eventName: suspendEvent,
object: this,
ios: UIApplication.sharedApplication,
});
const rootView = this._rootView;
if (rootView && rootView.isLoaded) {
rootView.callUnloaded();
}
}
private willTerminate(notification: NSNotification) {
notify(<ApplicationEventData>{ eventName: exitEvent, object: this, ios: UIApplication.sharedApplication });
const rootView = this._rootView;
if (rootView && rootView.isLoaded) {
rootView.callUnloaded();
}
}
private willTerminate(notification: NSNotification) {
notify(<ApplicationEventData>{
eventName: exitEvent,
object: this,
ios: UIApplication.sharedApplication,
});
const rootView = this._rootView;
if (rootView && rootView.isLoaded) {
rootView.callUnloaded();
}
}
private didChangeStatusBarOrientation(notification: NSNotification) {
const statusBarOrientation = UIApplication.sharedApplication.statusBarOrientation;
const newOrientation = this.getOrientationValue(statusBarOrientation);
private didChangeStatusBarOrientation(notification: NSNotification) {
const statusBarOrientation =
UIApplication.sharedApplication.statusBarOrientation;
const newOrientation = this.getOrientationValue(statusBarOrientation);
if (this._orientation !== newOrientation) {
this._orientation = newOrientation;
orientationChanged(getRootView(), newOrientation);
if (this._orientation !== newOrientation) {
this._orientation = newOrientation;
orientationChanged(getRootView(), newOrientation);
notify(<OrientationChangedEventData>{
eventName: orientationChangedEvent,
ios: this,
newValue: this._orientation,
object: this
});
}
}
notify(<OrientationChangedEventData>{
eventName: orientationChangedEvent,
ios: this,
newValue: this._orientation,
object: this,
});
}
}
private didReceiveMemoryWarning(notification: NSNotification) {
notify(<ApplicationEventData>{ eventName: lowMemoryEvent, object: this, ios: UIApplication.sharedApplication });
}
private didReceiveMemoryWarning(notification: NSNotification) {
notify(<ApplicationEventData>{
eventName: lowMemoryEvent,
object: this,
ios: UIApplication.sharedApplication,
});
}
private getOrientationValue(orientation: number): "portrait" | "landscape" | "unknown" {
switch (orientation) {
case UIInterfaceOrientation.LandscapeRight:
case UIInterfaceOrientation.LandscapeLeft:
return "landscape";
case UIInterfaceOrientation.PortraitUpsideDown:
case UIInterfaceOrientation.Portrait:
return "portrait";
case UIInterfaceOrientation.Unknown:
return "unknown";
}
}
private getOrientationValue(
orientation: number
): "portrait" | "landscape" | "unknown" {
switch (orientation) {
case UIInterfaceOrientation.LandscapeRight:
case UIInterfaceOrientation.LandscapeLeft:
return "landscape";
case UIInterfaceOrientation.PortraitUpsideDown:
case UIInterfaceOrientation.Portrait:
return "portrait";
case UIInterfaceOrientation.Unknown:
return "unknown";
}
}
public _onLivesync(context?: ModuleContext): void {
// Handle application root module
const isAppRootModuleChanged = context && context.path && context.path.includes(getMainEntry().moduleName) && context.type !== "style";
public _onLivesync(context?: ModuleContext): void {
// Handle application root module
const isAppRootModuleChanged =
context &&
context.path &&
context.path.includes(getMainEntry().moduleName) &&
context.type !== "style";
// Set window content when:
// + Application root module is changed
// + View did not handle the change
// Note:
// The case when neither app root module is changed, nor livesync is handled on View,
// then changes will not apply until navigate forward to the module.
if (isAppRootModuleChanged || (this._rootView && !this._rootView._onLivesync(context))) {
this.setWindowContent();
}
}
// Set window content when:
// + Application root module is changed
// + View did not handle the change
// Note:
// The case when neither app root module is changed, nor livesync is handled on View,
// then changes will not apply until navigate forward to the module.
if (
isAppRootModuleChanged ||
(this._rootView && !this._rootView._onLivesync(context))
) {
this.setWindowContent();
}
}
public setWindowContent(view?: View): void {
if (this._rootView) {
// if we already have a root view, we reset it.
this._rootView._onRootViewReset();
}
const rootView = createRootView(view);
const controller = getViewController(rootView);
public setWindowContent(view?: View): void {
if (this._rootView) {
// if we already have a root view, we reset it.
this._rootView._onRootViewReset();
}
const rootView = createRootView(view);
const controller = getViewController(rootView);
this._rootView = rootView;
this._rootView = rootView;
// setup view as styleScopeHost
rootView._setupAsRootView({});
// setup view as styleScopeHost
rootView._setupAsRootView({});
setViewControllerView(rootView);
setViewControllerView(rootView);
const haveController = this._window.rootViewController !== null;
this._window.rootViewController = controller;
const haveController = this._window.rootViewController !== null;
this._window.rootViewController = controller;
setRootViewsSystemAppearanceCssClass(rootView);
setRootViewsSystemAppearanceCssClass(rootView);
if (!haveController) {
this._window.makeKeyAndVisible();
}
if (!haveController) {
this._window.makeKeyAndVisible();
}
rootView.on(IOSHelper.traitCollectionColorAppearanceChangedEvent, () => {
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
rootView.on(
IOSHelper.traitCollectionColorAppearanceChangedEvent,
() => {
const userInterfaceStyle =
controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(
userInterfaceStyle
);
if (this._systemAppearance !== newSystemAppearance) {
this._systemAppearance = newSystemAppearance;
systemAppearanceChanged(rootView, newSystemAppearance);
if (this._systemAppearance !== newSystemAppearance) {
this._systemAppearance = newSystemAppearance;
systemAppearanceChanged(rootView, newSystemAppearance);
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: this._systemAppearance,
object: this
});
}
});
}
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: this._systemAppearance,
object: this,
});
}
}
);
}
}
/* tslint:disable */
@@ -337,175 +445,211 @@ setApplication(iosApp);
// attach on global, so it can be overwritten in NativeScript Angular
(<any>global).__onLiveSyncCore = function (context?: ModuleContext) {
iosApp._onLivesync(context);
iosApp._onLivesync(context);
};
let mainEntry: NavigationEntry;
function createRootView(v?: View) {
let rootView = v;
if (!rootView) {
// try to navigate to the mainEntry (if specified)
if (!mainEntry) {
throw new Error("Main entry is missing. App cannot be started. Verify app bootstrap.");
} else {
rootView = Builder.createViewFromEntry(mainEntry);
}
}
let rootView = v;
if (!rootView) {
// try to navigate to the mainEntry (if specified)
if (!mainEntry) {
throw new Error(
"Main entry is missing. App cannot be started. Verify app bootstrap."
);
} else {
rootView = Builder.createViewFromEntry(mainEntry);
}
}
setRootViewsCssClasses(rootView);
setRootViewsCssClasses(rootView);
return rootView;
return rootView;
}
export function getMainEntry() {
return mainEntry;
return mainEntry;
}
export function getRootView() {
return iosApp.rootView;
return iosApp.rootView;
}
let started: boolean = false;
export function run(entry?: string | NavigationEntry) {
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
started = true;
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
started = true;
if (!iosApp.nativeApp) {
// Normal NativeScript app will need UIApplicationMain.
UIApplicationMain(0, null, null, iosApp && iosApp.delegate ? NSStringFromClass(<any>iosApp.delegate) : NSStringFromClass(Responder));
} else {
// TODO: this rootView should be held alive until rootController dismissViewController is called.
const rootView = createRootView();
if (rootView) {
// Attach to the existing iOS app
const window = iosApp.nativeApp.keyWindow || (iosApp.nativeApp.windows.count > 0 && iosApp.nativeApp.windows[0]);
if (window) {
const rootController = window.rootViewController;
if (rootController) {
const controller = getViewController(rootView);
rootView._setupAsRootView({});
let embedderDelegate = NativeScriptEmbedder.sharedInstance().delegate;
if (embedderDelegate) {
embedderDelegate.presentNativeScriptApp(controller);
} else {
let visibleVC = getVisibleViewController(rootController);
visibleVC.presentViewControllerAnimatedCompletion(controller, true, null);
}
if (!iosApp.nativeApp) {
// Normal NativeScript app will need UIApplicationMain.
UIApplicationMain(
0,
null,
null,
iosApp && iosApp.delegate
? NSStringFromClass(<any>iosApp.delegate)
: NSStringFromClass(Responder)
);
} else {
// TODO: this rootView should be held alive until rootController dismissViewController is called.
const rootView = createRootView();
if (rootView) {
// Attach to the existing iOS app
const window =
iosApp.nativeApp.keyWindow ||
(iosApp.nativeApp.windows.count > 0 &&
iosApp.nativeApp.windows[0]);
if (window) {
const rootController = window.rootViewController;
if (rootController) {
const controller = getViewController(rootView);
rootView._setupAsRootView({});
let embedderDelegate = NativeScriptEmbedder.sharedInstance()
.delegate;
if (embedderDelegate) {
embedderDelegate.presentNativeScriptApp(controller);
} else {
let visibleVC = getVisibleViewController(
rootController
);
visibleVC.presentViewControllerAnimatedCompletion(
controller,
true,
null
);
}
// Mind root view CSS classes in future work
// on embedding NativeScript applications
setRootViewsSystemAppearanceCssClass(rootView);
rootView.on(IOSHelper.traitCollectionColorAppearanceChangedEvent, () => {
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
// Mind root view CSS classes in future work
// on embedding NativeScript applications
setRootViewsSystemAppearanceCssClass(rootView);
rootView.on(
IOSHelper.traitCollectionColorAppearanceChangedEvent,
() => {
const userInterfaceStyle =
controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(
userInterfaceStyle
);
if (this._systemAppearance !== newSystemAppearance) {
this._systemAppearance = newSystemAppearance;
if (
this._systemAppearance !== newSystemAppearance
) {
this._systemAppearance = newSystemAppearance;
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: this._systemAppearance,
object: this
});
}
});
iosApp.notifyAppStarted();
}
}
}
}
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: this._systemAppearance,
object: this,
});
}
}
);
iosApp.notifyAppStarted();
}
}
}
}
}
export function addCss(cssText: string, attributeScoped?: boolean): void {
notify(<CssChangedEventData>{ eventName: "cssChanged", object: <any>iosApp, cssText: cssText });
if (!attributeScoped) {
const rootView = getRootView();
if (rootView) {
rootView._onCssStateChange();
}
}
notify(<CssChangedEventData>{
eventName: "cssChanged",
object: <any>iosApp,
cssText: cssText,
});
if (!attributeScoped) {
const rootView = getRootView();
if (rootView) {
rootView._onCssStateChange();
}
}
}
export function _resetRootView(entry?: NavigationEntry | string) {
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
iosApp.setWindowContent();
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
iosApp.setWindowContent();
}
export function getNativeApplication(): UIApplication {
return iosApp.nativeApp;
return iosApp.nativeApp;
}
function getSystemAppearanceValue(userInterfaceStyle: number): "dark" | "light" {
switch (userInterfaceStyle) {
case UIUserInterfaceStyle.Dark:
return "dark";
case UIUserInterfaceStyle.Light:
case UIUserInterfaceStyle.Unspecified:
return "light";
}
function getSystemAppearanceValue(
userInterfaceStyle: number
): "dark" | "light" {
switch (userInterfaceStyle) {
case UIUserInterfaceStyle.Dark:
return "dark";
case UIUserInterfaceStyle.Light:
case UIUserInterfaceStyle.Unspecified:
return "light";
}
}
function getViewController(rootView: View): UIViewController {
let viewController: UIViewController = rootView.viewController || rootView.ios;
let viewController: UIViewController =
rootView.viewController || rootView.ios;
if (!(viewController instanceof UIViewController)) {
// We set UILayoutViewController dynamically to the root view if it doesn't have a view controller
// At the moment the root view doesn't have its native view created. We set it in the setViewControllerView func
viewController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(rootView)) as UIViewController;
rootView.viewController = viewController;
}
if (!(viewController instanceof UIViewController)) {
// We set UILayoutViewController dynamically to the root view if it doesn't have a view controller
// At the moment the root view doesn't have its native view created. We set it in the setViewControllerView func
viewController = IOSHelper.UILayoutViewController.initWithOwner(
new WeakRef(rootView)
) as UIViewController;
rootView.viewController = viewController;
}
return viewController;
return viewController;
}
function setViewControllerView(view: View): void {
const viewController: UIViewController = view.viewController || view.ios;
const nativeView = view.ios || view.nativeViewProtected;
const viewController: UIViewController = view.viewController || view.ios;
const nativeView = view.ios || view.nativeViewProtected;
if (!nativeView || !viewController) {
throw new Error("Root should be either UIViewController or UIView");
}
if (!nativeView || !viewController) {
throw new Error("Root should be either UIViewController or UIView");
}
if (viewController instanceof IOSHelper.UILayoutViewController) {
viewController.view.addSubview(nativeView);
}
if (viewController instanceof IOSHelper.UILayoutViewController) {
viewController.view.addSubview(nativeView);
}
}
function setRootViewsCssClasses(rootView: View): void {
const deviceType = device.deviceType.toLowerCase();
const deviceType = device.deviceType.toLowerCase();
pushToSystemCssClasses(`${CLASS_PREFIX}${IOS_PLATFORM}`);
pushToSystemCssClasses(`${CLASS_PREFIX}${deviceType}`);
pushToSystemCssClasses(`${CLASS_PREFIX}${iosApp.orientation}`);
pushToSystemCssClasses(`${CLASS_PREFIX}${IOS_PLATFORM}`);
pushToSystemCssClasses(`${CLASS_PREFIX}${deviceType}`);
pushToSystemCssClasses(`${CLASS_PREFIX}${iosApp.orientation}`);
rootView.cssClasses.add(ROOT_VIEW_CSS_CLASS);
const rootViewCssClasses = getSystemCssClasses();
rootViewCssClasses.forEach(c => rootView.cssClasses.add(c));
rootView.cssClasses.add(ROOT_VIEW_CSS_CLASS);
const rootViewCssClasses = getSystemCssClasses();
rootViewCssClasses.forEach((c) => rootView.cssClasses.add(c));
}
function setRootViewsSystemAppearanceCssClass(rootView: View): void {
if (majorVersion >= 13) {
const systemAppearanceCssClass = `${CLASS_PREFIX}${iosApp.systemAppearance}`;
pushToSystemCssClasses(systemAppearanceCssClass);
rootView.cssClasses.add(systemAppearanceCssClass);
}
if (majorVersion >= 13) {
const systemAppearanceCssClass = `${CLASS_PREFIX}${iosApp.systemAppearance}`;
pushToSystemCssClasses(systemAppearanceCssClass);
rootView.cssClasses.add(systemAppearanceCssClass);
}
}
export function orientation(): "portrait" | "landscape" | "unknown" {
return iosApp.orientation;
return iosApp.orientation;
}
export function systemAppearance(): "dark" | "light" {
return iosApp.systemAppearance;
return iosApp.systemAppearance;
}
global.__onLiveSync = function __onLiveSync(context?: ModuleContext) {
if (!started) {
return;
}
if (!started) {
return;
}
const rootView = getRootView();
livesync(rootView, context);
const rootView = getRootView();
livesync(rootView, context);
};