@knitui/components 1.0.0 → 1.1.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 (167) hide show
  1. package/lib/commonjs/ActionIcon/ActionIcon.js +1 -1
  2. package/lib/commonjs/ActionIcon/ActionIcon.js.map +1 -1
  3. package/lib/commonjs/Affix/Affix.js +1 -1
  4. package/lib/commonjs/Affix/Affix.js.map +1 -1
  5. package/lib/commonjs/Alert/Alert.js +1 -1
  6. package/lib/commonjs/Alert/Alert.js.map +1 -1
  7. package/lib/commonjs/Avatar/Avatar.js +1 -1
  8. package/lib/commonjs/Avatar/Avatar.js.map +1 -1
  9. package/lib/commonjs/Badge/Badge.js +1 -1
  10. package/lib/commonjs/Badge/Badge.js.map +1 -1
  11. package/lib/commonjs/Button/Button.js +1 -1
  12. package/lib/commonjs/Button/Button.js.map +1 -1
  13. package/lib/commonjs/CloseButton/CloseButton.js +1 -1
  14. package/lib/commonjs/CloseButton/CloseButton.js.map +1 -1
  15. package/lib/commonjs/Input/Input.native.js +15 -6
  16. package/lib/commonjs/Input/Input.native.js.map +1 -1
  17. package/lib/commonjs/KeyboardAwareScrollView/KeyboardAwareScrollView.native.js.map +1 -1
  18. package/lib/commonjs/Modal/drag/DragDismissHost.js +4 -1
  19. package/lib/commonjs/Modal/drag/DragDismissHost.js.map +1 -1
  20. package/lib/commonjs/Modal/drag/DragDismissOverlay.js +4 -1
  21. package/lib/commonjs/Modal/drag/DragDismissOverlay.js.map +1 -1
  22. package/lib/commonjs/Modal/drag/useDragDismiss.js +83 -67
  23. package/lib/commonjs/Modal/drag/useDragDismiss.js.map +1 -1
  24. package/lib/commonjs/Modal/modal-base.js +2 -2
  25. package/lib/commonjs/Modal/modal-base.js.map +1 -1
  26. package/lib/commonjs/Pill/Pill.js +1 -1
  27. package/lib/commonjs/Pill/Pill.js.map +1 -1
  28. package/lib/commonjs/Popover/Popover.shared.js +1 -1
  29. package/lib/commonjs/Popover/Popover.shared.js.map +1 -1
  30. package/lib/commonjs/Portal/OverlayHost.js.map +1 -1
  31. package/lib/commonjs/Portal/OverlayPortal.js +33 -0
  32. package/lib/commonjs/Portal/OverlayPortal.js.map +1 -0
  33. package/lib/commonjs/Portal/index.js +7 -0
  34. package/lib/commonjs/Portal/index.js.map +1 -1
  35. package/lib/commonjs/ScrollArea/ScrollArea.native.js +25 -15
  36. package/lib/commonjs/ScrollArea/ScrollArea.native.js.map +1 -1
  37. package/lib/commonjs/ThemeIcon/ThemeIcon.js +1 -1
  38. package/lib/commonjs/ThemeIcon/ThemeIcon.js.map +1 -1
  39. package/lib/commonjs/Tooltip/Tooltip.js +1 -1
  40. package/lib/commonjs/Tooltip/Tooltip.js.map +1 -1
  41. package/lib/commonjs/index.js +6 -0
  42. package/lib/commonjs/index.js.map +1 -1
  43. package/lib/commonjs/internal/gradient-shared.js +11 -1
  44. package/lib/commonjs/internal/gradient-shared.js.map +1 -1
  45. package/lib/commonjs/internal/gradient.js +6 -0
  46. package/lib/commonjs/internal/gradient.js.map +1 -1
  47. package/lib/commonjs/internal/gradient.native.js +6 -0
  48. package/lib/commonjs/internal/gradient.native.js.map +1 -1
  49. package/lib/commonjs/internal/use-looping-animation.native.js +1 -1
  50. package/lib/commonjs/internal/use-looping-animation.native.js.map +1 -1
  51. package/lib/module/ActionIcon/ActionIcon.js +2 -2
  52. package/lib/module/ActionIcon/ActionIcon.js.map +1 -1
  53. package/lib/module/Affix/Affix.js +2 -2
  54. package/lib/module/Affix/Affix.js.map +1 -1
  55. package/lib/module/Alert/Alert.js +2 -2
  56. package/lib/module/Alert/Alert.js.map +1 -1
  57. package/lib/module/Avatar/Avatar.js +2 -2
  58. package/lib/module/Avatar/Avatar.js.map +1 -1
  59. package/lib/module/Badge/Badge.js +2 -2
  60. package/lib/module/Badge/Badge.js.map +1 -1
  61. package/lib/module/Button/Button.js +2 -2
  62. package/lib/module/Button/Button.js.map +1 -1
  63. package/lib/module/CloseButton/CloseButton.js +2 -2
  64. package/lib/module/CloseButton/CloseButton.js.map +1 -1
  65. package/lib/module/Input/Input.native.js +15 -6
  66. package/lib/module/Input/Input.native.js.map +1 -1
  67. package/lib/module/KeyboardAwareScrollView/KeyboardAwareScrollView.native.js.map +1 -1
  68. package/lib/module/Modal/drag/DragDismissHost.js +4 -1
  69. package/lib/module/Modal/drag/DragDismissHost.js.map +1 -1
  70. package/lib/module/Modal/drag/DragDismissOverlay.js +4 -1
  71. package/lib/module/Modal/drag/DragDismissOverlay.js.map +1 -1
  72. package/lib/module/Modal/drag/useDragDismiss.js +84 -68
  73. package/lib/module/Modal/drag/useDragDismiss.js.map +1 -1
  74. package/lib/module/Modal/modal-base.js +3 -3
  75. package/lib/module/Modal/modal-base.js.map +1 -1
  76. package/lib/module/Pill/Pill.js +2 -2
  77. package/lib/module/Pill/Pill.js.map +1 -1
  78. package/lib/module/Popover/Popover.shared.js +2 -2
  79. package/lib/module/Popover/Popover.shared.js.map +1 -1
  80. package/lib/module/Portal/OverlayHost.js.map +1 -1
  81. package/lib/module/Portal/OverlayPortal.js +28 -0
  82. package/lib/module/Portal/OverlayPortal.js.map +1 -0
  83. package/lib/module/Portal/index.js +4 -0
  84. package/lib/module/Portal/index.js.map +1 -1
  85. package/lib/module/ScrollArea/ScrollArea.native.js +26 -16
  86. package/lib/module/ScrollArea/ScrollArea.native.js.map +1 -1
  87. package/lib/module/ThemeIcon/ThemeIcon.js +2 -2
  88. package/lib/module/ThemeIcon/ThemeIcon.js.map +1 -1
  89. package/lib/module/Tooltip/Tooltip.js +2 -2
  90. package/lib/module/Tooltip/Tooltip.js.map +1 -1
  91. package/lib/module/index.js +1 -1
  92. package/lib/module/index.js.map +1 -1
  93. package/lib/module/internal/gradient-shared.js +9 -0
  94. package/lib/module/internal/gradient-shared.js.map +1 -1
  95. package/lib/module/internal/gradient.js +2 -0
  96. package/lib/module/internal/gradient.js.map +1 -1
  97. package/lib/module/internal/gradient.native.js +2 -0
  98. package/lib/module/internal/gradient.native.js.map +1 -1
  99. package/lib/module/internal/use-looping-animation.native.js +1 -1
  100. package/lib/module/internal/use-looping-animation.native.js.map +1 -1
  101. package/lib/typescript/ActionIcon/ActionIcon.d.ts.map +1 -1
  102. package/lib/typescript/Alert/Alert.d.ts.map +1 -1
  103. package/lib/typescript/Avatar/Avatar.d.ts +14 -14
  104. package/lib/typescript/Avatar/Avatar.d.ts.map +1 -1
  105. package/lib/typescript/Badge/Badge.d.ts.map +1 -1
  106. package/lib/typescript/Button/Button.d.ts.map +1 -1
  107. package/lib/typescript/CloseButton/CloseButton.d.ts.map +1 -1
  108. package/lib/typescript/Image/Image.d.ts +14 -14
  109. package/lib/typescript/Image/Image.native.d.ts +14 -14
  110. package/lib/typescript/Image/createImage.d.ts +18 -18
  111. package/lib/typescript/Input/Input.native.d.ts +21 -21
  112. package/lib/typescript/Input/Input.native.d.ts.map +1 -1
  113. package/lib/typescript/KeyboardAvoidingView/KeyboardAvoidingView.native.d.ts +2 -2
  114. package/lib/typescript/KeyboardAwareScrollView/KeyboardAwareScrollView.native.d.ts +12 -18
  115. package/lib/typescript/KeyboardAwareScrollView/KeyboardAwareScrollView.native.d.ts.map +1 -1
  116. package/lib/typescript/Modal/drag/DragDismissHost.d.ts.map +1 -1
  117. package/lib/typescript/Modal/drag/DragDismissOverlay.d.ts.map +1 -1
  118. package/lib/typescript/Modal/drag/useDragDismiss.d.ts +2 -2
  119. package/lib/typescript/Modal/drag/useDragDismiss.d.ts.map +1 -1
  120. package/lib/typescript/Modal/modal-base-inner.native.d.ts +2 -2
  121. package/lib/typescript/Modal/modal-base-inner.native.d.ts.map +1 -1
  122. package/lib/typescript/Pill/Pill.d.ts.map +1 -1
  123. package/lib/typescript/Portal/OverlayHost.d.ts +2 -2
  124. package/lib/typescript/Portal/OverlayHost.d.ts.map +1 -1
  125. package/lib/typescript/Portal/OverlayPortal.d.ts +19 -0
  126. package/lib/typescript/Portal/OverlayPortal.d.ts.map +1 -0
  127. package/lib/typescript/Portal/index.d.ts +4 -0
  128. package/lib/typescript/Portal/index.d.ts.map +1 -1
  129. package/lib/typescript/ScrollArea/ScrollArea.native.d.ts.map +1 -1
  130. package/lib/typescript/ThemeIcon/ThemeIcon.d.ts.map +1 -1
  131. package/lib/typescript/index.d.ts +1 -1
  132. package/lib/typescript/index.d.ts.map +1 -1
  133. package/lib/typescript/internal/gradient-shared.d.ts +1 -0
  134. package/lib/typescript/internal/gradient-shared.d.ts.map +1 -1
  135. package/lib/typescript/internal/gradient.d.ts +1 -0
  136. package/lib/typescript/internal/gradient.d.ts.map +1 -1
  137. package/lib/typescript/internal/gradient.native.d.ts +1 -0
  138. package/lib/typescript/internal/gradient.native.d.ts.map +1 -1
  139. package/lib/typescript/internal/use-looping-animation.native.d.ts +2 -2
  140. package/lib/typescript/internal/use-looping-animation.native.d.ts.map +1 -1
  141. package/package.json +12 -12
  142. package/src/ActionIcon/ActionIcon.tsx +2 -2
  143. package/src/Affix/Affix.tsx +2 -2
  144. package/src/Alert/Alert.tsx +2 -2
  145. package/src/Avatar/Avatar.tsx +2 -2
  146. package/src/Badge/Badge.tsx +2 -2
  147. package/src/Button/Button.tsx +2 -2
  148. package/src/CloseButton/CloseButton.tsx +2 -2
  149. package/src/Input/Input.native.tsx +22 -7
  150. package/src/KeyboardAwareScrollView/KeyboardAwareScrollView.native.tsx +33 -32
  151. package/src/Modal/drag/DragDismissHost.tsx +10 -5
  152. package/src/Modal/drag/DragDismissOverlay.tsx +9 -5
  153. package/src/Modal/drag/useDragDismiss.ts +29 -21
  154. package/src/Modal/modal-base.tsx +4 -4
  155. package/src/Pill/Pill.tsx +2 -2
  156. package/src/Popover/Popover.shared.tsx +3 -3
  157. package/src/Portal/OverlayHost.tsx +4 -4
  158. package/src/Portal/OverlayPortal.tsx +26 -0
  159. package/src/Portal/index.ts +4 -0
  160. package/src/ScrollArea/ScrollArea.native.tsx +39 -33
  161. package/src/ThemeIcon/ThemeIcon.tsx +2 -2
  162. package/src/Tooltip/Tooltip.tsx +3 -3
  163. package/src/index.ts +2 -0
  164. package/src/internal/gradient-shared.ts +13 -0
  165. package/src/internal/gradient.native.tsx +1 -0
  166. package/src/internal/gradient.tsx +1 -0
  167. package/src/internal/use-looping-animation.native.tsx +2 -2
