FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnative/src/pythonnative/navigation/host.py at v0.43.1 · pythonnative/pythonnative · GitHub
pythonnative
pythonnative
Repository navigation
Code
Issues
11
(11)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
navigation
/
host.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (43 loc) · 2.31 KB
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
navigation
/
host.py
Copy path
File metadata and controls
58 lines (43 loc) · 2.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Bridge between the native screen host and the navigation tree.
The host wraps the app's root element in
[`HostRoot`][pythonnative.navigation.host.HostRoot], which publishes:
- [`HostContext`][pythonnative.navigation.host.HostContext]: the
[`HostNavigator`][pythonnative.navigation.HostNavigator] a root stack
uses to push and pop real native screens, and
- [`FocusContext`][pythonnative.navigation.handle.FocusContext]: whether
the host's screen is currently presented (``on_resume`` /
``on_pause``), so [`use_is_focused`][pythonnative.use_is_focused]
and [`use_focus_effect`][pythonnative.use_focus_effect] follow the
platform lifecycle even outside any declarative navigator.
Pushed screens receive their navigation history under the
``"pn_nav"`` key of the host's launch arguments; the root stack reads
it through ``HostNavigator.initial_navigation_state``.
"""
from
__future__
import
annotations
from
typing
import
Any
,
Dict
,
Optional
from
..
component
import
component
from
..
element
import
Element
,
Node
from
..
hooks
import
Context
,
create_context
,
use_effect
,
use_state
from
.
handle
import
FocusContext
,
HostNavigator
__all__
=
[
"HostContext"
,
"HostRoot"
,
"NAV_STATE_ARG"
]
NAV_STATE_ARG
=
"pn_nav"
"""Launch-argument key under which a pushed screen receives its serialized navigation state."""
HostContext
:
Context
[
Optional
[
HostNavigator
]]
=
create_context
(
None
,
name
=
"Host"
)
"""The native host bridging this tree, or ``None`` when rendering without one (tests, rows)."""
@
component
def
HostRoot
(
*
children
:
Node
,
host
:
HostNavigator
)
->
Element
:
"""Publish the host bridge and its focus state to the tree below."""
focused
,
set_focused
=
use_state
(
bool
(
getattr
(
host
,
"is_focused"
,
True
)))
def
subscribe
()
->
Any
:
set_focused
(
bool
(
getattr
(
host
,
"is_focused"
,
True
)))
return
host
.
add_focus_listener
(
lambda
value
:
set_focused
(
bool
(
value
)))
use_effect
(
subscribe
, [
host
])
return
HostContext
.
Provider
(
host
,
FocusContext
.
Provider
(
focused
,
*
children
))
def
initial_state_from_args
(
args
:
Optional
[
Dict
[
str
,
Any
]])
->
Optional
[
Dict
[
str
,
Any
]]:
"""Extract a serialized navigation state from host launch arguments."""
if
not
isinstance
(
args
,
dict
):
return
None
state
=
args
.
get
(
NAV_STATE_ARG
)
if
isinstance
(
state
,
dict
)
and
state
.
get
(
"routes"
):
return
state
return
None
Back
|
FazBrowse Home
|
New Git URL