@knitui/components 0.9.0 → 0.11.0

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 (153) hide show
  1. package/lib/commonjs/ActionIcon/ActionIcon.js +4 -2
  2. package/lib/commonjs/ActionIcon/ActionIcon.js.map +1 -1
  3. package/lib/commonjs/Affix/Affix.js +3 -1
  4. package/lib/commonjs/Affix/Affix.js.map +1 -1
  5. package/lib/commonjs/Button/Button.js +38 -3
  6. package/lib/commonjs/Button/Button.js.map +1 -1
  7. package/lib/commonjs/CloseButton/CloseButton.js +7 -0
  8. package/lib/commonjs/CloseButton/CloseButton.js.map +1 -1
  9. package/lib/commonjs/Modal/modal-base.js +4 -2
  10. package/lib/commonjs/Modal/modal-base.js.map +1 -1
  11. package/lib/commonjs/Pill/Pill.js +1 -1
  12. package/lib/commonjs/Popover/Popover.shared.js +3 -1
  13. package/lib/commonjs/Popover/Popover.shared.js.map +1 -1
  14. package/lib/commonjs/Portal/OverlayHost.js +147 -0
  15. package/lib/commonjs/Portal/OverlayHost.js.map +1 -0
  16. package/lib/commonjs/Portal/index.js +25 -0
  17. package/lib/commonjs/Portal/index.js.map +1 -1
  18. package/lib/commonjs/ScrollArea/ScrollArea.js +5 -0
  19. package/lib/commonjs/ScrollArea/ScrollArea.js.map +1 -1
  20. package/lib/commonjs/ScrollArea/ScrollArea.native.js +32 -0
  21. package/lib/commonjs/ScrollArea/ScrollArea.native.js.map +1 -1
  22. package/lib/commonjs/ScrollArea/ScrollArea.shared.js.map +1 -1
  23. package/lib/commonjs/SegmentedControl/SegmentedControl.js +7 -1
  24. package/lib/commonjs/SegmentedControl/SegmentedControl.js.map +1 -1
  25. package/lib/commonjs/Tabs/Tabs.js +8 -1
  26. package/lib/commonjs/Tabs/Tabs.js.map +1 -1
  27. package/lib/commonjs/Tooltip/Tooltip.js +3 -1
  28. package/lib/commonjs/Tooltip/Tooltip.js.map +1 -1
  29. package/lib/commonjs/VirtualList/VirtualList.js +7 -1
  30. package/lib/commonjs/VirtualList/VirtualList.js.map +1 -1
  31. package/lib/commonjs/VirtualList/VirtualList.shared.js.map +1 -1
  32. package/lib/commonjs/floating/platform.js +4 -1
  33. package/lib/commonjs/floating/platform.js.map +1 -1
  34. package/lib/commonjs/floating/platform.native.js +15 -5
  35. package/lib/commonjs/floating/platform.native.js.map +1 -1
  36. package/lib/commonjs/floating/use-position.js +9 -3
  37. package/lib/commonjs/floating/use-position.js.map +1 -1
  38. package/lib/commonjs/index.js +24 -0
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/internal/control-icon-size.js +5 -1
  41. package/lib/commonjs/internal/control-icon-size.js.map +1 -1
  42. package/lib/commonjs/internal/control-metrics.js +13 -9
  43. package/lib/commonjs/internal/control-metrics.js.map +1 -1
  44. package/lib/commonjs/internal/style-props.js +36 -6
  45. package/lib/commonjs/internal/style-props.js.map +1 -1
  46. package/lib/module/ActionIcon/ActionIcon.js +5 -3
  47. package/lib/module/ActionIcon/ActionIcon.js.map +1 -1
  48. package/lib/module/Affix/Affix.js +4 -2
  49. package/lib/module/Affix/Affix.js.map +1 -1
  50. package/lib/module/Button/Button.js +40 -5
  51. package/lib/module/Button/Button.js.map +1 -1
  52. package/lib/module/CloseButton/CloseButton.js +8 -1
  53. package/lib/module/CloseButton/CloseButton.js.map +1 -1
  54. package/lib/module/Modal/modal-base.js +5 -3
  55. package/lib/module/Modal/modal-base.js.map +1 -1
  56. package/lib/module/Pill/Pill.js +1 -1
  57. package/lib/module/Popover/Popover.shared.js +4 -2
  58. package/lib/module/Popover/Popover.shared.js.map +1 -1
  59. package/lib/module/Portal/OverlayHost.js +138 -0
  60. package/lib/module/Portal/OverlayHost.js.map +1 -0
  61. package/lib/module/Portal/index.js +5 -0
  62. package/lib/module/Portal/index.js.map +1 -1
  63. package/lib/module/ScrollArea/ScrollArea.js +5 -0
  64. package/lib/module/ScrollArea/ScrollArea.js.map +1 -1
  65. package/lib/module/ScrollArea/ScrollArea.native.js +33 -1
  66. package/lib/module/ScrollArea/ScrollArea.native.js.map +1 -1
  67. package/lib/module/ScrollArea/ScrollArea.shared.js.map +1 -1
  68. package/lib/module/SegmentedControl/SegmentedControl.js +9 -3
  69. package/lib/module/SegmentedControl/SegmentedControl.js.map +1 -1
  70. package/lib/module/Tabs/Tabs.js +9 -2
  71. package/lib/module/Tabs/Tabs.js.map +1 -1
  72. package/lib/module/Tooltip/Tooltip.js +4 -2
  73. package/lib/module/Tooltip/Tooltip.js.map +1 -1
  74. package/lib/module/VirtualList/VirtualList.js +7 -1
  75. package/lib/module/VirtualList/VirtualList.js.map +1 -1
  76. package/lib/module/VirtualList/VirtualList.shared.js.map +1 -1
  77. package/lib/module/floating/platform.js +4 -1
  78. package/lib/module/floating/platform.js.map +1 -1
  79. package/lib/module/floating/platform.native.js +15 -5
  80. package/lib/module/floating/platform.native.js.map +1 -1
  81. package/lib/module/floating/use-position.js +9 -3
  82. package/lib/module/floating/use-position.js.map +1 -1
  83. package/lib/module/index.js +1 -1
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/module/internal/control-icon-size.js +5 -1
  86. package/lib/module/internal/control-icon-size.js.map +1 -1
  87. package/lib/module/internal/control-metrics.js +13 -9
  88. package/lib/module/internal/control-metrics.js.map +1 -1
  89. package/lib/module/internal/style-props.js +33 -4
  90. package/lib/module/internal/style-props.js.map +1 -1
  91. package/lib/typescript/ActionIcon/ActionIcon.d.ts +5 -0
  92. package/lib/typescript/ActionIcon/ActionIcon.d.ts.map +1 -1
  93. package/lib/typescript/Affix/Affix.d.ts.map +1 -1
  94. package/lib/typescript/Button/Button.d.ts +6 -0
  95. package/lib/typescript/Button/Button.d.ts.map +1 -1
  96. package/lib/typescript/CloseButton/CloseButton.d.ts.map +1 -1
  97. package/lib/typescript/Input/shared.d.ts +3 -3
  98. package/lib/typescript/Modal/modal-base.d.ts.map +1 -1
  99. package/lib/typescript/Popover/Popover.shared.d.ts.map +1 -1
  100. package/lib/typescript/Portal/OverlayHost.d.ts +46 -0
  101. package/lib/typescript/Portal/OverlayHost.d.ts.map +1 -0
  102. package/lib/typescript/Portal/index.d.ts +6 -1
  103. package/lib/typescript/Portal/index.d.ts.map +1 -1
  104. package/lib/typescript/Portal/types.d.ts +10 -0
  105. package/lib/typescript/Portal/types.d.ts.map +1 -1
  106. package/lib/typescript/ScrollArea/ScrollArea.d.ts.map +1 -1
  107. package/lib/typescript/ScrollArea/ScrollArea.native.d.ts.map +1 -1
  108. package/lib/typescript/ScrollArea/ScrollArea.shared.d.ts +20 -0
  109. package/lib/typescript/ScrollArea/ScrollArea.shared.d.ts.map +1 -1
  110. package/lib/typescript/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  111. package/lib/typescript/Tabs/Tabs.d.ts.map +1 -1
  112. package/lib/typescript/Tooltip/Tooltip.d.ts.map +1 -1
  113. package/lib/typescript/VirtualList/VirtualList.d.ts.map +1 -1
  114. package/lib/typescript/VirtualList/VirtualList.shared.d.ts +9 -0
  115. package/lib/typescript/VirtualList/VirtualList.shared.d.ts.map +1 -1
  116. package/lib/typescript/floating/platform.d.ts +1 -1
  117. package/lib/typescript/floating/platform.d.ts.map +1 -1
  118. package/lib/typescript/floating/platform.native.d.ts +7 -1
  119. package/lib/typescript/floating/platform.native.d.ts.map +1 -1
  120. package/lib/typescript/floating/use-position.d.ts.map +1 -1
  121. package/lib/typescript/index.d.ts +1 -1
  122. package/lib/typescript/index.d.ts.map +1 -1
  123. package/lib/typescript/internal/control-icon-size.d.ts.map +1 -1
  124. package/lib/typescript/internal/control-metrics.d.ts +13 -9
  125. package/lib/typescript/internal/control-metrics.d.ts.map +1 -1
  126. package/lib/typescript/internal/style-props.d.ts +23 -4
  127. package/lib/typescript/internal/style-props.d.ts.map +1 -1
  128. package/package.json +4 -4
  129. package/src/ActionIcon/ActionIcon.tsx +10 -3
  130. package/src/Affix/Affix.tsx +4 -2
  131. package/src/Button/Button.tsx +69 -19
  132. package/src/CloseButton/CloseButton.tsx +7 -1
  133. package/src/Modal/modal-base.tsx +5 -3
  134. package/src/Pill/Pill.tsx +1 -1
  135. package/src/Popover/Popover.shared.tsx +4 -2
  136. package/src/Portal/OverlayHost.tsx +141 -0
  137. package/src/Portal/index.ts +11 -1
  138. package/src/Portal/types.ts +11 -0
  139. package/src/ScrollArea/ScrollArea.native.tsx +33 -2
  140. package/src/ScrollArea/ScrollArea.shared.ts +23 -0
  141. package/src/ScrollArea/ScrollArea.tsx +5 -0
  142. package/src/SegmentedControl/SegmentedControl.tsx +8 -2
  143. package/src/Tabs/Tabs.tsx +9 -1
  144. package/src/Tooltip/Tooltip.tsx +4 -2
  145. package/src/VirtualList/VirtualList.shared.ts +12 -0
  146. package/src/VirtualList/VirtualList.tsx +6 -0
  147. package/src/floating/platform.native.ts +13 -4
  148. package/src/floating/platform.ts +3 -0
  149. package/src/floating/use-position.tsx +13 -3
  150. package/src/index.ts +5 -0
  151. package/src/internal/control-icon-size.ts +5 -1
  152. package/src/internal/control-metrics.ts +13 -9
  153. package/src/internal/style-props.ts +32 -4