@@ -1,5 +1,9 @@
1
1
  import * as React from "react";
2
- import { Gesture, type PanGesture } from "react-native-gesture-handler";
2
+ import {
3
+ type PanGesture,
4
+ type PanGestureConfig,
5
+ usePanGesture,
6
+ } from "react-native-gesture-handler";
3
7
  import {
4
8
  cancelAnimation,
5
9
  type SharedValue,
@@ -61,12 +65,12 @@ export interface DragDismissParams {
61
65
  }
62
66
 
63
67
  /**
64
- * A single-axis drag-to-dismiss `Gesture.Pan`, shared by `Modal` (axis `y`,
68
+ * A single-axis drag-to-dismiss pan (RNGH 3 `usePanGesture`), shared by `Modal` (axis `y`,
65
69
  * sign `-1` — drag up) and `Drawer` (per-edge axis/sign). Tracks the finger toward the
66
70
  * dismiss edge into `offset` (rubber-banding the wrong way), and on release runs
67
71
  * the pure {@link shouldDismiss} on the UI thread: dismiss → spring off-screen
68
72
  * then `onDismiss`; otherwise spring back to rest. Works on web and native (RNGH
69
- * `Gesture.Pan` supports both).
73
+ * `usePanGesture` supports both). Returns the gesture for a `<GestureDetector>`.
70
74
  */
71
75
  export function useDragDismiss(params: DragDismissParams): PanGesture {
72
76
  const { offset, axis, sign, extent, dismissTravel, enabled, threshold, spring, onDismiss } =
@@ -75,7 +79,7 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
75
79
  // Whether this cycle activated (crossed the threshold into a real drag). A bare
76
80
  // tap begins + finalizes without activating, so this stays false.
77
81
  const active = useSharedValue(false);
78
- // Whether `onEnd` already committed a settle, so the `onFinalize` safety net only
82
+ // Whether `onDeactivate` already committed a settle, so the `onFinalize` safety net only
79
83
  // runs for an activated drag that was cancelled/interrupted before a clean end.
80
84
  const settled = useSharedValue(false);
81
85
  const config = spring ?? DEFAULT_DISMISS_SPRING;
@@ -84,25 +88,26 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
84
88
  // only the settle target differs (see `dismissTravel`).
85
89
  const exitTo = dismissTravel != null && dismissTravel > extent ? dismissTravel : extent;
86
90
 
87
- return React.useMemo(() => {
91
+ // Config identity drives RNGH's re-configuration (`usePanGesture` re-sends the
92
+ // config to the native handler whenever the object changes), so memoize it on
93
+ // exactly the inputs the callbacks close over.
94
+ const panConfig = React.useMemo((): PanGestureConfig => {
88
95
  // Only claim the touch once it has travelled along the drag axis — taps,
89
96
  // control presses, and cross-axis swipes are left to their own handlers.
90
97
  const threshold2: [number, number] = [-ACTIVATION_THRESHOLD, ACTIVATION_THRESHOLD];
91
- const gesture =
92
- axis === "x"
93
- ? Gesture.Pan().enabled(enabled).activeOffsetX(threshold2)
94
- : Gesture.Pan().enabled(enabled).activeOffsetY(threshold2);
95
98
 
96
- return gesture
97
- .onBegin(() => {
99
+ return {
100
+ enabled,
101
+ ...(axis === "x" ? { activeOffsetX: threshold2 } : { activeOffsetY: threshold2 }),
102
+ onBegin: () => {
98
103
  "worklet";
99
104
  // Touch-down (may still be a tap). Reset the cycle flags but leave any
100
105
  // running settle spring alone — cancelling here would freeze a mid-flight
101
106
  // panel under a tap that never becomes a drag.
102
107
  active.value = false;
103
108
  settled.value = false;
104
- })
105
- .onStart(() => {
109
+ },
110
+ onActivate: () => {
106
111
  "worklet";
107
112
  // Activation (a real drag crossed the threshold). Catch the panel wherever
108
113
  // its spring currently is and hand it to the finger with no jump — grabbing
@@ -111,8 +116,8 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
111
116
  panStart.value = offset.value;
112
117
  cancelAnimation(offset);
113
118
  active.value = true;
114
- })
115
- .onUpdate((e) => {
119
+ },
120
+ onUpdate: (e) => {
116
121
  "worklet";
117
122
  const raw = axis === "x" ? e.translationX : e.translationY;
118
123
  // Map screen translation into dismiss-direction travel. Hard-clamp the
@@ -120,8 +125,8 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
120
125
  // TOWARD the edge — never further into the screen than its open position.
121
126
  const d = panStart.value + raw * sign;
122
127
  offset.value = d > 0 ? d : 0;
123
- })
124
- .onEnd((e) => {
128
+ },
129
+ onDeactivate: (e) => {
125
130
  "worklet";
126
131
  const velocity = (axis === "x" ? e.velocityX : e.velocityY) * sign;
127
132
  settled.value = true;
@@ -140,15 +145,16 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
140
145
  } else {
141
146
  offset.value = withSpring(0, { ...config, velocity });
142
147
  }
143
- })
144
- .onFinalize(() => {
148
+ },
149
+ onFinalize: () => {
145
150
  "worklet";
146
151
  // Safety net for an activated drag interrupted/cancelled before a clean
147
- // `onEnd` (e.g. the OS stole the gesture) — spring back to rest. Never
152
+ // `onDeactivate` (e.g. the OS stole the gesture) — spring back to rest. Never
148
153
  // dismisses: only a real release may close the panel.
149
154
  if (!active.value || settled.value) return;
150
155
  offset.value = withSpring(0, config);
151
- });
156
+ },
157
+ };
152
158
  }, [
153
159
  offset,
154
160
  panStart,
@@ -163,4 +169,6 @@ export function useDragDismiss(params: DragDismissParams): PanGesture {
163
169
  config,
164
170
  onDismiss,
165
171
  ]);
172
+
173
+ return usePanGesture(panConfig);
166
174
  }
@@ -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, useOverlayHost } from "../Portal";
11
+ import { OverlayPortal, useOverlayHost } from "../Portal";
12
12
  import { ModalBaseInner } from "./modal-base-inner";
13
13
 
14
14
  /**
@@ -302,7 +302,7 @@ export function ModalBase(props: ModalBaseProps) {
302
302
  // `keepMounted` stays in the tree and toggles `display` — entrance animates but
303
303
  // there is no exit (the node never leaves), mirroring `Dialog`/`Popover`.
304
304
  if (keepMounted) {
305
- return <Portal hostName={withinPortal ? overlayHost : undefined}>{layer}</Portal>;
305
+ return <OverlayPortal hostName={withinPortal ? overlayHost : undefined}>{layer}</OverlayPortal>;
306
306
  }
307
307
 
308
308
  // Default: `AnimatePresence` holds the whole layer (scrim + content) in the tree
@@ -314,9 +314,9 @@ export function ModalBase(props: ModalBaseProps) {
314
314
  return (
315
315
  <AnimatePresence>
316
316
  {opened ? (
317
- <Portal key="modal-layer" hostName={withinPortal ? overlayHost : undefined}>
317
+ <OverlayPortal key="modal-layer" hostName={withinPortal ? overlayHost : undefined}>
318
318
  {layer}
319
- </Portal>
319
+ </OverlayPortal>
320
320
  ) : null}
321
321
  </AnimatePresence>
322
322
  );
package/src/Pill/Pill.tsx CHANGED
@@ -10,7 +10,7 @@ import {
10
10
 
11
11
  import { Box } from "../Box";
12
12
  import { CloseButton, type CloseButtonProps } from "../CloseButton";
13
- import { type GradientValue, useGradient } from "../internal/gradient";
13
+ import { gradientForVariant, type GradientValue, useGradient } from "../internal/gradient";
14
14
  import { renderTextChild } from "../internal/render-text-child";
15
15
  import {
16
16
  controlFontVariant,
@@ -230,7 +230,7 @@ const PillComponent = styleable<PillProps>(PillFrame, function Pill(props, ref)
230
230
 
231
231
  // Gradient fill (only when `variant="gradient"`): web paints a CSS
232
232
  // `backgroundImage`; native renders the `layer` (an SVG fill) behind the label.
233
- const grad = useGradient(variant === "gradient" ? gradient : undefined);
233
+ const grad = useGradient(gradientForVariant(variant, gradient));
234
234
  const group = React.useContext(PillGroupContext);
235
235
  const resolvedSize: PillSize = size ?? group?.size ?? "sm";
236
236
  const isDisabled = disabled ?? group?.disabled ?? false;
@@ -39,7 +39,7 @@ import { useOverlayChrome } from "../internal/overlay-chrome";
39
39
  import { shadowVariant } from "../internal/style-props";
40
40
  import { type SlotStyles } from "../internal/styles";
41
41
  import { type OverlayProps } from "../Overlay";
42
- import { Portal, useOverlayHost } from "../Portal";
42
+ import { OverlayPortal, useOverlayHost } from "../Portal";
43
43
  import {
44
44
  type OverlayTransitionConfig,
45
45
  useOverlayTransition,
@@ -743,7 +743,7 @@ export const PopoverDropdownView = styleable<PopoverDropdownViewProps>(
743
743
  const transitionStyle = waitingForPosition ? { ...t.style, opacity: 0 } : t.style;
744
744
 
745
745
  return (
746
- <Portal hostName={ctx.withinPortal ? overlayHost : undefined}>
746
+ <OverlayPortal hostName={ctx.withinPortal ? overlayHost : undefined}>
747
747
  <Theme name={themeName}>
748
748
  {/* Keep the scrim and the dropdown frame as direct siblings (rather
749
749
  than hoisting the scrim above `<Theme>`) so their z-indices compare
@@ -800,7 +800,7 @@ export const PopoverDropdownView = styleable<PopoverDropdownViewProps>(
800
800
  ) : null}
801
801
  </PopoverDropdownFrame>
802
802
  </Theme>
803
- </Portal>
803
+ </OverlayPortal>
804
804
  );
805
805
  },
806
806
  );
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { StyleSheet, View } from "react-native";
2
+ import { StyleSheet, View, type ViewInstance } from "react-native";
3
3
  import { PortalHost } from "react-native-teleport";
4
4
 
5
5
  import type { OverlayHostProps } from "./types";
@@ -17,7 +17,7 @@ type OverlayHostContextValue = {
17
17
  * the host's window origin. `null` for the root host (it sits at the window
18
18
  * origin by construction).
19
19
  */
20
- frameRef: React.RefObject<View | null> | null;
20
+ frameRef: React.RefObject<ViewInstance | null> | null;
21
21
  };
22
22
 
23
23
  const ROOT_VALUE: OverlayHostContextValue = { name: ROOT_OVERLAY_HOST, depth: 0, frameRef: null };
@@ -87,7 +87,7 @@ function register(name: string, depth: number): () => void {
87
87
  export function OverlayHost({ name, children }: OverlayHostProps) {
88
88
  const parent = React.useContext(OverlayHostContext);
89
89
  const depth = parent.depth + 1;
90
- const frameRef = React.useRef<View>(null);
90
+ const frameRef = React.useRef<ViewInstance>(null);
91
91
 
92
92
  const value = React.useMemo<OverlayHostContextValue>(
93
93
  () => ({ name, depth, frameRef }),
@@ -136,6 +136,6 @@ export function useTopmostOverlayHost(): string {
136
136
  * @internal The scoped host's measurable frame (or `null` under the root host),
137
137
  * for the native floating engine's container-origin math.
138
138
  */
139
- export function useOverlayHostFrame(): React.RefObject<View | null> | null {
139
+ export function useOverlayHostFrame(): React.RefObject<ViewInstance | null> | null {
140
140
  return React.useContext(OverlayHostContext).frameRef;
141
141
  }
@@ -0,0 +1,26 @@
1
+ import * as React from "react";
2
+ import { Portal } from "react-native-teleport";
3
+
4
+ import { useScreenFocused } from "@knitui/core";
5
+
6
+ export interface OverlayPortalProps {
7
+ /** Host to teleport into (usually `useOverlayHost()`); omit to render inline. */
8
+ hostName?: string;
9
+ children?: React.ReactNode;
10
+ }
11
+
12
+ /**
13
+ * The portal the kit's overlays render through: a `Portal` that teleports into
14
+ * `hostName` only while the screen it sits in is focused (`<Provider useScreenFocus>`).
15
+ *
16
+ * On a backgrounded stack screen the screen stays mounted, but the shared host it
17
+ * teleports into does not belong to it, so an open popover would draw over the
18
+ * screen in front. Dropping `hostName` while unfocused keeps the overlay inline in
19
+ * its own (now hidden) screen instead. Teleport re-parents rather than remounts, so
20
+ * the overlay keeps its state and is back, still open, when the screen regains focus.
21
+ * Without `useScreenFocus` this is exactly `<Portal hostName={hostName}>`.
22
+ */
23
+ export function OverlayPortal({ hostName, children }: OverlayPortalProps) {
24
+ const focused = useScreenFocused();
25
+ return <Portal hostName={focused ? hostName : undefined}>{children}</Portal>;
26
+ }
@@ -4,6 +4,7 @@ export {
4
4
  useOverlayHost,
5
5
  useTopmostOverlayHost,
6
6
  } from "./OverlayHost";
7
+ export { OverlayPortal, type OverlayPortalProps } from "./OverlayPortal";
7
8
  export type { OverlayHostProps, PortalHostProps, PortalProps, PortalProviderProps } from "./types";
8
9
  /**
9
10
  * Portal system — a thin re-export of `react-native-teleport`.
@@ -24,6 +25,9 @@ export type { OverlayHostProps, PortalHostProps, PortalProps, PortalProviderProp
24
25
  * kit's overlays inside it teleport into THAT host rather than `"root"` (which
25
26
  * lives in the window underneath the modal). They read the host through
26
27
  * `useOverlayHost()`; `useTopmostOverlayHost()` serves app-global layers.
28
+ * - The kit's overlays render through `<OverlayPortal>`, which stops teleporting
29
+ * while its screen is unfocused (`<Provider useScreenFocus>`), so a backgrounded
30
+ * stack screen's popovers don't draw over the screen in front of it.
27
31
  *
28
32
  * @see https://kirillzyusko.github.io/react-native-teleport
29
33
  */
@@ -1,6 +1,10 @@
1
1
  import * as React from "react";
2
- import { RefreshControl, type ScrollView } from "react-native";
3
- import { Gesture, GestureDetector } from "react-native-gesture-handler";
2
+ import { RefreshControl, type ScrollViewInstance } from "react-native";
3
+ import {
4
+ GestureDetector,
5
+ type PanGestureConfig,
6
+ usePanGesture,
7
+ } from "react-native-gesture-handler";
4
8
  import Animated, {
5
9
  cancelAnimation,
6
10
  useAnimatedReaction,
@@ -329,7 +333,7 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
329
333
  const reducedMotion = useReducedMotion();
330
334
 
331
335
  // The live native scroller (Autosize only; the Pan engine has none).
332
- const scrollViewRef = React.useRef<ScrollView | null>(null);
336
+ const scrollViewRef = React.useRef<ScrollViewInstance | null>(null);
333
337
 
334
338
  // ── UI-thread state (shared values) ──────────────────────────────────────
335
339
  // Scroll offset lives here, not in React state: the thumb worklet reads it every
@@ -565,19 +569,16 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
565
569
 
566
570
  /* ---------------- native (Autosize) scroll handler ---------------- */
567
571
 
568
- const scrollHandler = useAnimatedScrollHandler(
569
- {
570
- onScroll: (event) => {
571
- "worklet";
572
- scrollX.value = event.contentOffset.x;
573
- scrollY.value = event.contentOffset.y;
574
- if (needsJsScroll && shouldReportW(lastReportSV, reportIntervalMs)) {
575
- runOnJS(reportScroll)(event.contentOffset.x, event.contentOffset.y);
576
- }
577
- },
572
+ const scrollHandler = useAnimatedScrollHandler({
573
+ onScroll: (event) => {
574
+ "worklet";
575
+ scrollX.value = event.contentOffset.x;
576
+ scrollY.value = event.contentOffset.y;
577
+ if (needsJsScroll && shouldReportW(lastReportSV, reportIntervalMs)) {
578
+ runOnJS(reportScroll)(event.contentOffset.x, event.contentOffset.y);
579
+ }
578
580
  },
579
- [needsJsScroll, reportIntervalMs, lastReportSV, reportScroll],
580
- );
581
+ });
581
582
 
582
583
  /* ---------------- Pan engine ---------------- */
583
584
 
@@ -615,21 +616,28 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
615
616
  },
616
617
  );
617
618
 
618
- const panGesture = React.useMemo(() => {
619
- let g = Gesture.Pan()
620
- .onBegin(() => {
619
+ // RNGH 3 hook API: the config object is memoized so its identity (which drives
620
+ // the handler re-configuration) only changes with the inputs it closes over.
621
+ const panConfig = React.useMemo(
622
+ (): PanGestureConfig => ({
623
+ // Only claim the axes we actually scroll, so a cross-axis drag (and a tap)
624
+ // passes through to ancestors / pressable children. Spread conditionally:
625
+ // an `undefined` offset key would be forwarded to the native config.
626
+ ...(axes.x ? { activeOffsetX: [-PAN_ACTIVATE_THRESHOLD, PAN_ACTIVATE_THRESHOLD] } : null),
627
+ ...(axes.y ? { activeOffsetY: [-PAN_ACTIVATE_THRESHOLD, PAN_ACTIVATE_THRESHOLD] } : null),
628
+ onBegin: () => {
621
629
  "worklet";
622
630
  cancelAnimation(scrollX);
623
631
  cancelAnimation(scrollY);
624
632
  panStartX.value = scrollX.value;
625
633
  panStartY.value = scrollY.value;
626
- })
627
- .onUpdate((e) => {
634
+ },
635
+ onUpdate: (e) => {
628
636
  "worklet";
629
637
  scrollX.value = clampW(panStartX.value - e.translationX, 0, maxXSV.value);
630
638
  scrollY.value = clampW(panStartY.value - e.translationY, 0, maxYSV.value);
631
- })
632
- .onEnd((e) => {
639
+ },
640
+ onDeactivate: (e) => {
633
641
  "worklet";
634
642
  // No momentum under reduced motion — settle where the finger lifted.
635
643
  if (reducedMotion) return;
@@ -647,13 +655,11 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
647
655
  rubberBandEffect: false,
648
656
  });
649
657
  }
650
- });
651
- // Only claim the axes we actually scroll, so a cross-axis drag (and a tap)
652
- // passes through to ancestors / pressable children.
653
- if (axes.x) g = g.activeOffsetX([-PAN_ACTIVATE_THRESHOLD, PAN_ACTIVATE_THRESHOLD]);
654
- if (axes.y) g = g.activeOffsetY([-PAN_ACTIVATE_THRESHOLD, PAN_ACTIVATE_THRESHOLD]);
655
- return g;
656
- }, [axes.x, axes.y, reducedMotion, scrollX, scrollY, panStartX, panStartY, maxXSV, maxYSV]);
658
+ },
659
+ }),
660
+ [axes.x, axes.y, reducedMotion, scrollX, scrollY, panStartX, panStartY, maxXSV, maxYSV],
661
+ );
662
+ const panGesture = usePanGesture(panConfig);
657
663
 
658
664
  /* ---------------- geometry (layout decisions, JS) ---------------- */
659
665
 
@@ -832,7 +838,7 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
832
838
  "worklet";
833
839
  const { offset } = thumbGeometryW(size.contentH, size.viewportH, yTrack, scrollY.value);
834
840
  return { transform: [{ translateY: offset }] };
835
- }, [size.contentH, size.viewportH, yTrack]);
841
+ });
836
842
 
