FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnative/src/pythonnative/navigation/screen.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
/
screen.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
143 lines (125 loc) · 6.12 KB
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
navigation
/
screen.py
Copy path
File metadata and controls
143 lines (125 loc) · 6.12 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""Screen definitions and the typed options a screen accepts."""
from
__future__
import
annotations
from
typing
import
Any
,
Callable
,
Dict
,
Literal
,
Mapping
,
Optional
,
TypedDict
,
Union
,
Unpack
from
..
element
import
Element
__all__
=
[
"HeaderSlot"
,
"ScreenDef"
,
"ScreenOptions"
,
"Unpack"
]
HeaderSlot
=
Union
[
Element
,
Callable
[[],
Optional
[
Element
]],
None
]
"""An element (or zero-arg factory) rendered into a header slot."""
class
ScreenOptions
(
TypedDict
,
total
=
False
):
"""Per-screen options accepted by ``Screen(...)`` and ``nav.set_options(...)``.
All keys are optional. Navigators ignore keys they don't use; the
native host applies the header keys it can (see the platform notes
on each key).
Attributes:
title: Screen title. Stack navigators show it in the native
navigation bar; tab and drawer navigators use it as the item
label.
header_shown: Whether the native navigation bar is visible for
this screen (default ``True``).
header_large_title: iOS: use a large title that collapses on
scroll. Ignored elsewhere.
header_back_title: iOS: label of the back button shown on the
*next* screen when it navigates back to this one. Ignored
elsewhere.
header_back_visible: Whether the back button is shown
(default ``True``).
header_left: Element (or factory) rendered at the leading edge
of the navigation bar. Rendered by PythonNative into the bar
on iOS; ignored on Android and in the browser preview today.
header_right: Element (or factory) rendered at the trailing edge
of the navigation bar (same platform notes as
``header_left``).
header_tint_color: Color of the bar's buttons and back chevron.
header_style: Style dict for the bar itself; ``background_color``
is honored on every platform that draws a bar.
header_title_style: Style dict for the title label
(``color``, ``font_size``, ``bold``).
presentation: ``"card"`` (default) pushes; ``"modal"`` presents
the screen as a sheet on iOS and as a full-screen push
elsewhere.
gesture_enabled: Whether the interactive back gesture (iOS
swipe) can pop this screen (default ``True``).
animation: Transition to use when the screen is pushed:
``"default"``, ``"none"``, ``"fade"``, ``"slide_from_right"``,
``"slide_from_bottom"``. Only ``"none"`` versus animated is
distinguished on iOS and Android today.
tab_bar_icon: Native system icon identifier for tab items. A
string is used on every platform; a dict like
``{"ios": "house.fill", "android": "ic_menu_home"}`` selects
per platform (SF Symbols on iOS, ``android.R.drawable.<name>``
on Android).
tab_bar_badge: Badge text or count shown on the tab item.
tab_bar_label: Label used for the tab item when it should differ
from ``title``.
lazy: Tab and drawer navigators only: mount the screen the first
time it's focused (default ``True``) instead of at
navigator mount.
unmount_on_blur: Tab and drawer navigators only: unmount the
screen when it loses focus instead of keeping it alive
hidden (default ``False``).
"""
title
:
str
header_shown
:
bool
header_large_title
:
bool
header_back_title
:
str
header_back_visible
:
bool
header_left
:
HeaderSlot
header_right
:
HeaderSlot
header_tint_color
:
str
header_style
:
Dict
[
str
,
Any
]
header_title_style
:
Dict
[
str
,
Any
]
presentation
:
Literal
[
"card"
,
"modal"
]
gesture_enabled
:
bool
animation
:
Literal
[
"default"
,
"none"
,
"fade"
,
"slide_from_right"
,
"slide_from_bottom"
]
tab_bar_icon
:
Union
[
str
,
Dict
[
str
,
str
]]
tab_bar_badge
:
Union
[
str
,
int
]
tab_bar_label
:
str
lazy
:
bool
unmount_on_blur
:
bool
class
ScreenDef
:
"""Configuration for one screen inside a navigator.
Created by ``Navigator.Screen(name, component, **options)``.
Attributes:
name: Route name used by ``nav.navigate(name)``.
component: The ``@component`` rendered when this screen is
active. Receives no props; read params with
[`use_route`][pythonnative.use_route].
options: Static [`ScreenOptions`][pythonnative.ScreenOptions]
for the screen. May be a callable ``(route) -> options`` to
derive options from the route's params.
initial_params: Params merged under any params supplied by
``navigate`` when this screen is first shown.
"""
__slots__
=
(
"name"
,
"component"
,
"options"
,
"initial_params"
)
def
__init__
(
self
,
name
:
str
,
component
:
Callable
[[],
Any
],
*
,
options
:
Union
[
ScreenOptions
,
Callable
[[
Any
],
ScreenOptions
],
None
]
=
None
,
initial_params
:
Optional
[
Mapping
[
str
,
Any
]]
=
None
,
**
option_kwargs
:
Unpack
[
ScreenOptions
],
)
->
None
:
if
not
name
or
not
isinstance
(
name
,
str
):
raise
TypeError
(
"Screen name must be a non-empty string"
)
if
not
callable
(
component
):
raise
TypeError
(
f"Screen
{
name
!r
}
: component must be a @component, got
{
component
!r
}
"
)
self
.
name
=
name
self
.
component
=
component
if
callable
(
options
):
if
option_kwargs
:
raise
TypeError
(
"Pass either a callable `options` or keyword options, not both"
)
self
.
options
:
Union
[
ScreenOptions
,
Callable
[[
Any
],
ScreenOptions
]]
=
options
else
:
merged
:
Dict
[
str
,
Any
]
=
dict
(
options
or
{})
merged
.
update
(
option_kwargs
)
self
.
options
=
merged
# type: ignore[assignment]
self
.
initial_params
:
Dict
[
str
,
Any
]
=
dict
(
initial_params
or
{})
def
resolve_options
(
self
,
route
:
Any
)
->
Dict
[
str
,
Any
]:
"""Return the static options, evaluating a callable ``options`` for ``route``."""
opts
=
self
.
options
if
callable
(
opts
):
return
dict
(
opts
(
route
)
or
{})
return
dict
(
opts
)
def
__repr__
(
self
)
->
str
:
return
f"Screen(
{
self
.
name
!r
}
)"
Back
|
FazBrowse Home
|
New Git URL