pythonnative 0.7.0__py3-none-any.whl → 0.9.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.
@@ -0,0 +1,150 @@
1
+ """Shared base classes and utilities for native view handlers.
2
+
3
+ Provides the :class:`ViewHandler` abstract base class and common helper
4
+ functions used by both Android and iOS platform implementations.
5
+ """
6
+
7
+ from typing import Any, Dict, Union
8
+
9
+
10
+ class ViewHandler:
11
+ """Protocol for creating, updating, and managing children of a native view type."""
12
+
13
+ def create(self, props: Dict[str, Any]) -> Any:
14
+ raise NotImplementedError
15
+
16
+ def update(self, native_view: Any, changed_props: Dict[str, Any]) -> None:
17
+ raise NotImplementedError
18
+
19
+ def add_child(self, parent: Any, child: Any) -> None:
20
+ pass
21
+
22
+ def remove_child(self, parent: Any, child: Any) -> None:
23
+ pass
24
+
25
+ def insert_child(self, parent: Any, child: Any, index: int) -> None:
26
+ self.add_child(parent, child)
27
+
28
+
29
+ # ======================================================================
30
+ # Color parsing
31
+ # ======================================================================
32
+
33
+
34
+ def parse_color_int(color: Union[str, int]) -> int:
35
+ """Parse ``#RRGGBB`` / ``#AARRGGBB`` hex string or raw int to a *signed* ARGB int.
36
+
37
+ Java's ``setBackgroundColor`` et al. expect a signed 32-bit int, so values
38
+ with a high alpha byte (e.g. 0xFF…) must be converted to negative ints.
39
+ """
40
+ if isinstance(color, int):
41
+ val = color
42
+ else:
43
+ c = color.strip().lstrip("#")
44
+ if len(c) == 6:
45
+ c = "FF" + c
46
+ val = int(c, 16)
47
+ if val > 0x7FFFFFFF:
48
+ val -= 0x100000000
49
+ return val
50
+
51
+
52
+ # ======================================================================
53
+ # Padding / margin helpers
54
+ # ======================================================================
55
+
56
+
57
+ def resolve_padding(padding: Any) -> tuple:
58
+ """Normalise various padding representations to ``(left, top, right, bottom)``."""
59
+ if padding is None:
60
+ return (0, 0, 0, 0)
61
+ if isinstance(padding, (int, float)):
62
+ v = int(padding)
63
+ return (v, v, v, v)
64
+ if isinstance(padding, dict):
65
+ h = int(padding.get("horizontal", 0))
66
+ v = int(padding.get("vertical", 0))
67
+ left = int(padding.get("left", h))
68
+ right = int(padding.get("right", h))
69
+ top = int(padding.get("top", v))
70
+ bottom = int(padding.get("bottom", v))
71
+ a = int(padding.get("all", 0))
72
+ if a:
73
+ left = left or a
74
+ right = right or a
75
+ top = top or a
76
+ bottom = bottom or a
77
+ return (left, top, right, bottom)
78
+ return (0, 0, 0, 0)
79
+
80
+
81
+ # ======================================================================
82
+ # Flex layout constants
83
+ # ======================================================================
84
+
85
+ FLEX_DIRECTION_COLUMN = "column"
86
+ FLEX_DIRECTION_ROW = "row"
87
+ FLEX_DIRECTION_COLUMN_REVERSE = "column_reverse"
88
+ FLEX_DIRECTION_ROW_REVERSE = "row_reverse"
89
+
90
+ JUSTIFY_FLEX_START = "flex_start"
91
+ JUSTIFY_CENTER = "center"
92
+ JUSTIFY_FLEX_END = "flex_end"
93
+ JUSTIFY_SPACE_BETWEEN = "space_between"
94
+ JUSTIFY_SPACE_AROUND = "space_around"
95
+ JUSTIFY_SPACE_EVENLY = "space_evenly"
96
+
97
+ ALIGN_STRETCH = "stretch"
98
+ ALIGN_FLEX_START = "flex_start"
99
+ ALIGN_CENTER = "center"
100
+ ALIGN_FLEX_END = "flex_end"
101
+
102
+ POSITION_RELATIVE = "relative"
103
+ POSITION_ABSOLUTE = "absolute"
104
+
105
+ OVERFLOW_VISIBLE = "visible"
106
+ OVERFLOW_HIDDEN = "hidden"
107
+ OVERFLOW_SCROLL = "scroll"
108
+
109
+
110
+ def is_vertical(direction: str) -> bool:
111
+ """Return ``True`` if *direction* represents a vertical (column) axis."""
112
+ return direction in (FLEX_DIRECTION_COLUMN, FLEX_DIRECTION_COLUMN_REVERSE)
113
+
114
+
115
+ # ======================================================================
116
+ # Layout property keys
117
+ # ======================================================================
118
+
119
+ LAYOUT_KEYS = frozenset(
120
+ {
121
+ "width",
122
+ "height",
123
+ "flex",
124
+ "flex_grow",
125
+ "flex_shrink",
126
+ "margin",
127
+ "min_width",
128
+ "max_width",
129
+ "min_height",
130
+ "max_height",
131
+ "align_self",
132
+ "position",
133
+ "top",
134
+ "right",
135
+ "bottom",
136
+ "left",
137
+ }
138
+ )
139
+
140
+ CONTAINER_KEYS = frozenset(
141
+ {
142
+ "flex_direction",
143
+ "justify_content",
144
+ "align_items",
145
+ "overflow",
146
+ "spacing",
147
+ "padding",
148
+ "background_color",
149
+ }
150
+ )