@@ -9,7 +9,7 @@ import { ControlIconProvider } from "../internal/ControlIconProvider";
9
9
  import { type GradientValue, useGradient } from "../internal/gradient";
10
10
  import { usePressScale } from "../internal/motion";
11
11
  import { renderTextChild } from "../internal/render-text-child";
12
- import { fontSizePassthroughVariant } from "../internal/style-props";
12
+ import { fontSizePassthroughVariant, WEB_BUTTON_PROPS } from "../internal/style-props";
13
13
  import { slotStyles, type SlotStyles } from "../internal/styles";
14
14
 
15
15
  const CloseButtonFrame = styled(ActionIcon.Frame, {
@@ -123,6 +123,12 @@ const CloseButtonComponent = CloseButtonFrame.styleable<CloseButtonProps>(
123
123
  {...press}
124
124
  {...grad.frameProps}
125
125
  {...rest}
126
+ aria-disabled={rest.disabled || undefined}
127
+ // A real focusable `<button>` on web, like `ActionIcon` (whose frame this
128
+ // is). Without it CloseButton was a `<div role="button">`: never a tab
129
+ // stop, so the inherited focus ring could not fire and every dismiss ✕
130
+ // in a consumer app was mouse-only.
131
+ {...WEB_BUTTON_PROPS}
126
132
  >
127
133
  {grad.layer}
128
134
  {icon ?? (
@@ -8,7 +8,7 @@ import type { CloseButtonProps } from "../CloseButton";
8
8
  import { type MotionPreset, type MotionPresetName, useMotionPreset } from "../internal/motion";
9
9
  import { slotStyles, type SlotStyles } from "../internal/styles";
10
10
  import { Overlay, type OverlayProps } from "../Overlay";
11
- import { Portal } from "../Portal";
11
+ import { Portal, useOverlayHost } from "../Portal";
12
12
  import { ModalBaseInner } from "./modal-base-inner";
13
13
 
14
14
  /**
@@ -195,6 +195,8 @@ export function ModalBase(props: ModalBaseProps) {
195
195
  // the active theme across the portal boundary (on web the content's DOM moves
196
196
  // into the root host, losing any nested `<Theme>` ancestor's class).
197
197
  const themeName = useThemeName();
198
+ // The nearest scoped `OverlayHost` (a native modal screen), else "root".
199
+ const overlayHost = useOverlayHost();
198
200
 
199
201
  // Trap keyboard focus within the content while opened; the returned ref
200
202
  // attaches to the positioning layer. `useFocusTrap` is itself a no-op on
@@ -298,7 +300,7 @@ export function ModalBase(props: ModalBaseProps) {
298
300
  // `keepMounted` stays in the tree and toggles `display` — entrance animates but
299
301
  // there is no exit (the node never leaves), mirroring `Dialog`/`Popover`.
300
302
  if (keepMounted) {
301
- return <Portal hostName={withinPortal ? "root" : undefined}>{layer}</Portal>;
303
+ return <Portal hostName={withinPortal ? overlayHost : undefined}>{layer}</Portal>;
302
304
  }
303
305
 
304
306
  // Default: `AnimatePresence` holds the whole layer (scrim + content) in the tree
@@ -310,7 +312,7 @@ export function ModalBase(props: ModalBaseProps) {
310
312
  return (
311
313
  <AnimatePresence>
312
314
  {opened ? (
313
- <Portal key="modal-layer" hostName={withinPortal ? "root" : undefined}>
315
+ <Portal key="modal-layer" hostName={withinPortal ? overlayHost : undefined}>
314
316
  {layer}
315
317
  </Portal>
316
318
  ) : null}
package/src/Pill/Pill.tsx CHANGED
@@ -74,7 +74,7 @@ const PillFrame = styled(Box, {
74
74
  size: controlGapVariant,
75
75
  radius: radiusVariant,
76
76
  disabled: {
77
- true: { opacity: 0.5, pointerEvents: "none" },
77
+ true: { opacity: 0.6, pointerEvents: "none" },
78
78
  },
79
79
  } as const,
80
80
 
@@ -38,7 +38,7 @@ import { useOverlayChrome } from "../internal/overlay-chrome";
38
38
  import { shadowVariant } from "../internal/style-props";
39
39
  import { type SlotStyles } from "../internal/styles";
40
40
  import { type OverlayProps } from "../Overlay";
41
- import { Portal } from "../Portal";
41
+ import { Portal, useOverlayHost } from "../Portal";
42
42
  import {
43
43
  type OverlayTransitionConfig,
44
44
  useOverlayTransition,
@@ -712,6 +712,8 @@ export const PopoverDropdownView = PopoverDropdownFrame.styleable<PopoverDropdow
712
712
  // variables ($background/$color/…) would otherwise resolve to the root theme.
713
713
  // (Mirrors `@tamagui/portal` wrapping its portal in `<TamaguiRoot theme={…}>`.)
714
714
  const themeName = useThemeName();
715
+ // The nearest scoped `OverlayHost` (a native modal screen), else "root".
716
+ const overlayHost = useOverlayHost();
715
717
  // Enter/exit animation via the shared `Transition` engine. It owns the lazy
716
718
  // mount/unmount (so the dropdown now animates OUT before unmounting, not just
717
719
  // in) and honours reduced motion (duration collapses to 0). Positioning,
@@ -739,7 +741,7 @@ export const PopoverDropdownView = PopoverDropdownFrame.styleable<PopoverDropdow
739
741
  const transitionStyle = waitingForPosition ? { ...t.style, opacity: 0 } : t.style;
740
742
 
741
743
  return (
742
- <Portal hostName={ctx.withinPortal ? "root" : undefined}>
744
+ <Portal hostName={ctx.withinPortal ? overlayHost : undefined}>
743
745
  <Theme name={themeName}>
744
746
  {/* Keep the scrim and the dropdown frame as direct siblings (rather
745
747
  than hoisting the scrim above `<Theme>`) so their z-indices compare
@@ -0,0 +1,141 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, View } from "react-native";
3
+ import { PortalHost } from "react-native-teleport";
4
+
5
+ import type { OverlayHostProps } from "./types";
6
+
7
+ /** The full-screen host `@knitui/core`'s `<Provider>` mounts (via `PortalProvider`). */
8
+ export const ROOT_OVERLAY_HOST = "root";
9
+
10
+ type OverlayHostContextValue = {
11
+ /** Host name the kit's overlays teleport into. */
12
+ name: string;
13
+ /** Nesting depth: 0 for the root host, +1 per enclosing {@link OverlayHost}. */
14
+ depth: number;
15
+ /**
16
+ * The view wrapping the scoped host, so the native floating engine can measure
17
+ * the host's window origin. `null` for the root host (it sits at the window
18
+ * origin by construction).
19
+ */
20
+ frameRef: React.RefObject<View | null> | null;
21
+ };
22
+
23
+ const ROOT_VALUE: OverlayHostContextValue = { name: ROOT_OVERLAY_HOST, depth: 0, frameRef: null };
24
+
25
+ const OverlayHostContext = React.createContext<OverlayHostContextValue>(ROOT_VALUE);
26
+
27
+ // ---------------------------------------------------------------------------
28
+ // Mounted-host registry — backs `useTopmostOverlayHost`. Module-level because
29
+ // the question it answers ("which host is on top right now?") is asked by
30
+ // app-global singletons (a toast layer) that sit OUTSIDE every scoped host.
31
+ // ---------------------------------------------------------------------------
32
+
33
+ type Entry = { name: string; depth: number; seq: number };
34
+
35
+ let entries: Entry[] = [];
36
+ let seq = 0;
37
+ const listeners = new Set<() => void>();
38
+
39
+ function subscribe(listener: () => void): () => void {
40
+ listeners.add(listener);
41
+ return () => {
42
+ listeners.delete(listener);
43
+ };
44
+ }
45
+
46
+ /** Deepest host wins; among equals, the most recently mounted one. */
47
+ function getTopmost(): string {
48
+ let top: Entry | undefined;
49
+ for (const e of entries) {
50
+ if (!top || e.depth > top.depth || (e.depth === top.depth && e.seq > top.seq)) top = e;
51
+ }
52
+ return top?.name ?? ROOT_OVERLAY_HOST;
53
+ }
54
+
55
+ function register(name: string, depth: number): () => void {
56
+ const entry: Entry = { name, depth, seq: ++seq };
57
+ entries = [...entries, entry];
58
+ listeners.forEach((l) => l());
59
+ return () => {
60
+ entries = entries.filter((e) => e !== entry);
61
+ listeners.forEach((l) => l());
62
+ };
63
+ }
64
+
65
+ /**
66
+ * A **scoped** portal host. Mounts a `PortalHost` named `name` over its
67
+ * children (an absolute fill of the parent) and tells every kit overlay rendered
68
+ * inside it — `Popover`/`Menu`/`Combobox`/date-picker dropdowns, `Tooltip`,
69
+ * `Modal`/`Drawer`, `Affix`, a modal `Sheet` — to teleport there instead of into
70
+ * the app-wide `"root"` host.
71
+ *
72
+ * Use it to wrap a screen that the platform presents in its own native container
73
+ * (an iOS `formSheet` / `fullScreenModal`, an Android dialog): the root host
74
+ * lives in the window underneath, so without a scope those overlays would draw
75
+ * BEHIND the modal.
76
+ *
77
+ * Nothing changes outside an `OverlayHost` — overlays keep using `"root"`.
78
+ * Names must be unique among mounted hosts (a route key is a good suffix).
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * <OverlayHost name={`modal:${route.key}`}>
83
+ * <FiltersScreen />
84
+ * </OverlayHost>
85
+ * ```
86
+ */
87
+ export function OverlayHost({ name, children }: OverlayHostProps) {
88
+ const parent = React.useContext(OverlayHostContext);
89
+ const depth = parent.depth + 1;
90
+ const frameRef = React.useRef<View>(null);
91
+
92
+ const value = React.useMemo<OverlayHostContextValue>(
93
+ () => ({ name, depth, frameRef }),
94
+ [name, depth],
95
+ );
96
+
97
+ React.useEffect(() => register(name, depth), [name, depth]);
98
+
99
+ return (
100
+ <OverlayHostContext.Provider value={value}>
101
+ {children}
102
+ {/* After the children, so teleported overlays paint above the screen.
103
+ `box-none`: the empty host must never swallow touches meant for the
104
+ screen beneath it. `collapsable={false}` keeps the wrapper a real
105
+ native view so it can be measured. */}
106
+ <View ref={frameRef} collapsable={false} style={styles.frame}>
107
+ <PortalHost name={name} style={StyleSheet.absoluteFill} />
108
+ </View>
109
+ </OverlayHostContext.Provider>
110
+ );
111
+ }
112
+
113
+ const styles = StyleSheet.create({
114
+ frame: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0, pointerEvents: "box-none" },
115
+ });
116
+
117
+ /**
118
+ * The host name overlays at this point in the tree should teleport into:
119
+ * the nearest {@link OverlayHost}'s, else `"root"`. The kit's own overlays read
120
+ * it; use it for a custom `<Portal hostName={useOverlayHost()}>`.
121
+ */
122
+ export function useOverlayHost(): string {
123
+ return React.useContext(OverlayHostContext).name;
124
+ }
125
+
126
+ /**
127
+ * The name of the top-most MOUNTED {@link OverlayHost} anywhere in the app, else
128
+ * `"root"`. For app-global overlays rendered OUTSIDE any scope — e.g. one toast
129
+ * layer near the app root — that should still show above whatever modal is up.
130
+ */
131
+ export function useTopmostOverlayHost(): string {
132
+ return React.useSyncExternalStore(subscribe, getTopmost, getTopmost);
133
+ }
134
+
135
+ /**
136
+ * @internal The scoped host's measurable frame (or `null` under the root host),
137
+ * for the native floating engine's container-origin math.
138
+ */
139
+ export function useOverlayHostFrame(): React.RefObject<View | null> | null {
140
+ return React.useContext(OverlayHostContext).frameRef;
141
+ }
@@ -1,4 +1,10 @@
1
- export type { PortalHostProps, PortalProps, PortalProviderProps } from "./types";
1
+ export {
2
+ OverlayHost,
3
+ ROOT_OVERLAY_HOST,
4
+ useOverlayHost,
5
+ useTopmostOverlayHost,
6
+ } from "./OverlayHost";
7
+ export type { OverlayHostProps, PortalHostProps, PortalProps, PortalProviderProps } from "./types";
2
8
  /**
3
9
  * Portal system — a thin re-export of `react-native-teleport`.
4
10
  *
@@ -14,6 +20,10 @@ export type { PortalHostProps, PortalProps, PortalProviderProps } from "./types"
14
20
  * to render inline in place (the no-teleport fallback).
15
21
  * - Add extra mount points with `<PortalHost name="…" />` and target them by name.
16
22
  * - `usePortal(hostName)` exposes `{ isHostAvailable, removePortal }`.
23
+ * - Wrap a natively presented modal screen in `<OverlayHost name="…">` so the
24
+ * kit's overlays inside it teleport into THAT host rather than `"root"` (which
25
+ * lives in the window underneath the modal). They read the host through
26
+ * `useOverlayHost()`; `useTopmostOverlayHost()` serves app-global layers.
17
27
  *
18
28
  * @see https://kirillzyusko.github.io/react-native-teleport
19
29
  */
@@ -45,3 +45,14 @@ export type PortalHostProps = {
45
45
  export type PortalProviderProps = {
46
46
  children: React.ReactNode;
47
47
  };
48
+
49
+ /**
50
+ * Props for {@link OverlayHost} — a scoped portal host that kit overlays inside
51
+ * it teleport into instead of the app-wide `"root"` host.
52
+ */
53
+ export type OverlayHostProps = {
54
+ /** Unique host name (among mounted hosts). Overlays inside target it automatically. */
55
+ name: string;
56
+ /** The subtree whose overlays should draw into this host. */
57
+ children?: React.ReactNode;
58
+ };
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { type LayoutChangeEvent, type ScrollView } from "react-native";
2
+ import { type LayoutChangeEvent, RefreshControl, type ScrollView } from "react-native";
3
3
  import { Gesture, GestureDetector } from "react-native-gesture-handler";
4
4
  import Animated, {
5
5
  cancelAnimation,
@@ -12,11 +12,12 @@ import Animated, {
12
12
  } from "react-native-reanimated";
13
13
  import { runOnJS } from "react-native-worklets";
14
14
 
15
- import { styled, type TamaguiElement, withStaticProperties } from "@knitui/core";
15
+ import { styled, type TamaguiElement, useTheme, withStaticProperties } from "@knitui/core";
16
16
  import { useDebouncedCallback, useMove, useReducedMotion } from "@knitui/hooks";
17
17
 
18
18
  import { Box, type BoxProps } from "../Box";
19
19
  import { useReducedTransition } from "../internal/motion";
20
+ import { resolveThemeColor } from "../internal/resolve-theme-color";
20
21
  import { animateOnlyProps } from "../internal/style-props";
21
22
  import { slotStyles } from "../internal/styles";
22
23
  import {
@@ -214,6 +215,22 @@ const ScrollAreaShadow = styled(Box, {
214
215
  export interface ScrollAreaProps
215
216
  extends Omit<BoxProps, "type" | "shadowColor">, ScrollAreaOwnProps {}
216
217
 
218
+ /**
219
+ * RN `RefreshControl` tinted from the active theme. A component of its own so only
220
+ * an area that actually refreshes subscribes to the theme. Forwards every prop:
221
+ * Android's `ScrollView` clones its `refreshControl` with a `style` and the
222
+ * scroller itself as `children`.
223
+ */
224
+ function ThemedRefreshControl({
225
+ color,
226
+ ...props
227
+ }: React.ComponentProps<typeof RefreshControl> & { color: string }) {
228
+ const theme = useTheme();
229
+ const resolved = resolveThemeColor(theme, color);
230
+ // iOS paints `tintColor`; Android paints the spinner from `colors`.
231
+ return <RefreshControl {...props} tintColor={resolved} colors={[resolved]} />;
232
+ }
233
+
217
234
  /** Internal: `ScrollArea.Autosize` forwards this so the component uses the native
218
235
  * `ScrollView` path (content-driven sizing) instead of the Pan engine. */
219
236
  type InternalProps = ScrollAreaProps & { autosize?: boolean };
@@ -279,6 +296,9 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
279
296
  // keyboardScrolling / keyStep are web-only; accepted and ignored here.
280
297
  keyboardScrolling: _keyboardScrolling,
281
298
  keyStep: _keyStep,
299
+ onRefresh,
300
+ refreshing = false,
301
+ refreshColor = "$color10",
282
302
  // Internal: Autosize uses the native ScrollView path.
283
303
  autosize = false,
284
304
  children,
@@ -879,6 +899,17 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
879
899
  scrollEventThrottle: 16,
880
900
  nestedScrollEnabled: true,
881
901
  keyboardShouldPersistTaps,
902
+ ...(onRefresh
903
+ ? {
904
+ refreshControl: (
905
+ <ThemedRefreshControl
906
+ refreshing={refreshing}
907
+ onRefresh={onRefresh}
908
+ color={refreshColor}
909
+ />
910
+ ),
911
+ }
912
+ : null),
882
913
  ...(mergedViewportProps as object),
883
914
  };
884
915
 
@@ -184,6 +184,29 @@ export interface ScrollAreaOwnProps {
184
184
  */
185
185
  keyboardShouldPersistTaps?: boolean | "always" | "never" | "handled";
186
186
 
187
+ /**
188
+ * Called when the reader pulls the viewport down past its top edge. Setting it
189
+ * mounts the platform refresh control on the native scroller. Native only, and
190
+ * only on a single-axis area (`scrollbars="y"` / `"x"` or `ScrollArea.Autosize`):
191
+ * the two-axis Pan engine has no native scroller to attach it to. Ignored on web,
192
+ * where an inner scroller has no pull gesture.
193
+ */
194
+ onRefresh?: () => void;
195
+
196
+ /**
197
+ * Whether the refresh spinner is showing. Controlled: set it `true` when
198
+ * {@link onRefresh} starts work and back to `false` once it settles.
199
+ * @default false
200
+ */
201
+ refreshing?: boolean;
202
+
203
+ /**
204
+ * Spinner colour — a theme token (`"$color10"`) or any concrete colour. iOS
205
+ * paints it as `tintColor`, Android as the spinner `colors`.
206
+ * @default "$color10"
207
+ */
208
+ refreshColor?: string;
209
+
187
210
  /** Props spread onto each scrollbar track (style the rail). */
188
211
  scrollbarProps?: Partial<BoxProps>;
189
212
 
@@ -252,6 +252,11 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
252
252
  // Native-only (RN `ScrollView` tap handling); accepted and ignored here so
253
253
  // it isn't spread onto the DOM viewport via `...rest`.
254
254
  keyboardShouldPersistTaps: _keyboardShouldPersistTaps,
255
+ // Pull-to-refresh is native only: an inner web scroller has no pull
256
+ // gesture. Accepted and ignored so they aren't spread onto the DOM.
257
+ onRefresh: _onRefresh,
258
+ refreshing: _refreshing,
259
+ refreshColor: _refreshColor,
255
260
  children,
256
261
  ...rest
257
262
  } = props;
@@ -5,12 +5,13 @@ import { useUncontrolled } from "@knitui/hooks";
5
5
 
6
6
  import { Box, type BoxProps } from "../Box";
7
7
  import { HiddenInput } from "../internal/hidden-input";
8
- import { useReducedTransition } from "../internal/motion";
8
+ import { usePressScale, useReducedTransition } from "../internal/motion";
9
9
  import {
10
10
  animateOnlyProps,
11
11
  controlFontVariant,
12
12
  controlVariant,
13
13
  focusRingStyle,
14
+ pressScaleStyle,
14
15
  radiusVariant,
15
16
  shadowVariant,
16
17
  type SizeKey,
@@ -101,6 +102,8 @@ const SegmentedControlControl = styled(Box, {
101
102
  backgroundColor: "transparent",
102
103
  zIndex: 1,
103
104
  ...focusRingStyle,
105
+ // The shared control press dip (see Tabs) — a segment had no press state at all.
106
+ ...pressScaleStyle,
104
107
 
105
108
  variants: {
106
109
  size: {
@@ -123,7 +126,7 @@ const SegmentedControlControl = styled(Box, {
123
126
  true: { flex: 1 },
124
127
  },
125
128
  itemDisabled: {
126
- true: { opacity: 0.45, pointerEvents: "none", ...webCursor("default") },
129
+ true: { opacity: 0.6, pointerEvents: "none", ...webCursor("default") },
127
130
  },
128
131
  } as const,
129
132
 
@@ -250,6 +253,8 @@ const SegmentedControlBase = SegmentedControlRoot.styleable<SegmentedControlProp
250
253
  ...rest
251
254
  } = props;
252
255
 
256
+ // Reduced-motion-aware easing for each segment's press dip.
257
+ const press = usePressScale();
253
258
  const indicatorTransition = useReducedTransition(
254
259
  timedTransition(transitionDuration, transitionTimingFunction),
255
260
  );
@@ -388,6 +393,7 @@ const SegmentedControlBase = SegmentedControlRoot.styleable<SegmentedControlProp
388
393
  />
389
394
  ) : null}
390
395
  <SegmentedControlControl
396
+ {...press}
391
397
  size={size}
392
398
  active={active}
393
399
  grow={fullWidth}
package/src/Tabs/Tabs.tsx CHANGED
@@ -5,11 +5,13 @@ import { useId, useUncontrolled } from "@knitui/hooks";
5
5
 
6
6
  import { Box, type BoxProps } from "../Box";
7
7
  import { controlMetrics as M } from "../internal/control-metrics";
8
+ import { usePressScale } from "../internal/motion";
8
9
  import { renderTextChild } from "../internal/render-text-child";
9
10
  import {
10
11
  controlFontVariant,
11
12
  controlVariant,
12
13
  focusRingStyle,
14
+ pressScaleStyle,
13
15
  radiusVariant,
14
16
  type SizeKey,
15
17
  webCursor,
@@ -246,6 +248,10 @@ const TabTabFrame = styled(Box, {
246
248
  ...webCursor("pointer"),
247
249
  userSelect: "none",
248
250
  position: "relative",
251
+ // The press dip every other kit control has (Button, ActionIcon, Chip). A tab
252
+ // swapped its colour and nothing else, so it was the one control whose press
253
+ // didn't feel like a press. Eased by `usePressScale()` at render.
254
+ ...pressScaleStyle,
249
255
 
250
256
  variants: {
251
257
  variant: {
@@ -292,7 +298,7 @@ const TabTabFrame = styled(Box, {
292
298
  xxl: { ...controlVariant.xxl, gap: M.xxl.gap },
293
299
  },
294
300
  disabled: {
295
- true: { opacity: 0.4, pointerEvents: "none" },
301
+ true: { opacity: 0.6, pointerEvents: "none" },
296
302
  },
297
303
  } as const,
298
304
 
@@ -382,6 +388,7 @@ export interface TabsTabProps extends Omit<
382
388
  }
383
389
 
384
390
  const TabsTab = TabTabFrame.styleable<TabsTabProps>(function TabsTab(props, ref) {
391
+ const press = usePressScale();
385
392
  const { value, children, leftSection, rightSection, disabled, ...rest } = props;
386
393
  const ctx = React.useContext(TabsContext);
387
394
  const s = useTabsSlots();
@@ -453,6 +460,7 @@ const TabsTab = TabTabFrame.styleable<TabsTabProps>(function TabsTab(props, ref)
453
460
  return (
454
461
  <TabTabFrame
455
462
  ref={ref}
463
+ {...press}
456
464
  variant={ctx.variant}
457
465
  size={ctx.size}
458
466
  active={isActive}
@@ -33,7 +33,7 @@ import { type MotionPresetName } from "../internal/motion";
33
33
  import { useOverlayChrome } from "../internal/overlay-chrome";
34
34
  import { radiusVariant, shadowVariant } from "../internal/style-props";
35
35
  import { type SlotStyles } from "../internal/styles";
36
- import { Portal } from "../Portal";
36
+ import { Portal, useOverlayHost } from "../Portal";
37
37
  import { Text } from "../Text";
38
38
  import {
39
39
  type OverlayTransitionConfig,
@@ -478,6 +478,8 @@ const TooltipBase = TooltipLabelFrame.styleable<TooltipProps>(function Tooltip(p
478
478
  );
479
479
 
480
480
  const themeName = useThemeName();
481
+ // The nearest scoped `OverlayHost` (a native modal screen), else "root".
482
+ const overlayHost = useOverlayHost();
481
483
  // Enter/exit animation via the shared `Transition` engine (honours reduced
482
484
  // motion; label now also animates OUT before unmounting).
483
485
  const t = useOverlayTransition({ mounted: open, keepMounted, animation, ...transitionProps });
@@ -574,7 +576,7 @@ const TooltipBase = TooltipLabelFrame.styleable<TooltipProps>(function Tooltip(p
574
576
  const dropdownSlot = s.get("dropdown");
575
577
 
576
578
  const labelNode = !t.rendered ? null : (
577
- <Portal hostName={withinPortal ? "root" : undefined}>
579
+ <Portal hostName={withinPortal ? overlayHost : undefined}>
578
580
  <Theme name={themeName}>
579
581
  <TooltipLabelFrame
580
582
  ref={floatingRef}
@@ -213,6 +213,18 @@ export interface VirtualListOwnProps<T> {
213
213
  */
214
214
  onRenderedRangeChange?: (range: { start: number; end: number }) => void;
215
215
 
216
+ /* ---- pull to refresh --------------------------------------------------- */
217
+
218
+ /**
219
+ * Pull-to-refresh on the list's scroller — forwarded to the underlying
220
+ * `ScrollArea`'s `onRefresh`. Native only; ignored on web.
221
+ */
222
+ onRefresh?: () => void;
223
+ /** Whether the refresh spinner is showing (controlled). @default false */
224
+ refreshing?: boolean;
225
+ /** Spinner colour — a theme token or concrete colour. @default "$color10" */
226
+ refreshColor?: string;
227
+
216
228
  /* ---- chrome slots ------------------------------------------------------ */
217
229
 
218
230
  /** Rendered once above the first row (scrolls with content). */
@@ -275,6 +275,9 @@ function VirtualListInner<T>(
275
275
  onStartReachedThreshold = DEFAULT_START_REACHED_THRESHOLD,
276
276
  maintainVisibleContentPosition = false,
277
277
  onRenderedRangeChange,
278
+ onRefresh,
279
+ refreshing,
280
+ refreshColor,
278
281
  ListHeaderComponent,
279
282
  ListFooterComponent,
280
283
  ListEmptyComponent,
@@ -791,6 +794,9 @@ function VirtualListInner<T>(
791
794
  height="100%"
792
795
  width="100%"
793
796
  onScrollPositionChange={handleScroll}
797
+ onRefresh={onRefresh}
798
+ refreshing={refreshing}
799
+ refreshColor={refreshColor}
794
800
  // `scrollArea` slot is a `Partial<BoxProps>`; spread through an index
795
801
  // signature so it doesn't collide with ScrollArea's narrowed `shadowColor`.
796
802
  {...(scrollAreaSlot as Record<string, unknown>)}
@@ -142,23 +142,32 @@ export function getViewport(): Rect {
142
142
  * consumer reports it from `onLayout` — reliable and timely); otherwise it's
143
143
  * measured as a fallback. The container origin accounts for the Android status
144
144
  * bar so the window-space placement lands correctly in the full-screen host.
145
+ *
146
+ * `hostNode` is a scoped `OverlayHost`'s frame, when the floating element
147
+ * teleports into one instead of the root host. That host is NOT at the window
148
+ * origin (an iOS `formSheet` starts below the status bar), so its origin is
149
+ * measured in the same window space as the reference — which also makes the
150
+ * Android status-bar correction unnecessary for it.
145
151
  */
146
152
  export async function measure(
147
153
  referenceNode: TamaguiElement | null,
148
154
  floatingNode: TamaguiElement | null,
149
155
  _strategy: Strategy,
150
156
  floatingSize?: Dimensions | null,
157
+ hostNode?: unknown,
151
158
  ): Promise<MeasureResult> {
152
159
  const hasSize =
153
160
  !!floatingSize && isFiniteNumber(floatingSize.width) && isFiniteNumber(floatingSize.height);
154
161
 
155
- const [reference, floating] = await Promise.all([
162
+ const [reference, floating, host] = await Promise.all([
156
163
  measureWindowRect(referenceNode),
157
164
  hasSize ? Promise.resolve(null) : measureWindowRect(floatingNode),
165
+ hostNode ? measureWindowRect(hostNode as TamaguiElement) : Promise.resolve(null),
158
166
  ]);
167
+ const containerOrigin = host ? { x: host.x, y: host.y } : getHostOrigin();
159
168
 
160
169
  if (!reference) {
161
- return { reference: null, floating: null, containerOrigin: getHostOrigin() };
170
+ return { reference: null, floating: null, containerOrigin };
162
171
  }
163
172
 
164
173
  const size: Dimensions | null = hasSize
@@ -168,10 +177,10 @@ export async function measure(
168
177
  : null;
169
178
 
170
179
  if (!size) {
171
- return { reference: null, floating: null, containerOrigin: getHostOrigin() };
180
+ return { reference: null, floating: null, containerOrigin };
172
181
  }
173
182
 
174
- return { reference, floating: size, containerOrigin: getHostOrigin() };
183
+ return { reference, floating: size, containerOrigin };
175
184
  }
176
185
 
177
186
  /**
@@ -54,6 +54,9 @@ export function measure(
54
54
  // Web reads the floating size synchronously from the DOM, so the `onLayout`
55
55
  // size hint the native platform uses is accepted for signature parity only.
56
56
  _floatingSize?: Dimensions | null,
57
+ // A scoped `OverlayHost` frame (native only): web derives the container origin
58
+ // from the floating element's own `offsetParent`, wherever it was teleported.
59
+ _hostNode?: unknown,
57
60
  ): Promise<MeasureResult> {
58
61
  const reference = asHTMLElement(referenceNode);
59
62
  const floating = asHTMLElement(floatingNode);
@@ -11,6 +11,7 @@ import * as React from "react";
11
11
 
12
12
  import type { TamaguiElement } from "@knitui/core";
13
13
 
14
+ import { useOverlayHostFrame } from "../Portal/OverlayHost";
14
15
  import {
15
16
  computePosition,
16
17
  type Dimensions,
@@ -135,10 +136,13 @@ export function usePosition(props: UsePositionProps): UsePositionReturn {
135
136
  // final layout's measurement is never dropped).
136
137
  const measuringRef = React.useRef(false);
137
138
  const pendingRef = React.useRef(false);
139
+ // A scoped `OverlayHost`'s frame when this overlay renders inside one (native
140
+ // measures its window origin); `null` under the root host.
141
+ const hostFrameRef = useOverlayHostFrame();
138
142
 
139
143
  // Latest config, read by the stable `update` callback so it never goes stale.
140
- const latest = React.useRef({ placement, strategy, middleware });
141
- latest.current = { placement, strategy, middleware };
144
+ const latest = React.useRef({ placement, strategy, middleware, hostFrameRef });
145
+ latest.current = { placement, strategy, middleware, hostFrameRef };
142
146
 
143
147
  const [data, setData] = React.useState<PositionData>({
144
148
  x: null,
@@ -178,7 +182,13 @@ export function usePosition(props: UsePositionProps): UsePositionReturn {
178
182
  pendingRef.current = false;
179
183
 
180
184
  const cfg = latest.current;
181
- void measure(reference, floating, cfg.strategy, floatingSizeRef.current)
185
+ void measure(
186
+ reference,
187
+ floating,
188
+ cfg.strategy,
189
+ floatingSizeRef.current,
190
+ cfg.hostFrameRef?.current ?? null,
191
+ )
182
192
  .then((m) => {
183
193
  if (!mountedRef.current || !m.reference || !m.floating) return;
184
194
  // Wait for real layout: a 0×0 box means the element hasn't laid out yet,