pythonnative 0.22.0__py3-none-any.whl → 0.23.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.
Files changed (53) hide show
  1. pythonnative/__init__.py +16 -2
  2. pythonnative/animated.py +6 -6
  3. pythonnative/appearance.py +124 -0
  4. pythonnative/cli/pn.py +1 -1
  5. pythonnative/components.py +718 -48
  6. pythonnative/events.py +5 -5
  7. pythonnative/gestures.py +3 -3
  8. pythonnative/hooks.py +44 -3
  9. pythonnative/hot_reload.py +4 -4
  10. pythonnative/images.py +196 -0
  11. pythonnative/layout.py +3 -3
  12. pythonnative/mutations.py +4 -13
  13. pythonnative/native_modules/camera.py +1 -1
  14. pythonnative/native_modules/haptics.py +2 -2
  15. pythonnative/native_modules/location.py +1 -1
  16. pythonnative/native_modules/permissions.py +2 -2
  17. pythonnative/native_modules/secure_store.py +1 -1
  18. pythonnative/native_views/__init__.py +1 -7
  19. pythonnative/native_views/android.py +592 -64
  20. pythonnative/native_views/base.py +3 -3
  21. pythonnative/native_views/desktop.py +85 -26
  22. pythonnative/native_views/ios.py +762 -74
  23. pythonnative/navigation.py +4 -4
  24. pythonnative/net.py +3 -3
  25. pythonnative/platform.py +1 -1
  26. pythonnative/platform_metrics.py +5 -5
  27. pythonnative/preview.py +34 -3
  28. pythonnative/project/builder.py +1 -1
  29. pythonnative/project/config.py +4 -12
  30. pythonnative/project/doctor.py +2 -2
  31. pythonnative/project/icons.py +1 -1
  32. pythonnative/project/ios.py +1 -1
  33. pythonnative/project/permissions.py +2 -2
  34. pythonnative/project/runtime_assets.py +3 -3
  35. pythonnative/reconciler.py +9 -9
  36. pythonnative/runtime.py +8 -8
  37. pythonnative/screen.py +90 -5
  38. pythonnative/sdk/_components.py +1 -1
  39. pythonnative/storage.py +3 -3
  40. pythonnative/style.py +66 -7
  41. pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +2 -1
  42. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNAccessibilityDelegate.kt +47 -0
  43. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNBorderDrawable.kt +67 -0
  44. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNVirtualListView.java +172 -0
  45. pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +2 -2
  46. pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +1 -1
  47. pythonnative/virtual_rows.py +137 -0
  48. {pythonnative-0.22.0.dist-info → pythonnative-0.23.0.dist-info}/METADATA +13 -13
  49. {pythonnative-0.22.0.dist-info → pythonnative-0.23.0.dist-info}/RECORD +53 -47
  50. {pythonnative-0.22.0.dist-info → pythonnative-0.23.0.dist-info}/WHEEL +1 -1
  51. {pythonnative-0.22.0.dist-info → pythonnative-0.23.0.dist-info}/entry_points.txt +0 -0
  52. {pythonnative-0.22.0.dist-info → pythonnative-0.23.0.dist-info}/licenses/LICENSE +0 -0
  53. {pythonnative-0.22.0.dist-info → pythonnative-0.23.0.dist-info}/top_level.txt +0 -0
