pythonnative 0.24.0__py3-none-any.whl → 0.25.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pythonnative/__init__.py +16 -4
- pythonnative/animated.py +2 -2
- pythonnative/components.py +59 -0
- pythonnative/hooks.py +364 -81
- pythonnative/native_modules/notifications.py +36 -4
- pythonnative/native_modules/permissions.py +24 -1
- pythonnative/native_views/android.py +7 -2
- pythonnative/native_views/ios.py +12 -1
- pythonnative/reconciler.py +518 -37
- pythonnative/runtime.py +407 -215
- pythonnative/screen.py +53 -7
- pythonnative/storage.py +2 -2
- pythonnative/suspense.py +417 -0
- {pythonnative-0.24.0.dist-info → pythonnative-0.25.0.dist-info}/METADATA +2 -1
- {pythonnative-0.24.0.dist-info → pythonnative-0.25.0.dist-info}/RECORD +19 -18
- {pythonnative-0.24.0.dist-info → pythonnative-0.25.0.dist-info}/WHEEL +1 -1
- {pythonnative-0.24.0.dist-info → pythonnative-0.25.0.dist-info}/entry_points.txt +0 -0
- {pythonnative-0.24.0.dist-info → pythonnative-0.25.0.dist-info}/licenses/LICENSE +0 -0
- {pythonnative-0.24.0.dist-info → pythonnative-0.25.0.dist-info}/top_level.txt +0 -0
pythonnative/__init__.py
CHANGED
|
@@ -60,7 +60,7 @@ Example:
|
|
|
60
60
|
```
|
|
61
61
|
"""
|
|
62
62
|
|
|
63
|
-
__version__ = "0.
|
|
63
|
+
__version__ = "0.25.0"
|
|
64
64
|
|
|
65
65
|
from . import appearance, diagnostics, gestures, images, runtime, sdk
|
|
66
66
|
from .alerts import Alert
|
|
@@ -92,6 +92,7 @@ from .components import (
|
|
|
92
92
|
Slider,
|
|
93
93
|
Spacer,
|
|
94
94
|
StatusBar,
|
|
95
|
+
Suspense,
|
|
95
96
|
Switch,
|
|
96
97
|
Text,
|
|
97
98
|
TextInput,
|
|
@@ -111,11 +112,11 @@ from .hooks import (
|
|
|
111
112
|
component,
|
|
112
113
|
create_context,
|
|
113
114
|
memo,
|
|
114
|
-
use_async_effect,
|
|
115
115
|
use_back_handler,
|
|
116
116
|
use_callback,
|
|
117
117
|
use_color_scheme,
|
|
118
118
|
use_context,
|
|
119
|
+
use_deferred_value,
|
|
119
120
|
use_effect,
|
|
120
121
|
use_imperative_handle,
|
|
121
122
|
use_keyboard_height,
|
|
@@ -126,8 +127,10 @@ from .hooks import (
|
|
|
126
127
|
use_query,
|
|
127
128
|
use_reducer,
|
|
128
129
|
use_ref,
|
|
130
|
+
use_resource,
|
|
129
131
|
use_safe_area_insets,
|
|
130
132
|
use_state,
|
|
133
|
+
use_transition,
|
|
131
134
|
use_window_dimensions,
|
|
132
135
|
)
|
|
133
136
|
from .native_modules import (
|
|
@@ -160,7 +163,7 @@ from .navigation import (
|
|
|
160
163
|
)
|
|
161
164
|
from .net import HTTPError, Response, fetch
|
|
162
165
|
from .platform import Platform
|
|
163
|
-
from .runtime import run_async
|
|
166
|
+
from .runtime import run_async, run_blocking
|
|
164
167
|
from .screen import create_screen
|
|
165
168
|
from .sdk import (
|
|
166
169
|
Props,
|
|
@@ -204,6 +207,7 @@ from .style import (
|
|
|
204
207
|
style,
|
|
205
208
|
use_theme,
|
|
206
209
|
)
|
|
210
|
+
from .suspense import Resource, lazy, start_resource
|
|
207
211
|
|
|
208
212
|
__all__ = [
|
|
209
213
|
# Components
|
|
@@ -233,6 +237,7 @@ __all__ = [
|
|
|
233
237
|
"Slider",
|
|
234
238
|
"Spacer",
|
|
235
239
|
"StatusBar",
|
|
240
|
+
"Suspense",
|
|
236
241
|
"Switch",
|
|
237
242
|
"Text",
|
|
238
243
|
"TextInput",
|
|
@@ -251,11 +256,11 @@ __all__ = [
|
|
|
251
256
|
"MutationState",
|
|
252
257
|
"QueryResult",
|
|
253
258
|
"Ref",
|
|
254
|
-
"use_async_effect",
|
|
255
259
|
"use_back_handler",
|
|
256
260
|
"use_callback",
|
|
257
261
|
"use_color_scheme",
|
|
258
262
|
"use_context",
|
|
263
|
+
"use_deferred_value",
|
|
259
264
|
"use_effect",
|
|
260
265
|
"use_focus_effect",
|
|
261
266
|
"use_imperative_handle",
|
|
@@ -268,11 +273,17 @@ __all__ = [
|
|
|
268
273
|
"use_query",
|
|
269
274
|
"use_reducer",
|
|
270
275
|
"use_ref",
|
|
276
|
+
"use_resource",
|
|
271
277
|
"use_route",
|
|
272
278
|
"use_safe_area_insets",
|
|
273
279
|
"use_state",
|
|
280
|
+
"use_transition",
|
|
274
281
|
"use_window_dimensions",
|
|
275
282
|
"Provider",
|
|
283
|
+
# Suspense and async rendering
|
|
284
|
+
"Resource",
|
|
285
|
+
"lazy",
|
|
286
|
+
"start_resource",
|
|
276
287
|
# Navigation
|
|
277
288
|
"NavigationContainer",
|
|
278
289
|
"ScreenOptions",
|
|
@@ -349,6 +360,7 @@ __all__ = [
|
|
|
349
360
|
"Response",
|
|
350
361
|
# Runtime
|
|
351
362
|
"run_async",
|
|
363
|
+
"run_blocking",
|
|
352
364
|
"runtime",
|
|
353
365
|
# Diagnostics
|
|
354
366
|
"HookOrderError",
|
pythonnative/animated.py
CHANGED
|
@@ -47,7 +47,7 @@ Example:
|
|
|
47
47
|
await pn.Animated.timing(opacity, to=1.0, duration=400)
|
|
48
48
|
await pn.Animated.timing(opacity, to=0.5, duration=200)
|
|
49
49
|
|
|
50
|
-
pn.
|
|
50
|
+
pn.use_effect(fade_in, [])
|
|
51
51
|
|
|
52
52
|
return pn.Animated.View(
|
|
53
53
|
pn.Text("Hello!"),
|
|
@@ -1014,7 +1014,7 @@ def use_animated_value(initial: float = 0.0) -> AnimatedValue:
|
|
|
1014
1014
|
async def fade_in():
|
|
1015
1015
|
await pn.Animated.timing(opacity, to=1.0, duration=300)
|
|
1016
1016
|
|
|
1017
|
-
pn.
|
|
1017
|
+
pn.use_effect(fade_in, [])
|
|
1018
1018
|
return pn.Animated.View(
|
|
1019
1019
|
pn.Text("Hello"),
|
|
1020
1020
|
style=pn.style(opacity=opacity),
|
pythonnative/components.py
CHANGED
|
@@ -1732,6 +1732,65 @@ def ErrorBoundary(
|
|
|
1732
1732
|
return Element("__ErrorBoundary__", props, list(children), key=key)
|
|
1733
1733
|
|
|
1734
1734
|
|
|
1735
|
+
def Suspense(
|
|
1736
|
+
*children: Element,
|
|
1737
|
+
fallback: Optional[Any] = None,
|
|
1738
|
+
key: Optional[str] = None,
|
|
1739
|
+
) -> Element:
|
|
1740
|
+
"""Show ``fallback`` while descendants wait on async work, then swap in the content.
|
|
1741
|
+
|
|
1742
|
+
A Suspense boundary catches **suspensions** from the subtree it
|
|
1743
|
+
wraps: an ``async def`` component body blocking on a pending
|
|
1744
|
+
await, or a regular component calling
|
|
1745
|
+
[`Resource.read`][pythonnative.suspense.Resource.read] on data that hasn't
|
|
1746
|
+
arrived (see [`use_resource`][pythonnative.use_resource] and
|
|
1747
|
+
[`lazy`][pythonnative.lazy]). While anything is pending the
|
|
1748
|
+
boundary renders ``fallback``; when the awaited work completes it
|
|
1749
|
+
retries the content and swaps it in. Suspended components keep
|
|
1750
|
+
their hook state across retries, so cached resources aren't
|
|
1751
|
+
refetched.
|
|
1752
|
+
|
|
1753
|
+
Two timing behaviors, matching React:
|
|
1754
|
+
|
|
1755
|
+
- **Initial mount**: the fallback shows until the content is ready.
|
|
1756
|
+
- **Updates**: a component that's already on screen and suspends
|
|
1757
|
+
again (its dependencies changed) keeps its previous content
|
|
1758
|
+
visible and re-renders when ready; there's no fallback flash.
|
|
1759
|
+
|
|
1760
|
+
Args:
|
|
1761
|
+
*children: Subtree to wrap (the async content).
|
|
1762
|
+
fallback: Content shown while suspended: an
|
|
1763
|
+
[`Element`][pythonnative.Element] or a zero-arg callable
|
|
1764
|
+
returning one. Without it, suspensions propagate to the
|
|
1765
|
+
next Suspense boundary up.
|
|
1766
|
+
key: Stable identity for keyed reconciliation.
|
|
1767
|
+
|
|
1768
|
+
Returns:
|
|
1769
|
+
An [`Element`][pythonnative.Element] of type ``"__Suspense__"``.
|
|
1770
|
+
|
|
1771
|
+
Example:
|
|
1772
|
+
```python
|
|
1773
|
+
import pythonnative as pn
|
|
1774
|
+
|
|
1775
|
+
@pn.component
|
|
1776
|
+
async def Profile(user_id: str):
|
|
1777
|
+
user = await api.fetch_user(user_id)
|
|
1778
|
+
return pn.Text(user.name)
|
|
1779
|
+
|
|
1780
|
+
@pn.component
|
|
1781
|
+
def Screen():
|
|
1782
|
+
return pn.Suspense(
|
|
1783
|
+
Profile(user_id="42"),
|
|
1784
|
+
fallback=pn.ActivityIndicator(),
|
|
1785
|
+
)
|
|
1786
|
+
```
|
|
1787
|
+
"""
|
|
1788
|
+
props: Dict[str, Any] = {}
|
|
1789
|
+
if fallback is not None:
|
|
1790
|
+
props["__fallback__"] = fallback
|
|
1791
|
+
return Element("__Suspense__", props, list(children), key=key)
|
|
1792
|
+
|
|
1793
|
+
|
|
1735
1794
|
# ======================================================================
|
|
1736
1795
|
# Lists (native virtualization with a Python-windowed fallback)
|
|
1737
1796
|
# ======================================================================
|