You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/architecture.md
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,10 +135,17 @@ PythonNative provides cross-platform modules for common device APIs:
135
135
136
136
## Navigation model overview
137
137
138
-
- See the Navigation guide for full details.
139
-
- Navigation is handled via the `use_navigation()` hook, which returns a `NavigationHandle` with `.push()`, `.pop()`, and `.get_args()`.
140
-
- iOS: one host `UIViewController` class, many instances pushed on a `UINavigationController`.
141
-
- Android: single host `Activity` with a `NavHostFragment` and a stack of generic `PageFragment`s driven by a navigation graph.
138
+
PythonNative provides two navigation approaches:
139
+
140
+
-**Declarative navigators** (recommended): `NavigationContainer` with `create_stack_navigator()`, `create_tab_navigator()`, and `create_drawer_navigator()`. Navigation state is managed in Python as component state, and navigators are composable — you can nest tabs inside stacks, etc.
141
+
-**Page-level navigation**: `use_navigation()` returns a `NavigationHandle` with `.navigate()`, `.go_back()`, and `.get_params()`, delegating to native platform navigation when running on device.
142
+
143
+
Both approaches are supported. The declarative system uses the existing reconciler pipeline — navigators are function components that render the active screen via `use_state`, and navigation context is provided via `Provider`.
144
+
145
+
See the [Navigation guide](../guides/navigation.md) for full details.
146
+
147
+
- iOS: one host `UIViewController` class, many instances pushed on a `UINavigationController`.
148
+
- Android: single host `Activity` with a `NavHostFragment` and a stack of generic `PageFragment`s driven by a navigation graph.
This guide shows how to navigate between screens and pass data using the `use_navigation()` hook.
3
+
PythonNative offers two approaches to navigation:
4
4
5
-
## Push / Pop
5
+
1.**Declarative navigators** (recommended) — component-based, inspired by React Navigation
6
+
2.**Legacy push/pop** — imperative navigation via `use_navigation()`
6
7
7
-
Call `pn.use_navigation()` inside a `@pn.component` to get a `NavigationHandle`. Use `.push()` and `.pop()` to change screens, passing a component reference with optional `args`.
8
+
## Declarative Navigation
9
+
10
+
Declarative navigators manage screen state as components. Define your screens once, and the navigator handles rendering, transitions, and state.
11
+
12
+
### Stack Navigator
13
+
14
+
A stack navigator manages a stack of screens — push to go forward, pop to go back.
8
15
9
16
```python
10
17
import pythonnative as pn
11
-
from app.second_page import SecondPage
18
+
from pythonnative.navigation import NavigationContainer, create_stack_navigator
`pn.use_navigation()` returns a `NavigationHandle` with:
128
+
Inside any screen rendered by a navigator, `pn.use_navigation()` returns a handle with:
129
+
130
+
-**`.navigate(route_name, params=...)`** — navigate to a named route with optional params
131
+
-**`.go_back()`** — pop the current screen
132
+
-**`.get_params()`** — get the current route's params dict
133
+
-**`.reset(route_name, params=...)`** — reset the stack to a single route
134
+
135
+
### Drawer-specific methods
136
+
137
+
When inside a drawer navigator, the handle also provides:
138
+
139
+
-**`.open_drawer()`** — open the drawer
140
+
-**`.close_drawer()`** — close the drawer
141
+
-**`.toggle_drawer()`** — toggle the drawer open/closed
142
+
143
+
## Focus-aware Effects
47
144
48
-
-**`.push(component, args=...)`** — navigate to a new screen. Pass a component reference (the `@pn.component` function itself), with an optional `args` dict.
49
-
-**`.pop()`** — go back to the previous screen.
50
-
-**`.get_args()`** — retrieve the args dict passed by the caller.
145
+
Use `pn.use_focus_effect()` to run effects only when a screen is focused:
0 commit comments