pythonnative 0.26.0__py3-none-any.whl → 0.27.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.
@@ -755,6 +755,8 @@ def View(
755
755
  *children: Element,
756
756
  style: StyleProp = None,
757
757
  gestures: Optional[List[Any]] = None,
758
+ hit_slop: Optional[Union[float, Dict[str, float]]] = None,
759
+ on_layout: Optional[Callable[[Dict[str, float]], None]] = None,
758
760
  accessibility_label: Optional[str] = None,
759
761
  accessibility_hint: Optional[str] = None,
760
762
  accessibility_role: Optional[str] = None,
@@ -797,6 +799,13 @@ def View(
797
799
  gestures: Optional list of gesture descriptors from
798
800
  `pythonnative.gestures` (e.g. ``[gestures.Pan(on_change=…)]``)
799
801
  recognized natively on this view.
802
+ hit_slop: Extend the touch target beyond the view's bounds
803
+ without changing layout: a uniform number of points, or a
804
+ dict with any of ``top`` / ``left`` / ``bottom`` /
805
+ ``right``.
806
+ on_layout: Callback invoked with
807
+ ``{"x", "y", "width", "height"}`` after this view is laid
808
+ out, and again whenever its frame changes.
800
809
  accessibility_label: Spoken description for screen readers.
801
810
  accessibility_hint: Spoken extra detail (iOS only).
802
811
  accessibility_role: Semantic role for assistive tech.
@@ -824,6 +833,8 @@ def View(
824
833
  ref=ref,
825
834
  key=key,
826
835
  gestures=gestures,
836
+ hit_slop=hit_slop,
837
+ on_layout=on_layout,
827
838
  accessibility_label=accessibility_label,
828
839
  accessibility_hint=accessibility_hint,
829
840
  accessibility_role=accessibility_role,
@@ -838,6 +849,7 @@ def View(
838
849
  def Column(
839
850
  *children: Element,
840
851
  style: StyleProp = None,
852
+ on_layout: Optional[Callable[[Dict[str, float]], None]] = None,
841
853
  ref: Optional[Ref] = None,
842
854
  key: Optional[str] = None,
843
855
  ) -> Element:
@@ -850,6 +862,9 @@ def Column(
850
862
  Args:
851
863
  *children: Child elements stacked top to bottom.
852
864
  style: Style dict (or list of dicts).
865
+ on_layout: Callback invoked with
866
+ ``{"x", "y", "width", "height"}`` after layout and on
867
+ frame changes.
853
868
  ref: Optional [`Ref`][pythonnative.Ref] for native-view access.
854
869
  key: Stable identity for keyed reconciliation.
855
870
 
@@ -860,6 +875,7 @@ def Column(
860
875
  "Column",
861
876
  *children,
862
877
  style=style,
878
+ on_layout=on_layout,
863
879
  ref=ref,
864
880
  key=key,
865
881
  _forced={"flex_direction": "column"},
@@ -869,6 +885,7 @@ def Column(
869
885
  def Row(
870
886
  *children: Element,
871
887
  style: StyleProp = None,
888
+ on_layout: Optional[Callable[[Dict[str, float]], None]] = None,
872
889
  ref: Optional[Ref] = None,
873
890
  key: Optional[str] = None,
874
891
  ) -> Element:
@@ -881,6 +898,9 @@ def Row(
881
898
  Args:
882
899
  *children: Child elements arranged left to right.
883
900
  style: Style dict (or list of dicts).
901
+ on_layout: Callback invoked with
902
+ ``{"x", "y", "width", "height"}`` after layout and on
903
+ frame changes.
884
904
  ref: Optional [`Ref`][pythonnative.Ref] for native-view access.
885
905
  key: Stable identity for keyed reconciliation.
886
906
 
@@ -891,6 +911,7 @@ def Row(
891
911
  "Row",
892
912
  *children,
893
913
  style=style,
914
+ on_layout=on_layout,
894
915
  ref=ref,
895
916
  key=key,
896
917
  _forced={"flex_direction": "row"},
@@ -1144,6 +1165,8 @@ def Pressable(
1144
1165
  on_press_out: Optional[Callable[[], None]] = None,
1145
1166
  pressed_opacity: float = 0.6,
1146
1167
  gestures: Optional[List[Any]] = None,
1168
+ hit_slop: Optional[Union[float, Dict[str, float]]] = None,
1169
+ on_layout: Optional[Callable[[Dict[str, float]], None]] = None,
1147
1170
  style: Union[StyleProp, Callable[[Dict[str, bool]], StyleProp]] = None,
1148
1171
  accessibility_label: Optional[str] = None,
1149
1172
  accessibility_hint: Optional[str] = None,
@@ -1174,6 +1197,14 @@ def Pressable(
1174
1197
  gestures: Optional list of gesture descriptors from
1175
1198
  `pythonnative.gestures` recognized natively on this view
1176
1199
  (pan / swipe / pinch / rotation / multi-tap).
1200
+ hit_slop: Extend the touch target beyond the view's bounds
1201
+ without changing layout: a uniform number of points, or a
1202
+ dict with any of ``top`` / ``left`` / ``bottom`` /
1203
+ ``right``. Essential for small touch targets (icons,
1204
+ chips) that should honor the 44-point guideline.
1205
+ on_layout: Callback invoked with
1206
+ ``{"x", "y", "width", "height"}`` after layout and on
1207
+ frame changes.
1177
1208
  style: Style dict applied to the wrapper, or a callable
1178
1209
  receiving the interaction state (``{"pressed": bool}``)
1179
1210
  and returning a style, re-evaluated on every press
@@ -1220,6 +1251,8 @@ def Pressable(
1220
1251
  on_press_out=on_press_out,
1221
1252
  pressed_opacity=pressed_opacity,
1222
1253
  gestures=gestures,
1254
+ hit_slop=hit_slop,
1255
+ on_layout=on_layout,
1223
1256
  accessibility_label=accessibility_label,
1224
1257
  accessibility_hint=accessibility_hint,
1225
1258
  accessibility_role=accessibility_role,
@@ -1240,6 +1273,8 @@ def Pressable(
1240
1273
  on_press_out=on_press_out,
1241
1274
  pressed_opacity=pressed_opacity,
1242
1275
  gestures=gestures,
1276
+ hit_slop=hit_slop,
1277
+ on_layout=on_layout,
1243
1278
  accessibility_label=accessibility_label,
1244
1279
  accessibility_hint=accessibility_hint,
1245
1280
  accessibility_role=accessibility_role,
@@ -2620,13 +2655,30 @@ def _KeyboardAvoidingContainer(**p: Any) -> Element:
2620
2655
  inside a full-height container).
2621
2656
  - ``"position"``: translates the whole container upward without
2622
2657
  resizing it (useful for pinned footers/toolbars).
2658
+ - ``"height"``: shrinks the container's own height by the shift.
2659
+ The resting height is captured via ``on_layout`` while the
2660
+ keyboard is hidden, so flex-sized containers work too.
2623
2661
  """
2624
- height = use_keyboard_height()
2662
+ keyboard = use_keyboard_height()
2663
+ base_height, set_base_height = use_state(0.0)
2625
2664
  behavior = p.get("behavior") or "padding"
2626
2665
  offset = float(p.get("keyboard_vertical_offset") or 0.0)
2627
- shift = max(0.0, height - offset) if height > 0 else 0.0
2666
+ shift = max(0.0, keyboard - offset) if keyboard > 0 else 0.0
2628
2667
  style: Dict[str, Any] = dict(p.get("style") or {})
2629
- if shift > 0:
2668
+ props: Dict[str, Any] = style
2669
+ if behavior == "height":
2670
+
2671
+ def _record_layout(frame: Dict[str, float]) -> None:
2672
+ if keyboard <= 0:
2673
+ measured = float(frame.get("height", 0.0))
2674
+ if measured > 0 and abs(measured - base_height) > 0.5:
2675
+ set_base_height(measured)
2676
+
2677
+ props = dict(style)
2678
+ props["on_layout"] = _record_layout
2679
+ if shift > 0 and base_height > 0:
2680
+ props["height"] = max(0.0, base_height - shift)
2681
+ elif shift > 0:
2630
2682
  if behavior == "position":
2631
2683
  transform = list(style.get("transform") or [])
2632
2684
  transform.append({"translate_y": -shift})
@@ -2634,12 +2686,12 @@ def _KeyboardAvoidingContainer(**p: Any) -> Element:
2634
2686
  else:
2635
2687
  style["padding_bottom"] = _numeric_edge_padding(style, "bottom") + shift
2636
2688
  children = p.get("children") or []
2637
- return Element("KeyboardAvoidingView", style, list(children))
2689
+ return Element("KeyboardAvoidingView", props, list(children))
2638
2690
 
2639
2691
 
2640
2692
  def KeyboardAvoidingView(
2641
2693
  *children: Element,
2642
- behavior: Literal["padding", "position"] = "padding",
2694
+ behavior: Literal["padding", "position", "height"] = "padding",
2643
2695
  keyboard_vertical_offset: float = 0.0,
2644
2696
  style: StyleProp = None,
2645
2697
  key: Optional[str] = None,
@@ -2656,8 +2708,10 @@ def KeyboardAvoidingView(
2656
2708
  Args:
2657
2709
  *children: Children rendered inside the avoiding container.
2658
2710
  behavior: ``"padding"`` (adds bottom padding, resizing the
2659
- content) or ``"position"`` (translates the container
2660
- upward without resizing).
2711
+ content), ``"position"`` (translates the container upward
2712
+ without resizing), or ``"height"`` (shrinks the
2713
+ container's height by the keyboard overlap, matching
2714
+ React Native's ``"height"`` behavior).
2661
2715
  keyboard_vertical_offset: Distance in layout units already
2662
2716
  covered by other UI (e.g. a nav bar); subtracted from the
2663
2717
  keyboard height before applying the shift.