UNPKG

16.1 kBTypeScriptView Raw
1import { NavigationType, FrameBase } from './frame-common';
2import { NavigatedData, Page } from '../page';
3import { Observable, EventData } from '../../data/observable';
4import { View } from '../core/view';
5import { Transition } from '../transition';
6
7export * from './frame-interfaces';
8
9export interface NavigationData extends EventData {
10 entry?: NavigationEntry;
11 fromEntry?: NavigationEntry;
12 isBack?: boolean;
13}
14
15/**
16 * Represents the logical View unit that is responsible for navigation within an application.
17 * Nested frames are supported, enabling hierarchical navigation scenarios.
18 */
19export class Frame extends FrameBase {
20 /**
21 * String value used when hooking to navigatingTo event.
22 */
23 public static readonly navigatingToEvent = 'navigatingTo';
24
25 /**
26 * String value used when hooking to navigatedTo event.
27 */
28 public static readonly navigatedToEvent = 'navigatedTo';
29
30 /**
31 * @private
32 */
33 _originalBackground?: any;
34
35 /**
36 * @private
37 */
38 _saveFragmentsState?();
39
40 /**
41 * Gets a frame by id.
42 */
43 static getFrameById(id: string): Frame;
44
45 /**
46 * Gets the topmost frame in the frames stack. An application will typically has one frame instance. Multiple frames handle nested (hierarchical) navigation scenarios.
47 */
48 static topmost(): Frame;
49
50 /**
51 * Navigates back using the navigation hierarchy (if any). Updates the Frame stack as needed.
52 * This method will start from the topmost Frame and will recursively search for an instance that has the canGoBack operation available.
53 */
54 static goBack();
55
56 /**
57 * @private
58 */
59 static reloadPage(context?: ModuleContext): void;
60
61 /**
62 * @private
63 */
64 static _stack(): Array<Frame>;
65
66 /**
67 * Navigates to the previous entry (if any) in the back stack.
68 * @param to The backstack entry to navigate back to.
69 */
70 goBack(to?: BackstackEntry);
71
72 /**
73 * Checks whether the goBack operation is available.
74 */
75 canGoBack(): boolean;
76
77 /**
78 * Navigates to a Page instance as described by the module name.
79 * This method will require the module and will check for a Page property in the exports of the module.
80 * @param pageModuleName The name of the module to require starting from the application root.
81 * For example if you want to navigate to page called "myPage.js" in a folder called "subFolder" and your root folder is "app" you can call navigate method like this:
82 * const frames = require("&#64;nativescript/core/ui/frame");
83 * frames.topmost().navigate("app/subFolder/myPage");
84 */
85 navigate(pageModuleName: string);
86
87 /**
88 * Creates a new Page instance using the provided callback and navigates to that Page.
89 * @param create The function to be used to create the new Page instance.
90 */
91 navigate(create: () => Page);
92
93 /**
94 * Navigates to a Page resolved by the provided NavigationEntry object.
95 * Since there are a couple of ways to specify a Page instance through an entry, there is a resolution priority:
96 * 1. entry.moduleName
97 * 2. entry.create()
98 * @param entry The NavigationEntry instance.
99 */
100 navigate(entry: NavigationEntry);
101
102 /**
103 * Used to control the visibility the Navigation Bar in iOS and the Action Bar in Android.
104 */
105 public actionBarVisibility: 'auto' | 'never' | 'always';
106
107 /**
108 * Gets the back stack of this instance.
109 */
110 // @ts-ignore
111 backStack: Array<BackstackEntry>;
112
113 /**
114 * Gets the Page instance the Frame is currently navigated to.
115 */
116 // @ts-ignore
117 currentPage: Page;
118
119 /**
120 * Gets the NavigationEntry instance the Frame is currently navigated to.
121 */
122 // @ts-ignore
123 currentEntry: NavigationEntry;
124
125 /**
126 * Gets or sets if navigation transitions should be animated.
127 */
128 // @ts-ignore
129 animated: boolean;
130
131 /**
132 * Gets or sets the default navigation transition for this frame.
133 */
134 // @ts-ignore
135 transition: NavigationTransition;
136
137 /**
138 * Gets or sets if navigation transitions should be animated globally.
139 */
140 static defaultAnimatedNavigation: boolean;
141
142 /**
143 * Gets or sets the default NavigationTransition for all frames across the app.
144 */
145 static defaultTransition: NavigationTransition;
146
147 /**
148 * Gets the AndroidFrame object that represents the Android-specific APIs for this Frame. Valid when running on Android OS.
149 */
150 android: AndroidFrame;
151
152 /**
153 * Gets the iOSFrame object that represents the iOS-specific APIs for this Frame. Valid when running on iOS.
154 */
155 ios: iOSFrame;
156
157 /**
158 * Specify a custom UINavigationBar class (iOS only)
159 */
160 iosNavigationBarClass: any;
161 /**
162 * Specify a custom UIToolbar class (iOS only)
163 */
164 iosToolBarClass: any;
165
166 //@private
167 /**
168 * @private
169 * @param entry to check
170 */
171 isCurrent(entry: BackstackEntry): boolean;
172
173 /**
174 * @private
175 * @param entry to set as current
176 * @param navigationType
177 */
178 setCurrent(entry: BackstackEntry, navigationType: NavigationType): void;
179 /**
180 * @private
181 */
182 navigationQueueIsEmpty(): boolean;
183 /**
184 * @private
185 */
186 // @ts-ignore
187 navigationBarHeight: number;
188 /**
189 * @private
190 */
191 _animationInProgress: boolean;
192 /**
193 * @private
194 */
195 _currentEntry: BackstackEntry;
196 /**
197 * @private
198 */
199 _executingContext: NavigationContext;
200 /**
201 * @private
202 */
203 _processNavigationQueue(page: Page);
204 /**
205 * @private
206 */
207 _getIsAnimatedNavigation(entry: NavigationEntry): boolean;
208 /**
209 * @private
210 */
211 _getNavigationTransition(entry: NavigationEntry): NavigationTransition;
212 /**
213 * @private
214 */
215 _updateActionBar(page?: Page, disableNavBarAnimation?: boolean);
216 /**
217 * @private
218 * @param navigationContext
219 */
220 public performNavigation(navigationContext: NavigationContext): void;
221 /**
222 * @private
223 */
224 _getNavBarVisible(page: Page): boolean;
225 /**
226 * @private
227 */
228 _findEntryForTag(fragmentTag: string): BackstackEntry;
229 /**
230 * @private
231 */
232 _updateBackstack(entry: BackstackEntry, navigationType: NavigationType): void;
233 /**
234 * @private
235 */
236 _pushInFrameStack();
237 /**
238 * @private
239 */
240 _pushInFrameStackRecursive();
241 /**
242 * @private
243 */
244 _removeFromFrameStack();
245 //@endprivate
246
247 /**
248 * Adds a listener for the specified event name.
249 *
250 * @param eventName The name of the event.
251 * @param callback The event listener to add. Will be called when an event of
252 * the given name is raised.
253 * @param thisArg An optional parameter which, when set, will be bound as the
254 * `this` context when the callback is called. Falsy values will be not be
255 * bound.
256 */
257 on(eventName: string, callback: (args: EventData) => void, thisArg?: any): void;
258
259 /**
260 * Raised when navigation to the page has started.
261 */
262 public on(event: 'navigatingTo', callback: (args: NavigationData) => void, thisArg?: any): void;
263
264 /**
265 * Raised when navigation to the page has finished.
266 */
267 public on(event: 'navigatedTo', callback: (args: NavigationData) => void, thisArg?: any): void;
268}
269
270/**
271 * Sets the extended androidx.fragment.app.Fragment class to the Frame and navigation routine. An instance of this class will be created to represent the Page currently visible on the srceen. This method is available only for the Android platform.
272 */
273export function setFragmentClass(clazz: any): void;
274
275/**
276 * @deprecated Use Frame.getFrameById() instead.
277 *
278 * Gets a frame by id.
279 */
280export function getFrameById(id: string): Frame;
281
282/**
283 *
284 * (Android Only) Gets a frame by internally tracked id.
285 */
286export function getFrameByNumberId(frameId: number): Frame;
287
288/**
289 * @deprecated Use Frame.topmost() instead.
290 *
291 * Gets the topmost frame in the frames stack. An application will typically has one frame instance. Multiple frames handle nested (hierarchical) navigation scenarios.
292 */
293export function topmost(): Frame;
294
295/**
296 * @deprecated Use Frame.goBack() instead.
297 *
298 * Navigates back using the navigation hierarchy (if any). Updates the Frame stack as needed.
299 * This method will start from the topmost Frame and will recursively search for an instance that has the canGoBack operation available.
300 */
301export function goBack();
302
303//@private
304/**
305 * @deprecated Use Frame._stack() instead.
306 *
307 * @private
308 */
309export function _stack(): Array<Frame>;
310//@endprivate
311
312/**
313 * Represents an entry to be used to create a view or load it form file
314 */
315export interface ViewEntry {
316 /**
317 * The name of the module containing the View instance to load. Optional.
318 */
319 moduleName?: string;
320
321 /**
322 * A function used to create the View instance. Optional.
323 */
324 create?: () => View;
325}
326/**
327 * Represents an entry in passed to navigate method.
328 */
329export interface NavigationEntry extends ViewEntry {
330 /**
331 * An object passed to the onNavigatedTo callback of the Page. Typically this is used to pass some data among pages. Optional.
332 */
333 context?: any;
334
335 /**
336 * An object to become the binding context of the page navigating to. Optional.
337 */
338 bindingContext?: any;
339
340 /**
341 * True to navigate to the new Page using animated transitions, false otherwise.
342 */
343 animated?: boolean;
344
345 /**
346 * Specifies an optional navigation transition for all platforms. If not specified, the default platform transition will be used.
347 */
348 transition?: NavigationTransition;
349
350 /**
351 * Specifies an optional navigation transition for iOS. If not specified, the default platform transition will be used.
352 */
353 transitioniOS?: NavigationTransition;
354
355 /**
356 * Specifies an optional navigation transition for Android. If not specified, the default platform transition will be used.
357 */
358 transitionAndroid?: NavigationTransition;
359
360 /**
361 * True to record the navigation in the backstack, false otherwise.
362 * If the parameter is set to false then the Page will be displayed but once navigated from it will not be able to be navigated back to.
363 */
364 backstackVisible?: boolean;
365
366 /**
367 * True to clear the navigation history, false otherwise. Very useful when navigating away from login pages.
368 */
369 clearHistory?: boolean;
370}
371
372/**
373 * Represents a context passed to navigation methods.
374 */
375export interface NavigationContext {
376 entry: BackstackEntry;
377 isBackNavigation: boolean;
378 navigationType: NavigationType;
379}
380
381/**
382 * Represents an object specifying a page navigation transition.
383 */
384export interface NavigationTransition {
385 /**
386 * Can be one of the built-in transitions:
387 * - curl (same as curlUp) (iOS only)
388 * - curlUp (iOS only)
389 * - curlDown (iOS only)
390 * - explode (Android Lollipop(21) and up only)
391 * - fade
392 * - flip (same as flipRight)
393 * - flipRight
394 * - flipLeft
395 * - slide (same as slideLeft)
396 * - slideLeft
397 * - slideRight
398 * - slideTop
399 * - slideBottom
400 */
401 name?: string;
402
403 /**
404 * An user-defined instance of the "ui/transition".Transition class.
405 */
406 instance?: Transition;
407
408 /**
409 * The length of the transition in milliseconds. If you do not specify this, the default platform transition duration will be used.
410 */
411 duration?: number;
412
413 /**
414 * An optional transition animation curve. Possible values are contained in the [AnimationCurve enumeration](https://docs.nativescript.org/api-reference/modules/_ui_enums_.animationcurve.html).
415 * Alternatively, you can pass an instance of type UIViewAnimationCurve for iOS or android.animation.TimeInterpolator for Android.
416 */
417 curve?: any;
418}
419
420/**
421 * Represents an entry in the back stack of a Frame object.
422 */
423export interface BackstackEntry {
424 entry: NavigationEntry;
425 resolvedPage: Page;
426
427 //@private
428 /**
429 * @private
430 */
431 navDepth: number;
432 /**
433 * @private
434 */
435 fragmentTag: string;
436 /**
437 * @private
438 */
439 fragment?: any;
440 /**
441 * @private
442 */
443 viewSavedState?: any;
444 /**
445 * @private
446 */
447 frameId?: number;
448 /**
449 * @private
450 */
451 recreated?: boolean;
452 //@endprivate
453}
454
455/**
456 * Represents the Android-specific Frame object, aggregated within the common Frame one.
457 * In Android there are two types of navigation - using new Activity instances or using Fragments within the main Activity.
458 * To start a new Activity, a new Frame instance should be created and navigated to the desired Page.
459 */
460export interface AndroidFrame extends Observable {
461 frameId?: any;
462
463 /**
464 * Gets the native [android ViewGroup](http://developer.android.com/reference/android/view/ViewGroup.html) instance that represents the root layout part of the Frame.
465 */
466 rootViewGroup: any /* android.view.ViewGroup */;
467
468 /**
469 * Gets the native [android Activity](http://developer.android.com/reference/android/app/Activity.html) instance associated with this Frame. In case of nested Frame objects, this property points to the activity of the root Frame.
470 */
471 activity: any /* androidx.appcompat.app.AppCompatActivity */;
472
473 /**
474 * Gets the current (foreground) activity for the application. This property will recursively traverse all existing Frame objects and check for own Activity property.
475 */
476 currentActivity: any /* androidx.appcompat.app.AppCompatActivity */;
477
478 /**
479 * Gets the actionBar property of the currentActivity.
480 */
481 actionBar: any /* android.app.ActionBar */;
482
483 /**
484 * Determines whether the Activity associated with this Frame will display an action bar or not.
485 */
486 showActionBar: boolean;
487
488 /**
489 * Finds the native androidx.fragment.app.Fragment instance created for the specified Page.
490 * @param page The Page instance to search for.
491 */
492 fragmentForPage(entry: BackstackEntry): any;
493}
494
495export interface AndroidActivityCallbacks {
496 getRootView(): View;
497 resetActivityContent(activity: any): void;
498
499 onCreate(activity: any, savedInstanceState: any, intent: any, superFunc: Function): void;
500 onSaveInstanceState(activity: any, outState: any, superFunc: Function): void;
501 onStart(activity: any, superFunc: Function): void;
502 onStop(activity: any, superFunc: Function): void;
503 onPostResume(activity: any, superFunc: Function): void;
504 onDestroy(activity: any, superFunc: Function): void;
505 onBackPressed(activity: any, superFunc: Function): void;
506 onRequestPermissionsResult(activity: any, requestCode: number, permissions: Array<string>, grantResults: Array<number>, superFunc: Function): void;
507 onActivityResult(activity: any, requestCode: number, resultCode: number, data: any, superFunc: Function);
508 onNewIntent(activity: any, intent: any, superSetIntentFunc: Function, superFunc: Function): void;
509}
510
511export interface AndroidFragmentCallbacks {
512 onHiddenChanged(fragment: any, hidden: boolean, superFunc: Function): void;
513 onCreateAnimator(fragment: any, transit: number, enter: boolean, nextAnim: number, superFunc: Function): any;
514 onCreate(fragment: any, savedInstanceState: any, superFunc: Function): void;
515 onCreateView(fragment: any, inflater: any, container: any, savedInstanceState: any, superFunc: Function): any;
516 onSaveInstanceState(fragment: any, outState: any, superFunc: Function): void;
517 onDestroyView(fragment: any, superFunc: Function): void;
518 onDestroy(fragment: any, superFunc: Function): void;
519 onPause(fragment: any, superFunc: Function): void;
520 onResume(fragment: any, superFunc: Function): void;
521 onStop(fragment: any, superFunc: Function): void;
522 toStringOverride(fragment: any, superFunc: Function): string;
523}
524
525/* tslint:disable */
526/**
527 * Represents the iOS-specific Frame object, aggregated within the common Frame one.
528 * In iOS the native controller, associated with a Frame object is UINavigationController.
529 * The navigation controller will automatically hide/show its navigation bar depending on the back stack of the Frame.
530 */
531export interface iOSFrame {
532 /**
533 * Gets the native [UINavigationController](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html) instance associated with this Frame.
534 */
535 controller: any /* UINavigationController */;
536
537 /**
538 * Gets or sets the visibility of navigationBar.
539 * Use NavBarVisibility enumeration - auto, never, always
540 */
541 navBarVisibility: 'auto' | 'never' | 'always';
542
543 //@private
544 /**
545 * @private
546 */
547 _disableNavBarAnimation: boolean;
548 //@endprivate
549}
550
551export function setActivityCallbacks(activity: any /*androidx.appcompat.app.AppCompatActivity*/): void;
552//@private
553/**
554 * @deprecated Use Frame.reloadPage() instead.
555 *
556 * @private
557 */
558export function reloadPage(context?: ModuleContext): void;
559/**
560 * @private
561 */
562export function setFragmentCallbacks(fragment: any /*androidx.fragment.app.Fragment*/): void;
563//@endprivate