UNPKG

23.8 kBTypeScriptView Raw
1import { NavigationEntry } from '../ui/frame';
2import { View } from '../ui/core/view';
3import { Observable, EventData } from '../data/observable';
4
5export * from './application-interfaces';
6
7/**
8 * String value used when hooking to launch event.
9 */
10export const launchEvent: string;
11
12/**
13 * String value used when hooking to displayed event.
14 */
15export const displayedEvent: string;
16
17/**
18 * String value used when hooking to uncaughtError event.
19 */
20export const uncaughtErrorEvent: string;
21
22/**
23 * String value used when hooking to discardedError event.
24 */
25export const discardedErrorEvent: string;
26
27/**
28 * String value used when hooking to suspend event.
29 */
30export const suspendEvent: string;
31
32/**
33 * String value used when hooking to resume event.
34 */
35export const resumeEvent: string;
36
37/**
38 * String value used when hooking to foreground event.
39 */
40export const foregroundEvent: string;
41
42/**
43 * String value used when hooking to background event.
44 */
45export const backgroundEvent: string;
46
47/**
48 * String value used when hooking to exit event.
49 */
50export const exitEvent: string;
51
52/**
53 * String value used when hooking to lowMemory event.
54 */
55export const lowMemoryEvent: string;
56
57/**
58 * String value used when hooking to orientationChanged event.
59 */
60export const orientationChangedEvent: string;
61
62/**
63 * String value used when hooking to systemAppearanceChanged event.
64 */
65export const systemAppearanceChangedEvent: string;
66
67/**
68 * String value used when hooking to fontScaleChanged event.
69 */
70export const fontScaleChangedEvent: string;
71
72/**
73 * Boolean to enable/disable systemAppearanceChanged
74 */
75export let autoSystemAppearanceChanged: boolean;
76
77/**
78 * enable/disable systemAppearanceChanged
79 */
80export function setAutoSystemAppearanceChanged(value: boolean): void;
81
82/**
83 * Updates root view classes including those of modals
84 * @param rootView the root view
85 * @param newSystemAppearance the new appearance change
86 */
87export function systemAppearanceChanged(rootView: View, newSystemAppearance: 'dark' | 'light'): void;
88
89/**
90 * iOS Only
91 * Dynamically change the preferred frame rate
92 * For devices (iOS 15+) which support min/max/preferred frame rate you can specify ranges
93 * For devices (iOS < 15), you can specify the max frame rate
94 * see: https://developer.apple.com/documentation/quartzcore/optimizing_promotion_refresh_rates_for_iphone_13_pro_and_ipad_pro
95 * To use, ensure your Info.plist has:
96 * <key>CADisableMinimumFrameDurationOnPhone</key>
97 * <true/>
98 * @param options { min?: number; max?: number; preferred?: number }
99 */
100export function setMaxRefreshRate(options?: { min?: number; max?: number; preferred?: number }): void;
101
102/**
103 * Event data containing information for the application events.
104 */
105export interface ApplicationEventData extends EventData {
106 /**
107 * Gets the native iOS event arguments. Valid only when running on iOS.
108 */
109 ios?: any;
110
111 /**
112 * Gets the native Android event arguments. Valid only when running on Android.
113 */
114 android?: any;
115
116 /**
117 * The name of the event.
118 */
119 eventName: string;
120
121 /**
122 * The instance that has raised the event.
123 */
124 object: any;
125}
126
127/**
128 * Event data containing information for launch event.
129 */
130export interface LaunchEventData extends ApplicationEventData {
131 /**
132 * The root view for this Window on iOS or Activity for Android.
133 * If not set a new Frame will be created as a root view in order to maintain backwards compatibility.
134 * If explicitly set to null, there will be no root view.
135 */
136 root?: View | null;
137
138 savedInstanceState?: any /* android.os.Bundle */;
139}
140
141/**
142 * Event data containing information for orientation changed event.
143 */
144export interface OrientationChangedEventData extends ApplicationEventData {
145 /**
146 * New orientation value.
147 */
148 newValue: 'portrait' | 'landscape' | 'unknown';
149}
150
151/**
152 * Event data containing information for system appearance changed event.
153 */
154export interface SystemAppearanceChangedEventData extends ApplicationEventData {
155 /**
156 * New system appearance value.
157 */
158 newValue: 'light' | 'dark';
159}
160
161/**
162 * Event data containing information for font scale changed event.
163 */
164export interface FontScaleChangedEventData extends ApplicationEventData {
165 /**
166 * New font scale value.
167 */
168 newValue: number;
169}
170
171/**
172 * Event data containing information about unhandled application errors.
173 */
174export interface UnhandledErrorEventData extends ApplicationEventData {
175 ios?: NativeScriptError;
176 android?: NativeScriptError;
177 error: NativeScriptError;
178}
179
180/**
181 * Event data containing information about discarded application errors.
182 */
183export interface DiscardedErrorEventData extends ApplicationEventData {
184 error: NativeScriptError;
185}
186
187/**
188 * Event data containing information about application css change.
189 */
190export interface CssChangedEventData extends EventData {
191 cssFile?: string;
192 cssText?: string;
193}
194
195/**
196 * Get main entry specified when calling start function.
197 */
198export function getMainEntry(): NavigationEntry;
199
200/**
201 * Get current application root view.
202 */
203export function getRootView(): View;
204
205/**
206 * Get application level static resources.
207 */
208export function getResources(): any;
209
210/**
211 * Set application level static resources.
212 */
213export function setResources(resources: any): void;
214
215/**
216 * Sets css file name for the application.
217 */
218export function setCssFileName(cssFile: string): void;
219
220/**
221 * Gets css file name for the application.
222 */
223export function getCssFileName(): string;
224
225/**
226 * Ensure css-class is set on rootView
227 */
228export function applyCssClass(rootView: View, cssClasses: string[], newCssClass: string): void;
229
230/**
231 * Loads immediately the app.css.
232 * By default the app.css file is loaded shortly after "loaded".
233 * For the Android snapshot the CSS can be parsed during the snapshot generation,
234 * as the CSS does not depend on runtime APIs, and loadAppCss will be called explicitly.
235 */
236export function loadAppCss();
237
238/**
239 * Adds new values to the application styles.
240 * @param cssText - A valid styles which will be added to the current application styles.
241 * @param attributeScoped - Whether the styles are attribute scoped. Adding attribute scoped styles will not perform a full application styling refresh.
242 */
243export function addCss(cssText: string, attributeScoped?: boolean): void;
244
245/**
246 * Call this method to run the application. Important: All code after this method call will not be executed!
247 * Compared to start this method won't create Frame as root view.
248 */
249export function run(entry?: NavigationEntry | string);
250
251/**
252 * Call this method to change the root view of your application. Important: Your application must already be running.
253 * This method won't create Frame as root view.
254 */
255export function _resetRootView(entry?: NavigationEntry | string);
256
257/**
258 * Removes listener for the specified event name.
259 */
260export function off(eventNames: string, callback?: any, thisArg?: any);
261
262/**
263 * Shortcut alias to the removeEventListener method.
264 * @param eventNames - String corresponding to events (e.g. "onLaunch").
265 * @param callback - Callback function which will be removed.
266 * @param thisArg - An optional parameter which will be used as `this` context for callback execution.
267 */
268export function off(eventNames: string, callback?: any, thisArg?: any);
269
270/**
271 * Notifies all the registered listeners for the event provided in the data.eventName.
272 * @param data The data associated with the event.
273 */
274export function notify(data: any): void;
275
276/**
277 * Checks whether a listener is registered for the specified event name.
278 * @param eventName The name of the event to check for.
279 */
280export function hasListeners(eventName: string): boolean;
281
282/**
283 * A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
284 * @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
285 * @param callback - Callback function which will be executed when event is raised.
286 * @param thisArg - An optional parameter which will be used as `this` context for callback execution.
287 */
288export function on(eventNames: string, callback: (data: any) => void, thisArg?: any);
289
290/**
291 * This event is raised when application css is changed.
292 */
293export function on(event: 'cssChanged', callback: (args: CssChangedEventData) => void, thisArg?: any);
294
295/**
296 * Event raised then livesync operation is performed.
297 */
298export function on(event: 'livesync', callback: (args: EventData) => void);
299
300/**
301 * This event is raised when application css is changed.
302 */
303export function on(event: 'cssChanged', callback: (args: CssChangedEventData) => void, thisArg?: any);
304
305/**
306 * Event raised then livesync operation is performed.
307 */
308export function on(event: 'livesync', callback: (args: EventData) => void);
309
310/**
311 * This event is raised on application launchEvent.
312 */
313export function on(event: 'launch', callback: (args: LaunchEventData) => void, thisArg?: any);
314
315/**
316 * This event is raised after the application has performed most of its startup actions.
317 * Its intent is to be suitable for measuring app startup times.
318 * @experimental
319 */
320export function on(event: 'displayed', callback: (args: EventData) => void, thisArg?: any);
321
322/**
323 * This event is raised when the Application is suspended.
324 */
325export function on(event: 'suspend', callback: (args: ApplicationEventData) => void, thisArg?: any);
326
327/**
328 * This event is raised when the Application is resumed after it has been suspended.
329 */
330export function on(event: 'resume', callback: (args: ApplicationEventData) => void, thisArg?: any);
331
332/**
333 * This event is raised when the Application is about to exit.
334 */
335export function on(event: 'exit', callback: (args: ApplicationEventData) => void, thisArg?: any);
336
337/**
338 * This event is raised when there is low memory on the target device.
339 */
340export function on(event: 'lowMemory', callback: (args: ApplicationEventData) => void, thisArg?: any);
341
342/**
343 * This event is raised when an uncaught error occurs while the application is running.
344 */
345export function on(event: 'uncaughtError', callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
346
347/**
348 * This event is raised when an discarded error occurs while the application is running.
349 */
350export function on(event: 'discardedError', callback: (args: DiscardedErrorEventData) => void, thisArg?: any);
351
352/**
353 * This event is raised when the orientation of the application changes.
354 */
355export function on(event: 'orientationChanged', callback: (args: OrientationChangedEventData) => void, thisArg?: any);
356
357/**
358 * This event is raised when the operating system appearance changes
359 * between light and dark theme (for Android);
360 * between light and dark mode (for iOS) and vice versa.
361 */
362export function on(event: 'systemAppearanceChanged', callback: (args: SystemAppearanceChangedEventData) => void, thisArg?: any);
363
364export function on(event: 'fontScaleChanged', callback: (args: FontScaleChangedEventData) => void, thisArg?: any);
365
366/**
367 * Gets the orientation of the application.
368 * Available values: "portrait", "landscape", "unknown".
369 */
370export function orientation(): 'portrait' | 'landscape' | 'unknown';
371
372/**
373 * Gets the operating system appearance.
374 * Available values: "dark", "light", null.
375 * Null for iOS <= 11.
376 */
377export function systemAppearance(): 'dark' | 'light' | null;
378
379/**
380 * This is the Android-specific application object instance.
381 * Encapsulates methods and properties specific to the Android platform.
382 * Will be undefined when TargetOS is iOS.
383 */
384export let android: AndroidApplication;
385
386/**
387 * Used internally for backwards compatibility, will be removed in the future.
388 * Allowed Application.android.context to work (or Application.ios). Instead use Utils.android.getApplicationContext() or Utils.android.getPackageName()
389 * @internal
390 */
391export function ensureNativeApplication(): void;
392
393/**
394 * This is the iOS-specific application object instance.
395 * Encapsulates methods and properties specific to the iOS platform.
396 * Will be undefined when TargetOS is Android.
397 */
398export let ios: iOSApplication;
399
400/**
401 * Data for the Android activity events.
402 */
403export interface AndroidActivityEventData {
404 /**
405 * The activity.
406 */
407 activity: any /* androidx.appcompat.app.AppCompatActivity */;
408
409 /**
410 * The name of the event.
411 */
412 eventName: string;
413
414 /**
415 * The instance that has raised the event.
416 */
417 object: any;
418}
419
420/**
421 * Data for the Android activity events with bundle.
422 */
423export interface AndroidActivityBundleEventData extends AndroidActivityEventData {
424 /**
425 * The bundle.
426 */
427 bundle: any /* android.os.Bundle */;
428}
429
430/**
431 * Data for the Android activity onRequestPermissions callback
432 */
433export interface AndroidActivityRequestPermissionsEventData extends AndroidActivityEventData {
434 /**
435 * The request code.
436 */
437 requestCode: number;
438
439 /**
440 * The Permissions.
441 */
442 permissions: Array<string>;
443
444 /**
445 * The Granted.
446 */
447 grantResults: Array<number>;
448}
449
450/**
451 * Data for the Android activity result event.
452 */
453export interface AndroidActivityResultEventData extends AndroidActivityEventData {
454 /**
455 * The request code.
456 */
457 requestCode: number;
458
459 /**
460 * The result code.
461 */
462 resultCode: number;
463
464 /**
465 * The intent.
466 */
467 intent: any /* android.content.Intent */;
468}
469
470/**
471 * Data for the Android activity newIntent event.
472 */
473export interface AndroidActivityNewIntentEventData extends AndroidActivityEventData {
474 /**
475 * The intent.
476 */
477 intent: any /* android.content.Intent */;
478}
479
480/**
481 * Data for the Android activity back pressed event.
482 */
483export interface AndroidActivityBackPressedEventData extends AndroidActivityEventData {
484 /**
485 * In the event handler, set this value to true if you want to cancel the back navigation and do something else instead.
486 */
487 cancel: boolean;
488}
489
490/**
491 * The abstraction of an Android-specific application object.
492 */
493export class AndroidApplication extends Observable {
494 /**
495 * The [android Application](http://developer.android.com/reference/android/app/Application.html) object instance provided to the init of the module.
496 */
497 nativeApp: any /* android.app.Application */;
498
499 /**
500 * The application's [android Context](http://developer.android.com/reference/android/content/Context.html) object instance.
501 * @deprecated Use Utils.android.getApplicationContext() instead.
502 */
503 context: any /* android.content.Context */;
504
505 /**
506 * The currently active (loaded) [android Activity](http://developer.android.com/reference/android/app/Activity.html). This property is automatically updated upon Activity events.
507 */
508 foregroundActivity: any /* androidx.appcompat.app.AppCompatActivity */;
509
510 /**
511 * The main (start) Activity for the application.
512 */
513 startActivity: any /* androidx.appcompat.app.AppCompatActivity */;
514
515 /**
516 * Gets the orientation of the application.
517 * Available values: "portrait", "landscape", "unknown".
518 */
519 orientation: 'portrait' | 'landscape' | 'unknown';
520
521 /**
522 * Gets the system appearance.
523 * Available values: "dark", "light".
524 */
525 systemAppearance: 'dark' | 'light';
526
527 /**
528 * The name of the application package.
529 * @deprecated Use Utils.android.getPackageName() instead.
530 */
531 packageName: string;
532
533 /**
534 * True if the main application activity is not running (suspended), false otherwise.
535 */
536 paused: boolean;
537
538 /**
539 * True if the main application activity is in background, false otherwise.
540 */
541 backgrounded: boolean;
542
543 /**
544 * Initialized the android-specific application object with the native android.app.Application instance.
545 * This is useful when creating custom application types.
546 * @param nativeApp - the android.app.Application instance that started the app.
547 */
548 init: (nativeApp) => void;
549
550 /**
551 * A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
552 * @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
553 * @param callback - Callback function which will be executed when event is raised.
554 * @param thisArg - An optional parameter which will be used as `this` context for callback execution.
555 */
556 on(eventNames: string, callback: (data: AndroidActivityEventData) => void, thisArg?: any);
557
558 /**
559 * This event is raised on android application ActivityCreated.
560 */
561 on(event: 'activityCreated', callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any);
562
563 /**
564 * This event is raised on android application ActivityDestroyed.
565 */
566 on(event: 'activityDestroyed', callback: (args: AndroidActivityEventData) => void, thisArg?: any);
567
568 /**
569 * This event is raised on android application ActivityStarted.
570 */
571 on(event: 'activityStarted', callback: (args: AndroidActivityEventData) => void, thisArg?: any);
572
573 /**
574 * This event is raised on android application ActivityPaused.
575 */
576 on(event: 'activityPaused', callback: (args: AndroidActivityEventData) => void, thisArg?: any);
577
578 /**
579 * This event is raised on android application ActivityResumed.
580 */
581 on(event: 'activityResumed', callback: (args: AndroidActivityEventData) => void, thisArg?: any);
582
583 /**
584 * This event is raised on android application ActivityStopped.
585 */
586 on(event: 'activityStopped', callback: (args: AndroidActivityEventData) => void, thisArg?: any);
587
588 /**
589 * This event is raised on android application SaveActivityState.
590 */
591 on(event: 'saveActivityState', callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any);
592
593 /**
594 * This event is raised on android application ActivityResult.
595 */
596 on(event: 'activityResult', callback: (args: AndroidActivityResultEventData) => void, thisArg?: any);
597
598 /**
599 * This event is raised on the back button is pressed in an android application.
600 */
601 on(event: 'activityBackPressed', callback: (args: AndroidActivityBackPressedEventData) => void, thisArg?: any);
602
603 /**
604 * This event is raised when the Android app was launched by an Intent with data.
605 */
606 on(event: 'activityNewIntent', callback: (args: AndroidActivityNewIntentEventData) => void, thisArg?: any);
607
608 /**
609 * This event is raised when the Android activity requests permissions.
610 */
611 on(event: 'activityRequestPermissions', callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any);
612
613 /**
614 * String value used when hooking to activityCreated event.
615 */
616 public static activityCreatedEvent: string;
617
618 /**
619 * String value used when hooking to activityDestroyed event.
620 */
621 public static activityDestroyedEvent: string;
622
623 /**
624 * String value used when hooking to activityStarted event.
625 */
626 public static activityStartedEvent: string;
627
628 /**
629 * String value used when hooking to activityPaused event.
630 */
631 public static activityPausedEvent: string;
632
633 /**
634 * String value used when hooking to activityResumed event.
635 */
636 public static activityResumedEvent: string;
637
638 /**
639 * String value used when hooking to activityStopped event.
640 */
641 public static activityStoppedEvent: string;
642
643 /**
644 * String value used when hooking to saveActivityState event.
645 */
646 public static saveActivityStateEvent: string;
647
648 /**
649 * String value used when hooking to activityResult event.
650 */
651 public static activityResultEvent: string;
652
653 /**
654 * String value used when hooking to activityBackPressed event.
655 */
656 public static activityBackPressedEvent: string;
657
658 /**
659 * String value used when hooking to activityNewIntent event.
660 */
661 public static activityNewIntentEvent: string;
662
663 /**
664 * String value used when hooking to requestPermissions event.
665 */
666 public static activityRequestPermissionsEvent: string;
667
668 /**
669 * Get a registered BroadcastReceiver, then you can get the result code of BroadcastReceiver in onReceiveCallback method.
670 * @param intentFilter A string containing the intent filter.
671 */
672 public getRegisteredBroadcastReceiver(intentFilter: string): any; /* android.content.BroadcastReceiver */
673
674 /**
675 * 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.
676 * For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
677 * @param intentFilter A string containing the intent filter.
678 * @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
679 */
680 registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: any /* android.content.Context */, intent: any /* android.content.Intent */) => void): void;
681
682 /**
683 * Unregister a previously registered BroadcastReceiver.
684 * For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
685 * @param intentFilter A string containing the intent filter with which the receiver was originally registered.
686 */
687 unregisterBroadcastReceiver(intentFilter: string): void;
688}
689
690/* tslint:disable */
691/**
692 * The abstraction of an iOS-specific application object.
693 */
694export class iOSApplication {
695 /* tslint:enable */
696 /**
697 * The root view controller for the application.
698 */
699 rootController: any /* UIViewController */;
700
701 /* tslint:enable */
702 /**
703 * The key window.
704 */
705 window: any /* UIWindow */;
706
707 /**
708 * The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class.
709 */
710 delegate: any /* typeof UIApplicationDelegate */;
711
712 /**
713 * Gets or sets the orientation of the application.
714 * Available values: "portrait", "landscape", "unknown".
715 */
716 orientation: 'portrait' | 'landscape' | 'unknown';
717
718 /**
719 * Gets the system appearance.
720 * Available values: "dark", "light", null.
721 * Null for iOS <= 11.
722 */
723 systemAppearance: 'dark' | 'light' | null;
724
725 /**
726 * The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html).
727 */
728 nativeApp: any /* UIApplication */;
729
730 /**
731 * Adds an observer to the default notification center for the specified notification.
732 * 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:'
733 * @param notificationName A string containing the name of the notification.
734 * @param onReceiveCallback A callback function that will be called each time the observer receives a notification.
735 */
736 addNotificationObserver(notificationName: string, onReceiveCallback: (notification: any /* NSNotification */) => void): any;
737
738 /**
739 * Removes the observer for the specified notification from the default notification center.
740 * 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:'
741 * @param observer The observer that was returned from the addNotificationObserver method.
742 * @param notificationName A string containing the name of the notification.
743 * @param onReceiveCallback A callback function that will be called each time the observer receives a notification.
744 */
745 removeNotificationObserver(observer: any, notificationName: string): void;
746}
747
748/**
749 * @deprecated
750 */
751export interface RootViewControllerImpl {
752 contentController: any;
753}
754
755export function getNativeApplication(): any;
756
757/**
758 * Indicates if the application is allready launched. See also the `application.on("launch", handler)` event.
759 */
760export function hasLaunched(): boolean;
761
762export interface LoadAppCSSEventData extends EventData {
763 cssFile: string;
764}