pythonnative/__init__.py CHANGED
@@ -60,9 +60,9 @@ Example:
60
60
  ```
61
61
  """
62
62
 
63
- __version__ = "0.22.0"
63
+ __version__ = "0.23.0"
64
64
 
65
- from . import gestures, runtime, sdk
65
+ from . import appearance, gestures, images, runtime, sdk
66
66
  from .alerts import Alert
67
67
  from .animated import Animated, AnimatedValue, use_animated_value
68
68
  from .components import (
@@ -132,6 +132,7 @@ from .hooks import (
132
132
  memo,
133
133
  use_async_effect,
134
134
  use_callback,
135
+ use_color_scheme,
135
136
  use_context,
136
137
  use_effect,
137
138
  use_keyboard_height,
@@ -185,6 +186,8 @@ from .sdk import (
185
186
  )
186
187
  from .storage import AsyncStorage, use_persisted_state
187
188
  from .style import (
189
+ DEFAULT_DARK_THEME,
190
+ DEFAULT_LIGHT_THEME,
188
191
  AlignItems,
189
192
  AlignSelf,
190
193
  AutoCapitalize,
@@ -207,8 +210,10 @@ from .style import (
207
210
  TextDecoration,
208
211
  ThemeContext,
209
212
  TransformSpec,
213
+ default_theme,
210
214
  resolve_style,
211
215
  style,
216
+ use_theme,
212
217
  )
213
218
 
214
219
  __all__ = [
@@ -280,6 +285,7 @@ __all__ = [
280
285
  "QueryResult",
281
286
  "use_async_effect",
282
287
  "use_callback",
288
+ "use_color_scheme",
283
289
  "use_context",
284
290
  "use_effect",
285
291
  "use_focus_effect",
@@ -306,6 +312,8 @@ __all__ = [
306
312
  "AlignSelf",
307
313
  "AutoCapitalize",
308
314
  "Color",
315
+ "DEFAULT_DARK_THEME",
316
+ "DEFAULT_LIGHT_THEME",
309
317
  "Dimension",
310
318
  "EdgeInsets",
311
319
  "FlexDirection",
@@ -324,8 +332,14 @@ __all__ = [
324
332
  "TextDecoration",
325
333
  "ThemeContext",
326
334
  "TransformSpec",
335
+ "default_theme",
327
336
  "resolve_style",
328
337
  "style",
338
+ "use_theme",
339
+ # Appearance
340
+ "appearance",
341
+ # Image pipeline
342
+ "images",
329
343
  # Animation
330
344
  "Animated",
331
345
  "AnimatedValue",
pythonnative/animated.py CHANGED
@@ -24,7 +24,7 @@ native view the value is attached to
24
24
 
25
25
  - **Accepted** (iOS Core Animation, Android ``ViewPropertyAnimator`` /
26
26
  ``DynamicAnimation``): the platform animates the property entirely
27
- natively no Python code runs per frame. Python receives exactly one
27
+ natively; no Python code runs per frame. Python receives exactly one
28
28
  callback when the animation settles, updates the
29
29
  [`AnimatedValue`][pythonnative.animated.AnimatedValue], and resolves
30
30
  any awaiting tasks.
@@ -135,7 +135,7 @@ class AnimatedValue:
135
135
  Animated components (``Animated.View`` et al.) **attach** the value
136
136
  to ``(tag, prop)`` bindings after mount. Setting the value pushes
137
137
  the new number to every attached native view through the registry's
138
- ``set_animated_property`` and when an animation can be driven
138
+ ``set_animated_property``, and when an animation can be driven
139
139
  natively, the platform animates those same bindings directly.
140
140
 
141
141
  Python-side listeners registered via
@@ -217,7 +217,7 @@ class AnimatedValue:
217
217
  def add_listener(self, prop: str, callback: Callable[[float], None]) -> Callable[[], None]:
218
218
  """Register ``callback`` for Python-driven changes to this value.
219
219
 
220
- Returns an unsubscribe callable. ``prop`` is metadata only it
220
+ Returns an unsubscribe callable. ``prop`` is metadata only; it
221
221
  lets the subscriber differentiate this binding from others on
222
222
  the same ``AnimatedValue``.
223
223
  """
@@ -686,7 +686,7 @@ class _AnimationHandle(_AwaitableAnimation):
686
686
 
687
687
  Each ``.start()`` call snapshots the value's current state, prefers
688
688
  the native driver, and falls back to a fresh Python-ticked
689
- animation otherwise (matches React Native the ``Animated.timing``
689
+ animation otherwise (matches React Native: the ``Animated.timing``
690
690
  return value is reusable).
691
691
  """
692
692
 
@@ -780,7 +780,7 @@ class _CompositeAnimation(_AwaitableAnimation):
780
780
  if item is None:
781
781
  return
782
782
  # ``_AwaitableAnimation`` and plain awaitables/coroutines are
783
- # both supported lets users mix in ``asyncio.sleep``.
783
+ # both supported: lets users mix in ``asyncio.sleep``.
784
784
  await item
785
785
 
786
786
 
@@ -824,7 +824,7 @@ def _make_animated_factory(
824
824
 
825
825
  # ``@component`` packs positional children into the ``children``
826
826
  # prop (this function declares ``*args``), and the reconciler
827
- # re-invokes it with keyword props only so at render time the
827
+ # re-invokes it with keyword props only, so at render time the
828
828
  # payload arrives in ``kwargs``, never in ``args``.
829
829
  children = list(args) or list(kwargs.pop("children", ()) or ())
830
830
 
@@ -0,0 +1,124 @@
1
+ """System color-scheme (light / dark mode) tracking.
2
+
3
+ The platform screen host publishes the operating system's current
4
+ appearance here (Android: ``Configuration.uiMode``; iOS:
5
+ ``UITraitCollection.userInterfaceStyle``), and components read it back
6
+ through [`use_color_scheme`][pythonnative.use_color_scheme] or
7
+ [`use_theme`][pythonnative.use_theme], both of which re-render when
8
+ the scheme changes.
9
+
10
+ Apps can also *override* the scheme (e.g. an in-app appearance
11
+ setting) with [`set_color_scheme`][pythonnative.appearance.set_color_scheme];
12
+ the override wins over the system value until cleared with ``None``.
13
+
14
+ Example:
15
+ >>> from pythonnative import appearance
16
+ >>> appearance.get_color_scheme()
17
+ 'light'
18
+ >>> appearance.set_color_scheme("dark") # app-level override
19
+ >>> appearance.get_color_scheme()
20
+ 'dark'
21
+ >>> appearance.set_color_scheme(None) # follow the system again
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import threading
27
+ from typing import Callable, List, Literal, Optional
28
+
29
+ ColorScheme = Literal["light", "dark"]
30
+ """The two supported appearance values."""
31
+
32
+ _system_scheme: str = "light"
33
+ _override_scheme: Optional[str] = None
34
+
35
+ _subscribers: List[Callable[[], None]] = []
36
+ _subscribers_lock = threading.Lock()
37
+
38
+
39
+ def _notify_subscribers() -> None:
40
+ """Invoke every registered subscriber, swallowing exceptions."""
41
+ with _subscribers_lock:
42
+ callbacks = list(_subscribers)
43
+ for cb in callbacks:
44
+ try:
45
+ cb()
46
+ except Exception:
47
+ pass
48
+
49
+
50
+ def subscribe(callback: Callable[[], None]) -> Callable[[], None]:
51
+ """Register ``callback`` to fire whenever the effective scheme changes.
52
+
53
+ Returns an unsubscribe function. Threadsafe.
54
+ """
55
+ with _subscribers_lock:
56
+ _subscribers.append(callback)
57
+
58
+ def _unsub() -> None:
59
+ with _subscribers_lock:
60
+ try:
61
+ _subscribers.remove(callback)
62
+ except ValueError:
63
+ pass
64
+
65
+ return _unsub
66
+
67
+
68
+ def _coerce(scheme: object) -> Optional[str]:
69
+ if scheme in ("light", "dark"):
70
+ return str(scheme)
71
+ return None
72
+
73
+
74
+ def set_system_color_scheme(scheme: str) -> None:
75
+ """Publish the operating system's current scheme.
76
+
77
+ Called by the platform screen host on create/resume and whenever
78
+ the system reports an appearance change. Invalid values are
79
+ ignored. Subscribers are only notified when the *effective* scheme
80
+ (after any app override) actually changes.
81
+ """
82
+ global _system_scheme
83
+ coerced = _coerce(scheme)
84
+ if coerced is None or coerced == _system_scheme:
85
+ return
86
+ effective_before = get_color_scheme()
87
+ _system_scheme = coerced
88
+ if get_color_scheme() != effective_before:
89
+ _notify_subscribers()
90
+
91
+
92
+ def set_color_scheme(scheme: Optional[str]) -> None:
93
+ """Set (or clear) the app-level scheme override.
94
+
95
+ Args:
96
+ scheme: ``"light"`` or ``"dark"`` to force that appearance
97
+ regardless of the system setting, or ``None`` to follow
98
+ the system again.
99
+ """
100
+ global _override_scheme
101
+ coerced = _coerce(scheme) if scheme is not None else None
102
+ if scheme is not None and coerced is None:
103
+ return
104
+ effective_before = get_color_scheme()
105
+ _override_scheme = coerced
106
+ if get_color_scheme() != effective_before:
107
+ _notify_subscribers()
108
+
109
+
110
+ def get_color_scheme() -> str:
111
+ """Return the effective scheme: the app override if set, else the system value."""
112
+ return _override_scheme if _override_scheme is not None else _system_scheme
113
+
114
+
115
+ def get_system_color_scheme() -> str:
116
+ """Return the system-reported scheme, ignoring any app override."""
117
+ return _system_scheme
118
+
119
+
120
+ def reset_color_scheme() -> None:
121
+ """Reset to system ``"light"`` with no override. Intended for tests."""
122
+ global _system_scheme, _override_scheme
123
+ _system_scheme = "light"
124
+ _override_scheme = None
pythonnative/cli/pn.py CHANGED
@@ -5,7 +5,7 @@ The console script `pn` (declared in `pyproject.toml`) dispatches to:
5
5
  - `pn init [name]`: scaffold a new project (``pythonnative.toml`` + ``app/``).
6
6
  - `pn doctor [platform]`: diagnose the local toolchain and config.
7
7
  - `pn preview [component]`: render the app in a desktop (Tkinter) window
8
- with Fast Refresh the fast inner dev loop, no device required.
8
+ with Fast Refresh, the fast inner dev loop, no device required.
9
9
  - `pn run android|ios`: stage + build + install + launch on a device or
10
10
  simulator, with optional on-device hot reload.
11
11
  - `pn build android|ios`: produce standalone artifacts (signed APK/AAB,