Skip to content

Commit c60ad26

Browse files
committed
docs: cleaning up navigation via frame/page [wip]
1 parent 2370e03 commit c60ad26

File tree

2 files changed

+191
-285
lines changed

2 files changed

+191
-285
lines changed
Lines changed: 37 additions & 282 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
---
22
title: Navigation using Frames and Pages
3-
description: Navigate from screen to screen in your app.
3+
description: Navigate between Pages in your app.
44
---
5-
<!--TODO: Add Preview -->
6-
<!--TODO: Add flavors -->
75

86
Navigation in NativeScript is enabled by the `Frame` class.
97

10-
## How to use the Frame class
11-
12-
The following sections will show you how to access an instance of the Frame class and use it to navigate between pages in your app.
13-
8+
## Examples
149

1510
### Navigating to another page
1611

17-
To navigate from one `Page` to another, first obtain the desired [Frame instance](#getting-a-frame-instance).
12+
To navigate from one `Page` to another, first obtain the desired [Frame instance](#getting-a-frame-instance).
1813
For simple navigation, call the [navigate](#navigate) method passing along the path of the page to navigate to.
1914

2015
```ts
21-
frame.navigate("~/pages/details/details-page")
16+
frame.navigate('~/pages/details/details-page')
2217
```
2318

2419
:::tip Note
@@ -27,66 +22,76 @@ For a complete navigation example, have a look at [Setup navigation from home to
2722

2823
### Getting a Frame instance
2924

30-
The following are some of the ways in which to obtain a Frame:
25+
The following are some of the ways in which to obtain a Frame instance.
3126

32-
1. Calling the static [topmost](#topmost)
27+
#### Getting the topmost frame
3328

3429
```ts
35-
const frame = Frame.topmost();
30+
import { Frame } from '@nativescript/core'
31+
32+
const frame = Frame.topmost()
3633
```
37-
2. Via the `frame` property of a [Page](/ui/page)
34+
35+
#### Getting the frame from a Page
3836

3937
For example, you can get the current Frame instance from a `tap` event's data as follows:
4038

4139
```ts
4240
onFlickTap(args: EventData): void {
43-
const btn = args.object as Button;
44-
const frame = btn.page.frame
41+
const button = args.object as Button;
42+
const frame = button.page.frame;
4543
}
4644
```
47-
1. Calling the static [getFrameById](#getframebyid) with the id of the frame instance of interest
45+
46+
#### Getting a frame by id
4847

4948
```ts
50-
const frame = Frame.getFrameById("frame-id")
49+
import { Frame } from '@nativescript/core'
50+
51+
const frame = Frame.getFrameById('frame-id')
5152
```
5253

5354
### Navigating back
5455

5556
To navigate back to the previous page, use the [goBack](#goback) method of the Frame instance.
57+
5658
```ts
5759
frame.goBack()
5860
```
5961

6062
### Avoid navigating back to the previous page
6163

62-
To avoid navigating to the previous page, set the [clearHistory](#clearhistory) property of the [NavigationEntry](#navigation-entry-interface) object that you pass to the [navigate](#navigate) method to `true`.
64+
To avoid navigating to the previous page, set the [clearHistory](#clearhistory) property of the [NavigationEntry](#navigation-entry-interface) object that you pass to the [navigate](#navigate) method to `true`.
6365

6466
```ts
6567
frame.navigate({
66-
moduleName: "details/details-page",
67-
clearHistory: true
68+
moduleName: 'details/details-page',
69+
clearHistory: true,
6870
})
6971
```
72+
7073
### Passing data between pages
7174

7275
To pass data to the page you are navigating to, set the value of the [context](#context) property of the NavigationEntry to the data you would like to pass.
76+
7377
```ts
7478
frame.navigate({
75-
moduleName: "details/details-page",
76-
context: { id: 2 }
79+
moduleName: 'details/details-page',
80+
context: { id: 2 },
7781
})
7882
```
7983

8084
To access the passed data, handle the `navigatedTo` event for the `details/details-page` page and access the `context` property on the event's [NavigatedData](https://docs.nativescript.org/api-reference/interfaces/navigateddata) object.
8185

8286
```ts
83-
import { NavigatedData } from "@nativescript/core"
87+
import { NavigatedData } from '@nativescript/core'
8488

85-
onNavigatedTo(args: NavigatedData) {
86-
this.id = args.context.id
87-
this.notifyPropertyChange("id", args.context.id)
88-
}
89+
export function onNavigatedTo(args: NavigatedData) {
90+
this.id = args.context.id
91+
this.notifyPropertyChange('id', args.context.id)
92+
}
8993
```
94+
9095
### Creating multiple frames
9196

9297
If you need to create multiple frames, you can do so by wrapping them in a container layout. For example if you want to have 2 frames side-by-side, you can wrap them in a GridLayout:
@@ -97,260 +102,10 @@ If you need to create multiple frames, you can do so by wrapping them in a conta
97102
<Frame col="1" />
98103
</GridLayout>
99104
```
100-
## Frame class API
101-
102-
The following are the properties and methods of the Frame class:
103-
104-
### defaultAnimatedNavigation
105-
106-
```ts
107-
Frame.defaultAnimatedNavigation = true
108-
```
109-
110-
Gets or sets if navigation transitions should be animated globally.
111-
112-
---
113-
### defaultTransition
114-
```ts
115-
const defaultTransition: NavigationTransition = {
116-
curve: CoreTypes.AnimationCurve.easeInOut,
117-
duration: 500,
118-
name: "slideRight"
119-
}
120-
Frame.defaultTransition = defaultTransition
121-
//or
122-
const defaultTransition: NavigationTransition = Frame.defaultTransition
123-
124-
```
125-
Gets or sets the default [NavigationTransition](#navigation-transition-interface) for all frames across the app. To set a naviagation transtion for a specific frame instance, use the [transition](#transition) property.
126-
127-
---
128-
129-
### backStack
130-
```ts
131-
const backStack: Array<BackstackEntry> = frame.backStack
132-
```
133-
Gets the back stack for a Frame instance. It is empty if the current page is the app's initial page(eg `main-page`) or if the [clearHistory](#clearhistory) property is set to `true`.
134-
135-
---
136-
### currentPage
137-
```ts
138-
const page: Page = frame.currentPage
139-
```
140-
Gets the Page instance the Frame is currently navigated to.
141-
142-
---
143-
### currentEntry
144-
```ts
145-
const currentEntry: NavigationEntry = frame.currentEntry
146-
```
147-
Gets the NavigationEntry instance the Frame is currently navigated to.
148-
149-
---
150-
### animated
151-
```ts
152-
const animated: boolean = frame.animated.
153-
//or
154-
frame.animated = true
155-
```
156-
Gets or sets if navigation transitions should be animated.
157-
158-
---
159-
### transition
160-
```ts
161-
const transtion: NavigationTransition = frame.transition
162-
//or
163-
frame.transition = {
164-
curve: CoreTypes.AnimationCurve.easeInOut,
165-
duration: 500,
166-
name: "slideRight",
167-
}
168-
```
169-
Gets or sets the default [navigation transition](#navigation-transition-interface) for this frame.
170-
171-
---
172-
### actionBarVisibility
173-
```ts
174-
frame.actionBarVisibility = "never"
175-
```
176-
177-
It controls the visibility of an actionbar across all the pages in a Frame instance.
178-
Available values:
179-
- `auto`
180-
- `always`
181-
- `never` (hides the action bar for all pages)
182-
183-
---
184-
### navigate()
185-
This method has the following overloads:
186-
- `navigate(pageFileName: string)` - navigates to the page instance in the specified file.
187-
- `navigate(create: () => Page)` - creates a new Page instance using the provided callback and navigates to that instance.
188-
189-
- `navigate(entry: NavigationEntry)` is for a more customized navigation. It allows you to pass data to another page or set transition animation, etc.
190-
191-
### goBack()
192-
193-
```ts
194-
frame.goBack(to)
195-
```
196-
Navigates back using the navigation stack within a Frame.
197-
- _Optional_ `to`: The back stack entry object for where to navigate back to. The object has the following properties:
198-
199-
- `entry`(type: [NavigationEntry](#navigation-entry-interface))
200-
201-
- (`resolvedPage`)(type: Page)
202-
203-
---
204-
### getFrameById()
205-
```ts
206-
const frame = Frame.getFrameById(id: string)
207-
```
208-
Gets a frame with the specified id.
209-
210-
---
211105

212-
### topmost()
213-
```ts
214-
const frame = Frame.topmost()
215-
```
216-
Gets the topmost frame in the frames stack.
217-
218-
---
219-
220-
### canGoBack()
221-
```ts
222-
const canGoBack = frame.canGoBack()
223-
```
224-
Checks whether the goBack operation is available.
225-
226-
---
227-
## Navigation Transition Interface
228-
The Navigation Transition interface has the following members:
229-
230-
### name
231-
```ts
232-
{
233-
name: "slideLeft"
234-
}
235-
```
236-
The type of the transition. Possible values:
237-
238-
- `curl` (same as curlUp) (iOS only)
239-
- `curlUp` (iOS only)
240-
- `curlDown` (iOS only)
241-
- `explode` (Android Lollipop(21) and up only)
242-
- `fade`
243-
- `flip` (same as flipRight)
244-
- `flipRight`
245-
- `flipLeft`
246-
- `slide` (same as slideLeft)
247-
- `slideLeft`
248-
- `slideRight`
249-
- `slideTop`
250-
- `slideBottom`
251-
---
252-
253-
### custom transition
254-
```ts
255-
{
256-
instance: customTransitionInstance
257-
}
258-
```
259-
This property allows you to define custom transition instance of the [Transition](https://docs.nativescript.org/api-reference/classes/transition) class.
260-
261-
---
262-
263-
### duration
264-
```ts
265-
{
266-
duration: 500
267-
}
268-
```
269-
The length of the transition in milliseconds
270-
271-
---
272-
### curve
273-
```ts
274-
import { CoreTypes } from "@nativescript/core";
275-
276-
{
277-
curve: CoreTypes.AnimationCurve.easeInOut,
278-
}
279-
```
280-
A transition animation curve with available values contained in the [AnimationCurve enumeration](https://docs.nativescript.org/api-reference/modules/coretypes.animationcurve).
281-
Alternatively, you can pass an instance of type [UIViewAnimationCurve](https://developer.apple.com/documentation/uikit/uiview/animationcurve) for iOS or [android.animation.TimeInterpolator](https://developer.android.com/reference/android/animation/TimeInterpolator) for Android.
282-
283-
---
284-
285-
## Navigation Entry Interface
286-
287-
### moduleName
288-
```ts
289-
{
290-
moduleName: "details/details-page"
291-
}
292-
```
293-
The name of the page (a View instance) to navigate to.
294-
295-
---
296-
### create()
297-
```ts
298-
{
299-
create() {
300-
const page = new Page()
301-
const actionBar = new ActionBar()
302-
actionBar.title = "Test heading"
303-
304-
const stack = new StackLayout()
305-
stack.backgroundColor = "#76ABEB"
306-
307-
page.actionBar = actionBar;
308-
page.content = stack
309-
return page
310-
},
311-
}
312-
```
313-
Creates a the page(View instance) to be navigated to
314-
315-
---
316-
### context
317-
```ts
318-
{
319-
context: any
320-
}
321-
```
322-
An object used to pass data to the page navigated to.
323-
324-
---
325-
326-
### transitionAndroid
327-
328-
_Optional_: Specifies a navigation transition for Android. This property has a higher priority than the [transition](#transition) property.
329-
330-
---
331-
### transitioniOS
332-
333-
_Optional_: Specifies a navigation transition for iOS. This property has a higher priority than the [transition](#transition) property.
334-
335-
---
336-
### backstackVisible
337-
```ts
338-
frame.backstackVisible = true
339-
```
340-
341-
A boolean value, if set to `true`, it records the navigation in the backstack. If set to `false`, the Page will be displayed but once navigated from it is not possible to navigate back.
342-
343-
---
344-
### clearHistory
345-
```ts
346-
{
347-
clearHistory: true
348-
}
349-
```
350-
If set to `true`, it clears the navigation history. This very useful when navigating away from a login page.
106+
## See also
351107

352-
## API Reference(s)
353-
- [Frame](https://docs.nativescript.org/api-reference/classes/frame) class
354-
## Native Component
355-
- `Android`: [org.nativescript.widgets.ContentLayout](https://github.com/NativeScript/NativeScript/blob/master/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/ContentLayout.java)
356-
- `iOS`: [UINavigationController](https://developer.apple.com/documentation/uikit/uinavigationcontroller)
108+
- [UI Components › Frame](/ui/frame)
109+
- [UI Components › Page](/ui/page)
110+
- [API Reference › Frame](/api/class/Frame)
111+
- [API Reference › Page](/api/class/Page)

0 commit comments

Comments
 (0)