pythonnative 0.14.0__py3-none-any.whl → 0.16.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 CHANGED
@@ -23,8 +23,18 @@ Key building blocks:
23
23
  factories.
24
24
  - **Styling** uses a single ``style`` dict per element (or a list of
25
25
  dicts), composable via [`StyleSheet`][pythonnative.StyleSheet].
26
+ PythonNative ships a fully-typed [`Style`][pythonnative.style.Style]
27
+ TypedDict so editors and ``mypy`` validate every key as you type.
26
28
  - **Animations** use the ``Animated`` namespace, modeled on React
27
29
  Native's animation API.
30
+ - **Custom native components** can be authored with the
31
+ ``pythonnative.sdk`` package: define a typed
32
+ [`Props`][pythonnative.sdk.Props] dataclass, implement a
33
+ [`ViewHandler`][pythonnative.native_views.base.ViewHandler] for each
34
+ platform, and register it via
35
+ [`@native_component`][pythonnative.sdk.native_component] (or expose
36
+ it from a PyPI package via the ``pythonnative.handlers`` entry-point
37
+ group).
28
38
 
29
39
  Example:
30
40
  ```python
@@ -34,42 +44,62 @@ Example:
34
44
  def App():
35
45
  count, set_count = pn.use_state(0)
36
46
  return pn.Column(
37
- pn.Text(f"Count: {count}", style={"font_size": 24}),
47
+ pn.Text(f"Count: {count}", style=pn.style(font_size=24)),
38
48
  pn.Button("+", on_click=lambda: set_count(count + 1)),
39
- style={"spacing": 12},
49
+ style=pn.style(spacing=12),
40
50
  )
41
51
  ```
42
52
  """
43
53
 
44
- __version__ = "0.14.0"
54
+ __version__ = "0.16.0"
45
55
 
56
+ from . import sdk
46
57
  from .alerts import Alert
47
- from .animated import Animated, AnimatedValue
58
+ from .animated import Animated, AnimatedValue, use_animated_value
48
59
  from .components import (
49
60
  ActivityIndicator,
61
+ ActivityIndicatorProps,
50
62
  Button,
63
+ ButtonProps,
51
64
  Column,
52
65
  ErrorBoundary,
53
66
  FlatList,
67
+ Fragment,
54
68
  Image,
69
+ ImageProps,
55
70
  KeyboardAvoidingView,
71
+ KeyboardAvoidingViewProps,
56
72
  Modal,
73
+ ModalProps,
57
74
  Picker,
75
+ PickerProps,
58
76
  Pressable,
77
+ PressableProps,
59
78
  ProgressBar,
79
+ ProgressBarProps,
60
80
  RefreshControl,
61
81
  Row,
62
82
  SafeAreaView,
83
+ SafeAreaViewProps,
63
84
  ScrollView,
85
+ ScrollViewProps,
64
86
  SectionList,
65
87
  Slider,
88
+ SliderProps,
66
89
  Spacer,
90
+ SpacerProps,
67
91
  StatusBar,
92
+ StatusBarProps,
68
93
  Switch,
94
+ SwitchProps,
69
95
  Text,
70
96
  TextInput,
97
+ TextInputProps,
98
+ TextProps,
71
99
  View,
100
+ ViewProps,
72
101
  WebView,
102
+ WebViewProps,
73
103
  )
74
104
  from .element import Element
75
105
  from .hooks import (
@@ -77,6 +107,7 @@ from .hooks import (
77
107
  batch_updates,
78
108
  component,
79
109
  create_context,
110
+ memo,
80
111
  use_callback,
81
112
  use_context,
82
113
  use_effect,
@@ -100,7 +131,39 @@ from .navigation import (
100
131
  )
101
132
  from .platform import Platform
102
133
  from .screen import create_screen
103
- from .style import StyleSheet, ThemeContext
134
+ from .sdk import (
135
+ Props,
136
+ ViewHandler,
137
+ element_factory,
138
+ native_component,
139
+ register_component,
140
+ )
141
+ from .style import (
142
+ AlignItems,
143
+ AlignSelf,
144
+ AutoCapitalize,
145
+ Color,
146
+ Dimension,
147
+ EdgeInsets,
148
+ FlexDirection,
149
+ FontWeight,
150
+ JustifyContent,
151
+ KeyboardType,
152
+ Overflow,
153
+ Position,
154
+ ReturnKeyType,
155
+ ScaleType,
156
+ ShadowOffset,
157
+ Style,
158
+ StyleProp,
159
+ StyleSheet,
160
+ TextAlign,
161
+ TextDecoration,
162
+ ThemeContext,
163
+ TransformSpec,
164
+ resolve_style,
165
+ style,
166
+ )
104
167
 
105
168
  __all__ = [
106
169
  # Components
@@ -109,6 +172,7 @@ __all__ = [
109
172
  "Column",
110
173
  "ErrorBoundary",
111
174
  "FlatList",
175
+ "Fragment",
112
176
  "Image",
113
177
  "KeyboardAvoidingView",
114
178
  "Modal",
@@ -128,6 +192,25 @@ __all__ = [
128
192
  "TextInput",
129
193
  "View",
130
194
  "WebView",
195
+ # Built-in Props dataclasses
196
+ "ActivityIndicatorProps",
197
+ "ButtonProps",
198
+ "ImageProps",
199
+ "KeyboardAvoidingViewProps",
200
+ "ModalProps",
201
+ "PickerProps",
202
+ "PressableProps",
203
+ "ProgressBarProps",
204
+ "SafeAreaViewProps",
205
+ "ScrollViewProps",
206
+ "SliderProps",
207
+ "SpacerProps",
208
+ "StatusBarProps",
209
+ "SwitchProps",
210
+ "TextInputProps",
211
+ "TextProps",
212
+ "ViewProps",
213
+ "WebViewProps",
131
214
  # Core
132
215
  "Element",
133
216
  "create_screen",
@@ -135,6 +218,7 @@ __all__ = [
135
218
  "batch_updates",
136
219
  "component",
137
220
  "create_context",
221
+ "memo",
138
222
  "use_callback",
139
223
  "use_context",
140
224
  "use_effect",
@@ -154,12 +238,35 @@ __all__ = [
154
238
  "create_drawer_navigator",
155
239
  "create_stack_navigator",
156
240
  "create_tab_navigator",
157
- # Styling
241
+ # Styling - typed primitives
242
+ "AlignItems",
243
+ "AlignSelf",
244
+ "AutoCapitalize",
245
+ "Color",
246
+ "Dimension",
247
+ "EdgeInsets",
248
+ "FlexDirection",
249
+ "FontWeight",
250
+ "JustifyContent",
251
+ "KeyboardType",
252
+ "Overflow",
253
+ "Position",
254
+ "ReturnKeyType",
255
+ "ScaleType",
256
+ "ShadowOffset",
257
+ "Style",
258
+ "StyleProp",
158
259
  "StyleSheet",
260
+ "TextAlign",
261
+ "TextDecoration",
159
262
  "ThemeContext",
263
+ "TransformSpec",
264
+ "resolve_style",
265
+ "style",
160
266
  # Animation
161
267
  "Animated",
162
268
  "AnimatedValue",
269
+ "use_animated_value",
163
270
  # Imperative
164
271
  "Alert",
165
272
  # Native modules
@@ -169,4 +276,11 @@ __all__ = [
169
276
  "Notifications",
170
277
  # Platform
171
278
  "Platform",
279
+ # Custom-component SDK
280
+ "Props",
281
+ "ViewHandler",
282
+ "element_factory",
283
+ "native_component",
284
+ "register_component",
285
+ "sdk",
172
286
  ]
pythonnative/animated.py CHANGED
@@ -58,7 +58,7 @@ from typing import Any, Callable, Dict, List, Optional, Tuple
58
58
 
59
59
  from .element import Element
60
60
  from .hooks import use_effect, use_ref
61
- from .style import StyleValue, resolve_style
61
+ from .style import StyleProp, resolve_style
62
62
 
63
63
  # Maximum frame rate at which the Python ticker drives animations.
64
64
  # We aim for 60 Hz but back off when no animation is active.
@@ -433,7 +433,7 @@ class _AnimationHandle:
433
433
  # ======================================================================
434
434
 
435
435
 
436
- def _resolve_style_with_values(style: StyleValue) -> Tuple[Dict[str, Any], Dict[str, AnimatedValue]]:
436
+ def _resolve_style_with_values(style: StyleProp) -> Tuple[Dict[str, Any], Dict[str, AnimatedValue]]:
437
437
  """Return ``(plain_style, animated_bindings)``.