837
843
  const yThumbInsetStyle = useAnimatedStyle(() => {
838
844
  "worklet";
@@ -843,7 +849,7 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
843
849
  "worklet";
844
850
  const { offset } = thumbGeometryW(size.contentW, size.viewportW, xTrack, scrollX.value);
845
851
  return { transform: [{ translateX: offset }] };
846
- }, [size.contentW, size.viewportW, xTrack]);
852
+ });
847
853
 
848
854
  const xThumbInsetStyle = useAnimatedStyle(() => {
849
855
  "worklet";
@@ -903,7 +909,7 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
903
909
  showsHorizontalScrollIndicator: false,
904
910
  scrollEventThrottle: 16,
905
911
  nestedScrollEnabled: true,
906
- keyboardShouldPersistTaps,
912
+ keyboardShouldPersistTaps: keyboardShouldPersistTaps as never,
907
913
  ...(onRefresh
908
914
  ? {
909
915
  refreshControl: (
@@ -918,7 +924,7 @@ const ScrollAreaComponent = React.forwardRef<ScrollAreaHandle, ScrollAreaProps>(
918
924
  ...(mergedViewportProps as object),
919
925
  };
920
926
 
921
- const assignScroller = (node: ScrollView | null) => {
927
+ const assignScroller = (node: ScrollViewInstance | null) => {
922
928
  scrollViewRef.current = node;
923
929
  assignRef(viewportRef, node as unknown as TamaguiElement);
924
930
  };
@@ -10,7 +10,7 @@ import {
10
10
 
11
11
  import { Box } from "../Box";
12
12
  import { ControlIconProvider } from "../internal/ControlIconProvider";
13
- import { type GradientValue, useGradient } from "../internal/gradient";
13
+ import { gradientForVariant, type GradientValue, useGradient } from "../internal/gradient";
14
14
  import {
15
15
  pickVariants,
16
16
  radiusVariant,
@@ -99,7 +99,7 @@ const ThemeIconComponent = styleable<ThemeIconProps>(
99
99
 
100
100
  // Gradient fill (only when `variant="gradient"`): web paints a CSS
101
101
  // `backgroundImage`; native renders the `layer` (an SVG fill) behind the icon.
102
- const grad = useGradient(variant === "gradient" ? gradient : undefined);
102
+ const grad = useGradient(gradientForVariant(variant, gradient));
103
103
 
104
104
  return (
105
105
  <ThemeIconFrame ref={ref} variant={variant} size={size} {...grad.frameProps} {...rest}>
@@ -35,7 +35,7 @@ import { type MotionPresetName } from "../internal/motion";
35
35
  import { useOverlayChrome } from "../internal/overlay-chrome";
36
36
  import { type RadiusValue, radiusVariant, shadowVariant } from "../internal/style-props";
37
37
  import { type SlotStyles } from "../internal/styles";
38
- import { Portal, useOverlayHost } from "../Portal";
38
+ import { OverlayPortal, useOverlayHost } from "../Portal";
39
39
  import { Text } from "../Text";
40
40
  import {
41
41
  type OverlayTransitionConfig,
@@ -592,7 +592,7 @@ const TooltipBase = styleable<TooltipProps>(TooltipLabelFrame, function Tooltip(
592
592
  const dropdownSlot = s.get("dropdown");
593
593
 
594
594
  const labelNode = !t.rendered ? null : (
595
- <Portal hostName={withinPortal ? overlayHost : undefined}>
595
+ <OverlayPortal hostName={withinPortal ? overlayHost : undefined}>
596
596
  <Theme name={themeName}>
597
597
  <TooltipLabelFrame
598
598
  ref={floatingRef}
@@ -648,7 +648,7 @@ const TooltipBase = styleable<TooltipProps>(TooltipLabelFrame, function Tooltip(
648
648
  ) : null}
649
649
  </TooltipLabelFrame>
650
650
  </Theme>
651
- </Portal>
651
+ </OverlayPortal>
652
652
  );
653
653
 
654
654
  return (
package/src/index.ts CHANGED
@@ -412,6 +412,8 @@ export {
412
412
  export {
413
413
  OverlayHost,
414
414
  type OverlayHostProps,
415
+ OverlayPortal,
416
+ type OverlayPortalProps,
415
417
  Portal,
416
418
  PortalHost,
417
419
  type PortalHostProps,
@@ -65,6 +65,19 @@ const DEFAULT_FROM = "color5";
65
65
  const DEFAULT_TO = "color9";
66
66
  const DEFAULT_DEG = 45;
67
67
 
68
+ /**
69
+ * The gradient a component paints for its `variant` / `gradient` props: `undefined`
70
+ * unless `variant="gradient"`, and the theme-ramp default (`color5` → `color9` at
71
+ * 45°) when the variant is set without a `gradient` prop. A shared frozen object,
72
+ * so the default keeps a stable identity across renders.
73
+ */
74
+ const DEFAULT_GRADIENT: GradientValue = Object.freeze({});
75
+ export const gradientForVariant = (
76
+ variant: unknown,
77
+ gradient: GradientValue | undefined,
78
+ ): GradientValue | undefined =>
79
+ variant === "gradient" ? (gradient ?? DEFAULT_GRADIENT) : undefined;
80
+
68
81
  /** The resolved angle, defaulting to Mantine's 45°. */
69
82
  export const gradientDeg = (gradient: GradientValue): number => gradient.deg ?? DEFAULT_DEG;
70
83
 
@@ -27,6 +27,7 @@ import type { GradientResult, GradientValue } from "./gradient-shared";
27
27
  import { degToSvgCoords, gradientDeg, resolveStops } from "./gradient-shared";
28
28
 
29
29
  export type { GradientStop, GradientValue } from "./gradient-shared";
30
+ export { gradientForVariant } from "./gradient-shared";
30
31
 
31
32
  /**
32
33
  * The no-gradient result, shared and frozen so the (overwhelmingly common)
@@ -20,6 +20,7 @@ import type { GradientResult, GradientValue } from "./gradient-shared";
20
20
  import { gradientToCss } from "./gradient-shared";
21
21
 
22
22
  export type { GradientStop, GradientValue } from "./gradient-shared";
23
+ export { gradientForVariant } from "./gradient-shared";
23
24
 
24
25
  /**
25
26
  * The no-gradient result, shared and frozen so the (overwhelmingly common)
@@ -28,7 +28,7 @@ type Easer = EasingFunction | EasingFunctionFactory;
28
28
  * worklet output) drives on the UI thread. Mirrors `LoopView` on web (a `Box`); the
29
29
  * spread API (`<LoopView {...loop} />`) is identical across platforms.
30
30
  */
31
- export const LoopView = Animated.View;
31
+ export const LoopView: typeof Animated.View = Animated.View;
32
32
 
33
33
  /**
34
34
  * Promote a frame component into a reanimated host so a {@link useLoopingAnimation}
@@ -116,7 +116,7 @@ export function useLoopingAnimation(motion: LoopMotion): LoopStyle {
116
116
  // shimmer
117
117
  const offset = progress.value * distance;
118
118
  return { transform: axis === "y" ? [{ translateY: offset }] : [{ translateX: offset }] };
119
- }, [reduced, kind, minOpacity, distance, axis]);
119
+ });
120
120
 
121
121
  return { style };
122
122
  }