pythonnative 0.22.1__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 (25) hide show
  1. pythonnative/__init__.py +16 -2
  2. pythonnative/appearance.py +124 -0
  3. pythonnative/components.py +708 -38
  4. pythonnative/hooks.py +41 -0
  5. pythonnative/images.py +196 -0
  6. pythonnative/mutations.py +3 -12
  7. pythonnative/native_views/__init__.py +1 -7
  8. pythonnative/native_views/android.py +573 -45
  9. pythonnative/native_views/desktop.py +78 -19
  10. pythonnative/native_views/ios.py +739 -51
  11. pythonnative/preview.py +31 -0
  12. pythonnative/project/config.py +1 -9
  13. pythonnative/screen.py +85 -0
  14. pythonnative/style.py +65 -6
  15. pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +2 -1
  16. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNAccessibilityDelegate.kt +47 -0
  17. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNBorderDrawable.kt +67 -0
  18. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/PNVirtualListView.java +172 -0
  19. pythonnative/virtual_rows.py +137 -0
  20. {pythonnative-0.22.1.dist-info → pythonnative-0.23.0.dist-info}/METADATA +1 -1
  21. {pythonnative-0.22.1.dist-info → pythonnative-0.23.0.dist-info}/RECORD +25 -19
  22. {pythonnative-0.22.1.dist-info → pythonnative-0.23.0.dist-info}/WHEEL +1 -1
  23. {pythonnative-0.22.1.dist-info → pythonnative-0.23.0.dist-info}/entry_points.txt +0 -0
  24. {pythonnative-0.22.1.dist-info → pythonnative-0.23.0.dist-info}/licenses/LICENSE +0 -0
  25. {pythonnative-0.22.1.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.1"
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",
@@ -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