438
438
 
439
439
  AnimatedValue entries in the style are replaced with their
@@ -661,7 +661,45 @@ class _AnimatedNamespace:
661
661
  Animated = _AnimatedNamespace()
662
662
 
663
663
 
664
+ def use_animated_value(initial: float = 0.0) -> AnimatedValue:
665
+ """Return an [`AnimatedValue`][pythonnative.AnimatedValue] with a stable identity across renders.
666
+
667
+ Convenience wrapper for the common pattern
668
+ ``pn.use_memo(lambda: AnimatedValue(initial), [])``. The same
669
+ instance is returned on every render of the same component, so
670
+ you can drive it from event handlers without recreating it.
671
+
672
+ Args:
673
+ initial: The starting numeric value.
674
+
675
+ Returns:
676
+ A mount-stable [`AnimatedValue`][pythonnative.AnimatedValue].
677
+
678
+ Example:
679
+ ```python
680
+ import pythonnative as pn
681
+
682
+ @pn.component
683
+ def FadeIn():
684
+ opacity = pn.use_animated_value(0.0)
685
+
686
+ def fade_in():
687
+ pn.Animated.timing(opacity, to=1.0, duration=300).start()
688
+
689
+ pn.use_effect(lambda: fade_in(), [])
690
+ return pn.Animated.View(
691
+ pn.Text("Hello"),
692
+ style=pn.style(opacity=opacity),
693
+ )
694
+ ```
695
+ """
696
+ from .hooks import use_memo
697
+
698
+ return use_memo(lambda: AnimatedValue(initial), [])
699
+
700
+
664
701
  __all__ = [
665
702
  "AnimatedValue",
666
703
  "Animated",
704
+ "use_animated_value",
667
705
  ]