@bloxwap/hig 0.7.0 → 0.8.1

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 (246) hide show
  1. package/README.md +2 -2
  2. package/chart/README.md +13 -2
  3. package/chart/dist/altimeter-burst.d.ts +4 -0
  4. package/chart/dist/altimeter-burst.js +43 -0
  5. package/chart/dist/altimeter-chart.d.ts +52 -0
  6. package/chart/dist/altimeter-chart.js +275 -0
  7. package/chart/dist/altimeter-model.d.ts +43 -0
  8. package/chart/dist/altimeter-model.js +148 -0
  9. package/chart/dist/altimeter-targets.d.ts +33 -0
  10. package/chart/dist/altimeter-targets.js +88 -0
  11. package/chart/dist/bitcoin-price.d.ts +8 -0
  12. package/chart/dist/bitcoin-price.js +41 -0
  13. package/chart/dist/champions-league.d.ts +19 -0
  14. package/chart/dist/champions-league.js +104 -0
  15. package/chart/dist/index.d.ts +6 -0
  16. package/chart/dist/index.js +5 -0
  17. package/chart/dist/outcome-chart.d.ts +37 -0
  18. package/chart/dist/outcome-chart.js +212 -0
  19. package/chart/dist/outcome-model.d.ts +43 -0
  20. package/chart/dist/outcome-model.js +71 -0
  21. package/chart/dist/plus-grid.d.ts +6 -0
  22. package/chart/dist/plus-grid.js +29 -0
  23. package/contracts/README.md +1 -1
  24. package/contracts/dist/avatar.d.ts +68 -0
  25. package/contracts/dist/avatar.js +93 -0
  26. package/contracts/dist/confetti.d.ts +174 -0
  27. package/contracts/dist/confetti.js +138 -0
  28. package/contracts/dist/decimal.d.ts +7 -0
  29. package/contracts/dist/decimal.js +35 -0
  30. package/contracts/dist/index.d.ts +29 -2
  31. package/contracts/dist/index.js +123 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/messages.d.ts +56 -2
  35. package/contracts/dist/messages.js +20 -2
  36. package/contracts/dist/number-flow.d.ts +90 -0
  37. package/contracts/dist/number-flow.js +150 -0
  38. package/contracts/dist/qr.d.ts +151 -0
  39. package/contracts/dist/qr.js +581 -0
  40. package/contracts/dist/toast.d.ts +168 -0
  41. package/contracts/dist/toast.js +171 -0
  42. package/feedback/README.md +1 -1
  43. package/feedback/dist/contract.js +1 -1
  44. package/feedback/dist/react.js +2 -4
  45. package/native/README.md +6 -1
  46. package/native/dist/account-block.d.ts +10 -1
  47. package/native/dist/account-block.js +17 -7
  48. package/native/dist/animated-number-model.d.ts +41 -1
  49. package/native/dist/animated-number-model.js +201 -23
  50. package/native/dist/animated-number.d.ts +39 -1
  51. package/native/dist/animated-number.js +161 -16
  52. package/native/dist/announce.d.ts +2 -0
  53. package/native/dist/announce.js +10 -0
  54. package/native/dist/asset-balance-row.d.ts +3 -1
  55. package/native/dist/asset-balance-row.js +15 -4
  56. package/native/dist/assets-block.d.ts +115 -0
  57. package/native/dist/assets-block.js +87 -0
  58. package/native/dist/async-result.d.ts +2 -0
  59. package/native/dist/async-result.js +11 -0
  60. package/native/dist/avatar-frame.d.ts +29 -0
  61. package/native/dist/avatar-frame.js +56 -0
  62. package/native/dist/avatar.d.ts +21 -0
  63. package/native/dist/avatar.js +31 -0
  64. package/native/dist/bar-mark.d.ts +2 -0
  65. package/native/dist/bar-mark.js +4 -2
  66. package/native/dist/bar-pnl.js +2 -1
  67. package/native/dist/blocks.d.ts +6 -1
  68. package/native/dist/blocks.js +5 -0
  69. package/native/dist/brand.js +2 -1
  70. package/native/dist/button.d.ts +7 -2
  71. package/native/dist/button.js +13 -3
  72. package/native/dist/checkbox.js +2 -1
  73. package/native/dist/confetti.d.ts +33 -0
  74. package/native/dist/confetti.js +143 -0
  75. package/native/dist/confirm-block.d.ts +98 -0
  76. package/native/dist/confirm-block.js +48 -0
  77. package/native/dist/data.js +2 -0
  78. package/native/dist/explainer-block.d.ts +91 -0
  79. package/native/dist/explainer-block.js +34 -0
  80. package/native/dist/field.d.ts +5 -1
  81. package/native/dist/field.js +27 -6
  82. package/native/dist/gesture-sheet-model.d.ts +50 -0
  83. package/native/dist/gesture-sheet-model.js +105 -0
  84. package/native/dist/gesture-sheet-next.d.ts +82 -0
  85. package/native/dist/gesture-sheet-next.js +315 -0
  86. package/native/dist/gesture-sheet.d.ts +5 -1
  87. package/native/dist/gesture-sheet.js +13 -6
  88. package/native/dist/icons.d.ts +9 -6
  89. package/native/dist/icons.js +25 -24
  90. package/native/dist/language-block.d.ts +10 -1
  91. package/native/dist/language-block.js +11 -4
  92. package/native/dist/list-group.d.ts +3 -1
  93. package/native/dist/list-group.js +26 -13
  94. package/native/dist/manage-position-block.d.ts +8 -1
  95. package/native/dist/manage-position-block.js +7 -2
  96. package/native/dist/market-row.js +19 -8
  97. package/native/dist/navigation.js +5 -3
  98. package/native/dist/number-format.d.ts +6 -0
  99. package/native/dist/number-format.js +9 -0
  100. package/native/dist/pickers.d.ts +8 -0
  101. package/native/dist/pickers.js +3 -3
  102. package/native/dist/position-block.d.ts +5 -5
  103. package/native/dist/preset-group.d.ts +31 -0
  104. package/native/dist/preset-group.js +39 -0
  105. package/native/dist/preset-picker-block.d.ts +107 -0
  106. package/native/dist/preset-picker-block.js +43 -0
  107. package/native/dist/profile-block.d.ts +10 -1
  108. package/native/dist/profile-block.js +8 -3
  109. package/native/dist/provider.d.ts +5 -2
  110. package/native/dist/provider.js +27 -5
  111. package/native/dist/qr-code.d.ts +33 -0
  112. package/native/dist/qr-code.js +29 -0
  113. package/native/dist/radio-group.d.ts +19 -7
  114. package/native/dist/radio-group.js +39 -10
  115. package/native/dist/reward-block.d.ts +10 -7
  116. package/native/dist/reward-block.js +9 -4
  117. package/native/dist/screen-header.d.ts +13 -3
  118. package/native/dist/screen-header.js +12 -4
  119. package/native/dist/select.js +4 -2
  120. package/native/dist/selection.d.ts +2 -1
  121. package/native/dist/selection.js +1 -0
  122. package/native/dist/setting-switch.d.ts +1 -1
  123. package/native/dist/setting-switch.js +7 -3
  124. package/native/dist/slider.js +5 -1
  125. package/native/dist/sound-haptics-block.js +1 -1
  126. package/native/dist/status.d.ts +41 -9
  127. package/native/dist/status.js +34 -17
  128. package/native/dist/sticky-header.js +9 -1
  129. package/native/dist/swap-amount-card.d.ts +57 -0
  130. package/native/dist/swap-amount-card.js +31 -0
  131. package/native/dist/swap-panel-block.d.ts +9 -3
  132. package/native/dist/swap-panel-block.js +59 -33
  133. package/native/dist/swap-parts.d.ts +3 -10
  134. package/native/dist/swap-parts.js +22 -24
  135. package/native/dist/swap-shared.d.ts +2 -2
  136. package/native/dist/swap-shared.js +10 -6
  137. package/native/dist/swap-views.js +1 -1
  138. package/native/dist/target-block.d.ts +7 -1
  139. package/native/dist/target-block.js +13 -6
  140. package/native/dist/toast.d.ts +47 -0
  141. package/native/dist/toast.js +386 -0
  142. package/native/dist/token-action-block.d.ts +10 -1
  143. package/native/dist/token-action-block.js +9 -4
  144. package/native/dist/trade-history-list-block.js +7 -4
  145. package/native/dist/wallet-address-core.js +6 -3
  146. package/native-fonts/README.md +1 -1
  147. package/og-fonts/README.md +1 -1
  148. package/package.json +111 -2
  149. package/react/README.md +3 -1
  150. package/react/dist/animated-number-flow.d.ts +72 -0
  151. package/react/dist/animated-number-flow.js +316 -0
  152. package/react/dist/animated-number-model.d.ts +18 -0
  153. package/react/dist/animated-number-model.js +75 -5
  154. package/react/dist/animated-number.d.ts +45 -1
  155. package/react/dist/animated-number.js +137 -6
  156. package/react/dist/asset-balance-row.d.ts +3 -1
  157. package/react/dist/asset-balance-row.js +10 -4
  158. package/react/dist/async-result.d.ts +2 -0
  159. package/react/dist/async-result.js +11 -0
  160. package/react/dist/avatar.d.ts +25 -0
  161. package/react/dist/avatar.js +50 -0
  162. package/react/dist/blocks/account-block.d.ts +5 -1
  163. package/react/dist/blocks/account-block.js +11 -6
  164. package/react/dist/blocks/assets-block.d.ts +106 -0
  165. package/react/dist/blocks/assets-block.js +135 -0
  166. package/react/dist/blocks/confirm-block.d.ts +91 -0
  167. package/react/dist/blocks/confirm-block.js +31 -0
  168. package/react/dist/blocks/explainer-block.d.ts +80 -0
  169. package/react/dist/blocks/explainer-block.js +20 -0
  170. package/react/dist/blocks/install-command.js +3 -1
  171. package/react/dist/blocks/language-block.d.ts +5 -1
  172. package/react/dist/blocks/language-block.js +4 -3
  173. package/react/dist/blocks/manage-position-block.d.ts +3 -1
  174. package/react/dist/blocks/manage-position-block.js +2 -2
  175. package/react/dist/blocks/market-row.js +8 -3
  176. package/react/dist/blocks/notifications-block.d.ts +3 -1
  177. package/react/dist/blocks/notifications-block.js +2 -2
  178. package/react/dist/blocks/pickers.d.ts +9 -0
  179. package/react/dist/blocks/pickers.js +4 -2
  180. package/react/dist/blocks/position-block.d.ts +3 -3
  181. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  182. package/react/dist/blocks/preset-picker-block.js +19 -0
  183. package/react/dist/blocks/profile-block.d.ts +5 -1
  184. package/react/dist/blocks/profile-block.js +12 -13
  185. package/react/dist/blocks/reward-block.d.ts +13 -8
  186. package/react/dist/blocks/reward-block.js +7 -4
  187. package/react/dist/blocks/screen-header.d.ts +10 -2
  188. package/react/dist/blocks/screen-header.js +7 -4
  189. package/react/dist/blocks/setting-switch.js +6 -3
  190. package/react/dist/blocks/signals-block.d.ts +3 -1
  191. package/react/dist/blocks/signals-block.js +4 -3
  192. package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
  193. package/react/dist/blocks/sound-haptics-block.js +2 -2
  194. package/react/dist/blocks/sticky-header.d.ts +14 -4
  195. package/react/dist/blocks/sticky-header.js +68 -8
  196. package/react/dist/blocks/swap/settings.js +2 -1
  197. package/react/dist/blocks/swap/shared.d.ts +22 -22
  198. package/react/dist/blocks/swap/shared.js +30 -28
  199. package/react/dist/blocks/swap-panel-block.d.ts +10 -3
  200. package/react/dist/blocks/swap-panel-block.js +71 -36
  201. package/react/dist/blocks/target-block.d.ts +7 -1
  202. package/react/dist/blocks/target-block.js +10 -4
  203. package/react/dist/blocks/token-action-block.d.ts +5 -1
  204. package/react/dist/blocks/token-action-block.js +2 -2
  205. package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
  206. package/react/dist/blocks/trade-history-detail-block.js +2 -2
  207. package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
  208. package/react/dist/blocks/trade-history-list-block.js +7 -4
  209. package/react/dist/blocks.d.ts +5 -1
  210. package/react/dist/blocks.js +4 -0
  211. package/react/dist/brand.js +2 -1
  212. package/react/dist/button.d.ts +9 -3
  213. package/react/dist/button.js +8 -3
  214. package/react/dist/confetti.d.ts +27 -0
  215. package/react/dist/confetti.js +240 -0
  216. package/react/dist/data.js +8 -1
  217. package/react/dist/field.d.ts +6 -1
  218. package/react/dist/field.js +18 -9
  219. package/react/dist/gesture-sheet.d.ts +15 -1
  220. package/react/dist/gesture-sheet.js +53 -8
  221. package/react/dist/list-group.js +11 -7
  222. package/react/dist/navigation.js +11 -3
  223. package/react/dist/overlay.d.ts +28 -3
  224. package/react/dist/overlay.js +29 -3
  225. package/react/dist/preset-group.d.ts +30 -0
  226. package/react/dist/preset-group.js +13 -0
  227. package/react/dist/provider.d.ts +2 -2
  228. package/react/dist/provider.js +23 -6
  229. package/react/dist/qr-code.d.ts +32 -0
  230. package/react/dist/qr-code.js +28 -0
  231. package/react/dist/select.js +10 -3
  232. package/react/dist/selection.d.ts +13 -5
  233. package/react/dist/selection.js +13 -8
  234. package/react/dist/slider.js +5 -1
  235. package/react/dist/status.d.ts +14 -10
  236. package/react/dist/status.js +17 -9
  237. package/react/dist/styles.css +238 -163
  238. package/react/dist/toast.d.ts +19 -12
  239. package/react/dist/toast.js +29 -7
  240. package/react/dist/wallet-address-core.d.ts +8 -4
  241. package/react/dist/wallet-address-core.js +10 -5
  242. package/tokens/README.md +2 -2
  243. package/tokens/dist/index.d.ts +16 -0
  244. package/tokens/dist/index.js +16 -0
  245. package/tokens/dist/manifest.json +8 -0
  246. package/tokens/dist/tokens.css +6 -0
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createContext, useContext, forwardRef, useEffect, useId, useRef, useState } from 'react';
2
+ import { createContext, useContext, forwardRef, useEffect, useId, useRef, useCallback, useState } from 'react';
3
3
  import { AccessibilityInfo, Platform, Pressable, TextInput, View } from 'react-native';
4
4
  import { CloseIcon, SearchIcon } from './icons.js';
5
5
  import { Text } from './surface.js';
@@ -24,8 +24,26 @@ export function Field({ label, description, descriptionTone, error, required, di
24
24
  return _jsx(Context.Provider, { value: { label: marked, hint: [description, error].filter(Boolean).join('. '), disabled, invalid: !!error }, children: _jsxs(View, { style: { gap: 8 }, children: [_jsx(Text, { nativeID: id, children: marked }), children, description && _jsx(Text, { ...(positive ? { accessibilityLiveRegion: 'polite' } : {}), style: { color: positive ? colors.positive : colors.muted }, children: description }), error && _jsx(Text, { accessibilityLiveRegion: 'polite', style: { color: colors.negative }, children: error })] }) });
25
25
  }
26
26
  export const Label = Text;
27
- /** No resting stroke: the fill separates the field (one step lighter inside a Surface, Dialog or sheet). The ring appears only for focus and for an invalid value. */
28
- export const Input = forwardRef(function Input({ style, onFocus, onBlur, ...props }, ref) { const field = useContext(Context); const colors = useColors(); const fills = useFills(); const env = useHIG(); const [focused, setFocused] = useState(false); return _jsx(TextInput, { ...props, ref: ref, accessibilityLabel: props.accessibilityLabel ?? field.label, accessibilityHint: props.accessibilityHint ?? field.hint, accessibilityState: { ...props.accessibilityState, disabled: !!field.disabled || !!props.accessibilityState?.disabled }, editable: field.disabled ? false : props.editable, onChangeText: field.disabled ? undefined : props.onChangeText, onChange: field.disabled ? undefined : props.onChange, onFocus: event => { setFocused(true); onFocus?.(event); }, onBlur: event => { setFocused(false); onBlur?.(event); }, placeholderTextColor: props.placeholderTextColor ?? colors.muted, style: [{ color: colors.text, backgroundColor: fills.well, minHeight: 48, borderWidth: 1.5, borderColor: field.invalid ? colors.negative : focused ? colors.faint : 'transparent', borderRadius: props.multiline ? 14 : 9999, paddingVertical: 12, paddingHorizontal: 20, fontSize: 16, fontFamily: env.fontFamilies?.[400] ?? env.fontFamily, opacity: field.disabled ? 0.5 : 1 }, style] }); });
27
+ export const Input = forwardRef(function Input({ style, onFocus, onBlur, prefix, ...props }, ref) {
28
+ const field = useContext(Context);
29
+ const colors = useColors();
30
+ const fills = useFills();
31
+ const env = useHIG();
32
+ const [focused, setFocused] = useState(false);
33
+ // The prefix is measured once laid out, so the text starts just after it; until then a width is estimated from its length.
34
+ const [lead, setLead] = useState(null);
35
+ const rtl = env.direction === 'rtl', web = Platform.OS === 'web';
36
+ const hint = props.accessibilityHint ?? ([prefix, field.hint].filter(Boolean).join('. ') || undefined);
37
+ const start = prefix ? 20 + (lead ?? prefix.length * 10) + 4 : undefined;
38
+ const inset = start === undefined ? null : web ? (rtl ? { paddingRight: start } : { paddingLeft: start }) : { paddingStart: start };
39
+ const input = _jsx(TextInput, { ...props, ref: ref, accessibilityLabel: props.accessibilityLabel ?? field.label, accessibilityHint: hint, accessibilityState: { ...props.accessibilityState, disabled: !!field.disabled || !!props.accessibilityState?.disabled }, editable: field.disabled ? false : props.editable, onChangeText: field.disabled ? undefined : props.onChangeText, onChange: field.disabled ? undefined : props.onChange, onFocus: event => { setFocused(true); onFocus?.(event); }, onBlur: event => { setFocused(false); onBlur?.(event); }, placeholderTextColor: props.placeholderTextColor ?? colors.muted, style: [{ color: colors.text, backgroundColor: fills.well, minHeight: 48, borderWidth: 1.5, borderColor: field.invalid ? colors.negative : focused ? colors.faint : 'transparent', borderRadius: props.multiline ? 14 : 9999, paddingVertical: 12, paddingHorizontal: 20, fontSize: 16, fontFamily: env.fontFamilies?.[400] ?? env.fontFamily, opacity: field.disabled ? 0.5 : 1 }, inset, style] });
40
+ if (!prefix)
41
+ return input;
42
+ const edge = web ? (rtl ? { right: 20 } : { left: 20 }) : { start: 20 };
43
+ return _jsxs(View, { style: { direction: env.direction, justifyContent: 'center' }, children: [input, _jsx(View, { ...hiddenPrefix, pointerEvents: 'none', style: { position: 'absolute', ...edge }, children: _jsx(Text, { testID: props.testID ? `${props.testID}-prefix` : undefined, onLayout: event => { const width = Math.ceil(event.nativeEvent.layout.width); if (width !== lead)
44
+ setLead(width); }, style: { fontSize: 16, color: colors.muted, opacity: field.disabled ? 0.5 : 1 }, children: prefix }) })] });
45
+ });
46
+ const hiddenPrefix = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
29
47
  export const TextArea = forwardRef(function TextArea(props, ref) { return _jsx(Input, { ...props, ref: ref, multiline: true, textAlignVertical: 'top' }); });
30
48
  /** The magnifying glass sits inset on the leading edge and the text starts past it. */
31
49
  /** A search box is as tall as a button, 44dp, not a 48dp form field. */
@@ -41,10 +59,13 @@ export const SearchInput = forwardRef(function SearchInput({ style, trailing, on
41
59
  const extra = trailing != null && trailing !== false, reserve = extra || onClear != null;
42
60
  const end = web ? (rtl ? { left: 0 } : { right: 0 }) : { end: 0 };
43
61
  const endInset = reserve ? (web ? (rtl ? { paddingLeft: 48 } : { paddingRight: 48 }) : { paddingEnd: 48 }) : null;
44
- const attach = (node) => { inner.current = node; if (typeof ref === 'function')
45
- ref(node);
62
+ const attach = useCallback((node) => { inner.current = node; const cleanup = typeof ref === 'function' ? ref(node) : undefined; if (ref && typeof ref !== 'function')
63
+ ref.current = node; return () => { inner.current = null; if (typeof cleanup === 'function')
64
+ cleanup();
65
+ else if (typeof ref === 'function')
66
+ ref(null);
46
67
  else if (ref)
47
- ref.current = node; };
68
+ ref.current = null; }; }, [ref]);
48
69
  const off = props.editable === false || !!useContext(Context).disabled;
49
70
  const clear = onClear && props.value != null && props.value !== '' ? _jsx(Pressable, { testID: props.testID ? `${props.testID}-clear` : undefined, accessibilityRole: 'button', accessibilityLabel: clearLabel ?? messages.clearSearch ?? en.clearSearch, accessibilityState: off ? { disabled: true } : undefined, disabled: off, hitSlop: 2, onPress: () => { onClear(); inner.current?.focus(); }, style: ({ pressed }) => ({ width: 44, height: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center', opacity: off ? 0.5 : pressed ? 0.6 : 1 }), children: _jsx(CloseIcon, { color: colors.muted }) }) : null;
50
71
  return _jsxs(View, { style: { direction, justifyContent: 'center' }, children: [_jsx(Input, { ...props, ref: onClear ? attach : ref, returnKeyType: props.returnKeyType ?? 'search', style: [searchSize, inset, endInset, style] }), _jsx(View, { pointerEvents: 'none', style: { position: 'absolute', ...edge }, children: _jsx(SearchIcon, { color: colors.muted }) }), extra || clear ? _jsxs(View, { style: { position: 'absolute', top: 0, bottom: 0, ...end, flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [trailing, clear] }) : null] });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The arithmetic of HIG's own sheet, kept apart from React so it runs on the UI thread as worklets and is tested as plain
3
+ * functions. Positions are the sheet's `translateY` in points: 0 is the sheet at its full height, `height` is closed.
4
+ */
5
+ export type SheetSnapPoint = number | `${number}%`;
6
+ /** A detent as visible height in points, from points or a percentage of the room the sheet has. Invalid input reads as 0. */
7
+ export declare function detentHeight(point: SheetSnapPoint, room: number): number;
8
+ /** Detent heights for fixed snap points: clamped to the room, sorted increasing, without duplicates or empty detents. */
9
+ export declare function detentHeights(points: readonly SheetSnapPoint[], room: number): number[];
10
+ /**
11
+ * Resistance past the sheet's limit: the further the finger goes, the less the sheet follows, and it never passes `limit`
12
+ * points. The same curve UIScrollView uses.
13
+ */
14
+ export declare function rubberBand(overshoot: number, limit: number): number;
15
+ /** Where a drag puts the sheet: 1:1 between the top detent and closed, resisting above the top detent, and resisting below the lowest detent when it cannot be dismissed. */
16
+ export declare function dragPosition(raw: number, top: number, lowest: number, closed: number, dismissible: boolean): number;
17
+ /** How far ahead of the finger a release is read, in seconds: a flick lands where its momentum would carry it. */
18
+ export declare const SHEET_PROJECTION = 0.18;
19
+ /** A release slower than this (points per second) is a placement, not a flick. */
20
+ export declare const SHEET_FLICK = 500;
21
+ /**
22
+ * The detent a release settles on, as an index into `positions` (increasing translateY, so index 0 is the tallest), or -1 to
23
+ * close. A flick moves one detent in its direction, or closes from the lowest; a slow release takes the nearest detent, or
24
+ * closes when the sheet is more than half way from the lowest detent to closed.
25
+ */
26
+ export declare function releaseTarget(position: number, velocity: number, positions: readonly number[], closed: number, dismissible: boolean): number;
27
+ /**
28
+ * The spring every settle uses: critically damped (damping = 2·√(stiffness·mass)), so the sheet lands without a bounce and
29
+ * without a slow tail, in about a third of a second. An overdamped spring creeps to rest and keeps drawing frames long
30
+ * after the sheet looks still (measured on a Seeker: animating almost a second per settle).
31
+ */
32
+ export declare const SHEET_SPRING: {
33
+ readonly damping: 36;
34
+ readonly stiffness: 320;
35
+ readonly mass: 1;
36
+ readonly overshootClamping: true;
37
+ };
38
+ /** Backdrop strength for a position: full at the lowest detent and above, fading to none at closed. */
39
+ export declare function backdropProgress(position: number, lowest: number, closed: number): number;
40
+ /**
41
+ * How a content-sized sheet moves when its content changes height while it rests: one curve with no spring and no
42
+ * overshoot, a short ease in and a long ease out, the values of Vaul's Dynamic Drawer. Drag releases, opening and closing
43
+ * use the spring.
44
+ */
45
+ export declare const SHEET_RESIZE: {
46
+ readonly duration: 270;
47
+ readonly curve: readonly [0.26, 0.08, 0.25, 1];
48
+ };
49
+ /** Invalid fixed detents are programmer errors, before they reach either sheet backend. */
50
+ export declare function validateSnapPoints(points: readonly SheetSnapPoint[], initialIndex?: number): void;
@@ -0,0 +1,105 @@
1
+ /** A detent as visible height in points, from points or a percentage of the room the sheet has. Invalid input reads as 0. */
2
+ export function detentHeight(point, room) {
3
+ 'worklet';
4
+ const raw = typeof point === 'number' ? point : parseFloat(point) / 100 * room;
5
+ return Number.isFinite(raw) ? Math.max(0, Math.min(raw, room)) : 0;
6
+ }
7
+ /** Detent heights for fixed snap points: clamped to the room, sorted increasing, without duplicates or empty detents. */
8
+ export function detentHeights(points, room) {
9
+ 'worklet';
10
+ const heights = [];
11
+ for (const point of points) {
12
+ const height = detentHeight(point, room);
13
+ if (height > 0 && !heights.includes(height))
14
+ heights.push(height);
15
+ }
16
+ return heights.sort((a, b) => a - b);
17
+ }
18
+ /**
19
+ * Resistance past the sheet's limit: the further the finger goes, the less the sheet follows, and it never passes `limit`
20
+ * points. The same curve UIScrollView uses.
21
+ */
22
+ export function rubberBand(overshoot, limit) {
23
+ 'worklet';
24
+ if (overshoot <= 0 || limit <= 0)
25
+ return 0;
26
+ return (1 - 1 / (overshoot * 0.55 / limit + 1)) * limit;
27
+ }
28
+ /** Where a drag puts the sheet: 1:1 between the top detent and closed, resisting above the top detent, and resisting below the lowest detent when it cannot be dismissed. */
29
+ export function dragPosition(raw, top, lowest, closed, dismissible) {
30
+ 'worklet';
31
+ if (raw < top)
32
+ return top - rubberBand(top - raw, Math.max(top, 64));
33
+ const floor = dismissible ? closed : lowest;
34
+ if (raw > floor)
35
+ return dismissible ? closed : floor + rubberBand(raw - floor, Math.max(closed - floor, 64));
36
+ return raw;
37
+ }
38
+ /** How far ahead of the finger a release is read, in seconds: a flick lands where its momentum would carry it. */
39
+ export const SHEET_PROJECTION = 0.18;
40
+ /** A release slower than this (points per second) is a placement, not a flick. */
41
+ export const SHEET_FLICK = 500;
42
+ /**
43
+ * The detent a release settles on, as an index into `positions` (increasing translateY, so index 0 is the tallest), or -1 to
44
+ * close. A flick moves one detent in its direction, or closes from the lowest; a slow release takes the nearest detent, or
45
+ * closes when the sheet is more than half way from the lowest detent to closed.
46
+ */
47
+ export function releaseTarget(position, velocity, positions, closed, dismissible) {
48
+ 'worklet';
49
+ if (positions.length === 0)
50
+ return -1;
51
+ const lowestIndex = positions.length - 1, lowest = positions[lowestIndex];
52
+ let nearest = 0;
53
+ for (let index = 1; index < positions.length; index++)
54
+ if (Math.abs(positions[index] - position) < Math.abs(positions[nearest] - position))
55
+ nearest = index;
56
+ if (Math.abs(velocity) >= SHEET_FLICK) {
57
+ const projected = position + velocity * SHEET_PROJECTION;
58
+ if (velocity > 0) {
59
+ // Downward: the next detent below where the finger let go, or closed.
60
+ for (let index = 0; index < positions.length; index++)
61
+ if (positions[index] > position + 1)
62
+ return index;
63
+ return dismissible && projected > lowest ? -1 : lowestIndex;
64
+ }
65
+ for (let index = lowestIndex; index >= 0; index--)
66
+ if (positions[index] < position - 1)
67
+ return index;
68
+ return 0;
69
+ }
70
+ if (dismissible && position > lowest + (closed - lowest) / 2)
71
+ return -1;
72
+ return nearest;
73
+ }
74
+ /**
75
+ * The spring every settle uses: critically damped (damping = 2·√(stiffness·mass)), so the sheet lands without a bounce and
76
+ * without a slow tail, in about a third of a second. An overdamped spring creeps to rest and keeps drawing frames long
77
+ * after the sheet looks still (measured on a Seeker: animating almost a second per settle).
78
+ */
79
+ export const SHEET_SPRING = { damping: 36, stiffness: 320, mass: 1, overshootClamping: true };
80
+ /** Backdrop strength for a position: full at the lowest detent and above, fading to none at closed. */
81
+ export function backdropProgress(position, lowest, closed) {
82
+ 'worklet';
83
+ if (closed <= lowest)
84
+ return position >= closed ? 0 : 1;
85
+ return Math.max(0, Math.min(1, (closed - position) / (closed - lowest)));
86
+ }
87
+ /**
88
+ * How a content-sized sheet moves when its content changes height while it rests: one curve with no spring and no
89
+ * overshoot, a short ease in and a long ease out, the values of Vaul's Dynamic Drawer. Drag releases, opening and closing
90
+ * use the spring.
91
+ */
92
+ export const SHEET_RESIZE = { duration: 270, curve: [0.26, 0.08, 0.25, 1] };
93
+ /** Invalid fixed detents are programmer errors, before they reach either sheet backend. */
94
+ export function validateSnapPoints(points, initialIndex = 0) {
95
+ if (!points.length)
96
+ throw new Error('GestureSheet requires at least one snap point.');
97
+ if (!Number.isInteger(initialIndex) || initialIndex < 0)
98
+ throw new RangeError('GestureSheet initialIndex must be a nonnegative integer.');
99
+ for (const point of points) {
100
+ const percent = typeof point === 'string';
101
+ const value = percent ? Number(point.slice(0, -1)) : point;
102
+ if ((percent && !/^\d+(?:\.\d+)?%$/.test(point)) || !Number.isFinite(value) || value <= 0 || (percent && value > 100))
103
+ throw new RangeError('GestureSheet snap points must be positive finite points or percentages up to 100%.');
104
+ }
105
+ }
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+ import { Text as RNText, TextInput, View, type StyleProp, type ViewStyle } from 'react-native';
3
+ import Reanimated from 'react-native-reanimated';
4
+ import { type SheetSnapPoint } from './gesture-sheet-model.js';
5
+ export type { SheetSnapPoint } from './gesture-sheet-model.js';
6
+ type FocusTarget = React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null;
7
+ interface SheetCommonProps {
8
+ open: boolean;
9
+ onOpenChange: (open: boolean) => void;
10
+ /** Names the sheet. Drawn as the heading in default mode; in custom mode it is read by assistive technology unless `titleRef` points at the host's own heading. */
11
+ title: string;
12
+ description?: string;
13
+ children: React.ReactNode;
14
+ /** Default anatomy scrolls the title, description, content and a Close action. Custom content owns layout, scrolling and its own way out. */
15
+ contentMode?: 'default' | 'custom';
16
+ /** In custom mode, the host's accessible title. It takes accessibility focus when the sheet opens. */
17
+ titleRef?: React.RefObject<FocusTarget>;
18
+ /** Takes accessibility focus back when the sheet has closed. */
19
+ returnFocusRef?: React.RefObject<FocusTarget>;
20
+ /** `nativeID` of a heading inside the sheet that names it (Android `accessibilityLabelledBy`). Same prop as web. */
21
+ labelledBy?: string;
22
+ /** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
23
+ closeLabel?: string;
24
+ /** `false` blocks every dismissal the user can start: drag, backdrop press, Android Back and the accessibility escape. Default `true`. */
25
+ dismissible?: boolean;
26
+ /** Modal draws in the nearest `GestureSheetHost`, above the screen. Inline draws where it is rendered and keeps its children mounted while closed. */
27
+ presentation?: 'modal' | 'inline';
28
+ /** Called once after an accepted dismissal has finished moving. */
29
+ onDismiss?: () => void;
30
+ /** Called with the detent index (0 is the lowest) each time the sheet settles on one. */
31
+ onChange?: (index: number) => void;
32
+ /** Return true to consume Android Back, or false to leave it to another handler. Omit for default dismissal. */
33
+ onHardwareBackPress?: () => boolean;
34
+ /** Room kept clear above the sheet, and padding under its content so nothing sits behind the home indicator. Default to the safe-area insets; pass `bottomInset={0}` for content that runs to the edge. */
35
+ topInset?: number;
36
+ bottomInset?: number;
37
+ /** Draws the drag handle. Default `true`. The whole sheet drags either way. */
38
+ handle?: boolean;
39
+ /** Merged over the sheet's fill, radius and clipping. */
40
+ backgroundStyle?: StyleProp<ViewStyle>;
41
+ /** Content sits one elevation up, so wells and rows step up a shade on the `overlay` fill. Pass `false` when `backgroundStyle` paints the page background. Default `true`. */
42
+ raised?: boolean;
43
+ /** Scales the modal scrim behind the sheet (the same scrim as Dialog), 0 to 1. Default 1; 0 draws none and lets presses through. */
44
+ backdropOpacity?: number;
45
+ /** Prefix of the test IDs: `<testID>`, `-backdrop`, `-surface`, `-handle` and `-content`. */
46
+ testID?: string;
47
+ }
48
+ export type GestureSheetProps = SheetCommonProps & (
49
+ /** Fixed detents, as points or a percentage of the room under `topInset`. Sorted for you; `initialIndex` counts from the lowest. */
50
+ {
51
+ enableDynamicSizing?: false;
52
+ snapPoints: readonly SheetSnapPoint[];
53
+ initialIndex?: number;
54
+ maxDynamicContentSize?: never;
55
+ }
56
+ /** One detent as tall as the content, up to `maxDynamicContentSize` points (default: all the room). */
57
+ | {
58
+ enableDynamicSizing: true;
59
+ snapPoints?: never;
60
+ initialIndex?: never;
61
+ maxDynamicContentSize?: number;
62
+ });
63
+ /**
64
+ * Where modal sheets draw: wrap the screen (inside GestureHandlerRootView and SafeAreaProvider) once. Sheets render in a
65
+ * layer over its children, so they cover the tab bar and anything else inside it. Without a host a modal sheet draws in place.
66
+ */
67
+ export declare function GestureSheetHost({ children, style }: {
68
+ children: React.ReactNode;
69
+ style?: StyleProp<ViewStyle>;
70
+ }): React.JSX.Element;
71
+ /**
72
+ * A ScrollView that shares the drag with its sheet: at the top detent it scrolls, and a pull down from the top of the
73
+ * content moves the sheet; below the top detent the drag moves the sheet and the content stays put. Outside a sheet it is a
74
+ * plain ScrollView. Bounce and overscroll are off so the content cannot move while the sheet does.
75
+ */
76
+ export declare const GestureSheetScrollView: React.ForwardRefExoticComponent<Omit<import("react-native-reanimated").AnimatedScrollViewProps, "ref"> & React.RefAttributes<Reanimated.ScrollView>>;
77
+ /**
78
+ * HIG's own sheet, one engine for iOS and Android: Reanimated moves it and Gesture Handler reads the finger, both on the UI
79
+ * thread. While it moves only a transform and the backdrop's opacity change, so content of any weight costs no layout per frame.
80
+ * Host supplies GestureHandlerRootView, SafeAreaProvider and, for modal sheets, GestureSheetHost.
81
+ */
82
+ export declare const GestureSheet: React.MemoExoticComponent<(props: GestureSheetProps) => React.JSX.Element | null>;
@@ -0,0 +1,315 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { validateSnapPoints } from './gesture-sheet-model.js';
3
+ import React, { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from 'react';
4
+ import { AccessibilityInfo, BackHandler, findNodeHandle, Keyboard, Platform, Pressable, StyleSheet, View } from 'react-native';
5
+ import Reanimated, { cancelAnimation, Easing, ReduceMotion, runOnJS, useAnimatedProps, useAnimatedReaction, useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useSharedValue, withSpring, withTiming } from 'react-native-reanimated';
6
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
7
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
8
+ import { nativeMetrics as tokens } from '@bloxwap/hig/tokens';
9
+ import * as en from '@bloxwap/hig/contracts/messages';
10
+ import { Raised, useColors, useHIG } from './provider.js';
11
+ import { Heading, Text, Stack } from './surface.js';
12
+ import { Button } from './button.js';
13
+ import { backdropProgress, detentHeights, dragPosition, releaseTarget, SHEET_RESIZE, SHEET_SPRING } from './gesture-sheet-model.js';
14
+ const HostContext = createContext(null);
15
+ /**
16
+ * Where modal sheets draw: wrap the screen (inside GestureHandlerRootView and SafeAreaProvider) once. Sheets render in a
17
+ * layer over its children, so they cover the tab bar and anything else inside it. Without a host a modal sheet draws in place.
18
+ */
19
+ export function GestureSheetHost({ children, style }) {
20
+ const [layers, setLayers] = useState([]);
21
+ const value = useMemo(() => ({
22
+ show: (id, node) => setLayers(current => { const index = current.findIndex(layer => layer.id === id); if (index < 0)
23
+ return [...current, { id, node }]; if (current[index].node === node)
24
+ return current; const next = current.slice(); next[index] = { id, node }; return next; }),
25
+ hide: id => setLayers(current => current.some(layer => layer.id === id) ? current.filter(layer => layer.id !== id) : current),
26
+ }), []);
27
+ return _jsx(HostContext.Provider, { value: value, children: _jsxs(View, { style: [styles.fill, style], children: [children, layers.map(layer => _jsx(View, { pointerEvents: 'box-none', style: StyleSheet.absoluteFill, children: layer.node }, layer.id))] }) });
28
+ }
29
+ const ScrollContext = createContext(null);
30
+ /**
31
+ * A ScrollView that shares the drag with its sheet: at the top detent it scrolls, and a pull down from the top of the
32
+ * content moves the sheet; below the top detent the drag moves the sheet and the content stays put. Outside a sheet it is a
33
+ * plain ScrollView. Bounce and overscroll are off so the content cannot move while the sheet does.
34
+ */
35
+ export const GestureSheetScrollView = React.forwardRef(function GestureSheetScrollView(props, ref) {
36
+ const sheet = useContext(ScrollContext);
37
+ const ownY = useSharedValue(0), ownCount = useSharedValue(0), free = useSharedValue(true);
38
+ const scrollY = sheet?.scrollY ?? ownY, scrollers = sheet?.scrollers ?? ownCount, atTop = sheet?.atTop ?? free, pan = sheet?.pan;
39
+ const native = useMemo(() => pan ? Gesture.Native().simultaneousWithExternalGesture(pan) : Gesture.Native(), [pan]);
40
+ useEffect(() => { scrollers.value += 1; return () => { scrollers.value -= 1; scrollY.value = 0; }; }, [scrollers, scrollY]);
41
+ const onScroll = useAnimatedScrollHandler(event => {
42
+ 'worklet';
43
+ scrollY.value = event.contentOffset.y;
44
+ });
45
+ const animatedProps = useAnimatedProps(() => {
46
+ 'worklet';
47
+ return { scrollEnabled: atTop.value };
48
+ });
49
+ return _jsx(GestureDetector, { gesture: native, children: _jsx(Reanimated.ScrollView, { keyboardShouldPersistTaps: 'handled', ...props, ref: ref, bounces: false, overScrollMode: 'never', scrollEventThrottle: 16, onScroll: onScroll, animatedProps: animatedProps }) });
50
+ });
51
+ const RESIZE = { duration: SHEET_RESIZE.duration, easing: Easing.bezier(...SHEET_RESIZE.curve) };
52
+ const focusOn = (node) => { if (!node)
53
+ return; try {
54
+ const handle = findNodeHandle(node);
55
+ if (handle != null) {
56
+ AccessibilityInfo.setAccessibilityFocus(handle);
57
+ if (Platform.OS === 'android')
58
+ AccessibilityInfo.sendAccessibilityEvent(node, 'viewHoverEnter');
59
+ }
60
+ }
61
+ catch { /* A detached focus target cannot block the sheet. */ } };
62
+ const OFFSCREEN = 100000;
63
+ /** The sheet itself. It lives in the host's layer (modal) or in place (inline), so a parent re-render reaches it only through the props below. */
64
+ function Surface({ open, onOpenChange, title, description, children, contentMode = 'default', titleRef, returnFocusRef, labelledBy, closeLabel, dismissible = true, presentation = 'modal', onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, handle = true, backgroundStyle, raised = true, backdropOpacity = 1, testID, snapPoints, initialIndex = 0, enableDynamicSizing = false, maxDynamicContentSize, onClosed }) {
65
+ const env = useHIG(), colors = useColors(), insets = useSafeAreaInsets();
66
+ const top = topInset ?? insets.top, bottom = bottomInset ?? insets.bottom;
67
+ const id = (part) => testID === undefined ? undefined : part ? `${testID}-${part}` : testID;
68
+ const heading = useRef(null);
69
+ const latest = useRef({ open, onOpenChange, onDismiss, onChange, onHardwareBackPress, onClosed, returnFocusRef, titleRef, contentMode });
70
+ latest.current = { open, onOpenChange, onDismiss, onChange, onHardwareBackPress, onClosed, returnFocusRef, titleRef, contentMode };
71
+ // Layout the JS side needs: the room under the top inset sizes the content box. It changes on rotation and when Android resizes the window for the keyboard, not while the sheet moves.
72
+ const [room, setRoom] = useState(0);
73
+ const roomValue = useSharedValue(0), contentHeight = useSharedValue(0), position = useSharedValue(OFFSCREEN), dragStart = useSharedValue(0), rebase = useSharedValue(0), dragging = useSharedValue(false), closing = useSharedValue(false), shown = useSharedValue(open), keyboard = useSharedValue(0), kick = useSharedValue(0);
74
+ const points = useSharedValue(snapPoints ?? []), dynamic = useSharedValue(enableDynamicSizing), ceiling = useSharedValue(maxDynamicContentSize ?? 0), canDismiss = useSharedValue(dismissible), reduce = useSharedValue(env.reducedMotion);
75
+ const detentCount = enableDynamicSizing ? 1 : (snapPoints ?? []).length;
76
+ const active = useSharedValue(Math.max(0, Math.min(initialIndex, detentCount - 1)));
77
+ const scrollY = useSharedValue(0), scrollers = useSharedValue(0);
78
+ const pointsKey = JSON.stringify(snapPoints ?? []);
79
+ useEffect(() => { points.value = snapPoints ?? []; dynamic.value = enableDynamicSizing; ceiling.value = maxDynamicContentSize ?? 0; canDismiss.value = dismissible; reduce.value = env.reducedMotion; }, [pointsKey, enableDynamicSizing, maxDynamicContentSize, dismissible, env.reducedMotion]);
80
+ // translateY of each detent, tallest first. Empty until the sheet knows its room (and, sized by content, its content).
81
+ const positions = useDerivedValue(() => {
82
+ 'worklet';
83
+ const space = roomValue.value;
84
+ if (space <= 0)
85
+ return [];
86
+ const heights = dynamic.value ? (contentHeight.value > 0 ? [Math.min(contentHeight.value, ceiling.value > 0 ? Math.min(ceiling.value, space) : space)] : []) : detentHeights(points.value, space);
87
+ const result = [];
88
+ for (let index = heights.length - 1; index >= 0; index--)
89
+ result.push(space - heights[index]);
90
+ return result;
91
+ });
92
+ const atTop = useDerivedValue(() => {
93
+ 'worklet';
94
+ return positions.value.length === 0 || position.value <= positions.value[0] + 0.5;
95
+ });
96
+ const reported = useRef(-1);
97
+ const settled = useCallback((index) => {
98
+ if (!latest.current.open || reported.current === index)
99
+ return;
100
+ reported.current = index;
101
+ latest.current.onChange?.(index);
102
+ }, []);
103
+ const requested = useRef(false);
104
+ const requestClose = useCallback(() => { if (requested.current || !latest.current.open)
105
+ return; requested.current = true; latest.current.onOpenChange(false); }, []);
106
+ // An inline sheet first mounts closed. Only a sheet that was shown can be dismissed.
107
+ const presented = useRef(false), closeFrame = useRef(null);
108
+ const finishClose = useCallback(() => {
109
+ // One frame for a host that answers `onOpenChange(false)` asynchronously, then: still open means the dismissal was rejected and the sheet returns to its detent.
110
+ if (closeFrame.current !== null)
111
+ cancelAnimationFrame(closeFrame.current);
112
+ closeFrame.current = requestAnimationFrame(() => {
113
+ closeFrame.current = null;
114
+ requested.current = false;
115
+ closing.value = false;
116
+ if (latest.current.open) {
117
+ kick.value += 1;
118
+ return;
119
+ }
120
+ if (!presented.current)
121
+ return;
122
+ presented.current = false;
123
+ reported.current = -1;
124
+ focusOn(latest.current.returnFocusRef?.current ?? null);
125
+ latest.current.onDismiss?.();
126
+ latest.current.onClosed();
127
+ });
128
+ }, [closing, kick]);
129
+ useEffect(() => () => { if (closeFrame.current !== null)
130
+ cancelAnimationFrame(closeFrame.current); }, []);
131
+ useEffect(() => { requested.current = false; shown.value = open; if (open) {
132
+ presented.current = true;
133
+ reported.current = -1;
134
+ active.value = Math.max(0, Math.min(initialIndex, detentCount - 1));
135
+ } }, [open]);
136
+ // Open focus: once per presentation, after the first frame so the content exists.
137
+ useEffect(() => { if (!open)
138
+ return; const frame = requestAnimationFrame(() => focusOn(latest.current.contentMode === 'custom' ? (latest.current.titleRef?.current ?? heading.current) : heading.current)); return () => cancelAnimationFrame(frame); }, [open]);
139
+ useEffect(() => { if (!open)
140
+ return; const subscription = BackHandler.addEventListener('hardwareBackPress', () => { if (latest.current.onHardwareBackPress)
141
+ return latest.current.onHardwareBackPress(); if (dismissible)
142
+ requestClose(); return true; }); return () => subscription.remove(); }, [open, dismissible, requestClose]);
143
+ // iOS lifts the sheet over the keyboard. Android resizes the window instead, which arrives here as a new room.
144
+ useEffect(() => { if (Platform.OS !== 'ios')
145
+ return; const show = Keyboard.addListener('keyboardWillShow', event => { keyboard.value = withTiming(event.endCoordinates.height, { duration: event.duration || 250 }); }), hide = Keyboard.addListener('keyboardWillHide', event => { keyboard.value = withTiming(0, { duration: event.duration || 250 }); }); return () => { show.remove(); hide.remove(); }; }, [keyboard]);
146
+ // The one place the sheet is told where to rest: opening, closing, a new detent set and content that changed height all arrive here and become one spring on the UI thread.
147
+ useAnimatedReaction(() => {
148
+ 'worklet';
149
+ const list = positions.value, space = roomValue.value;
150
+ if (space <= 0)
151
+ return { target: -1, kick: kick.value, index: active.value };
152
+ if (!shown.value)
153
+ return { target: space, kick: kick.value, index: active.value };
154
+ if (list.length === 0)
155
+ return { target: -1, kick: kick.value, index: active.value };
156
+ const index = Math.max(0, Math.min(list.length - 1, active.value));
157
+ return { target: list[list.length - 1 - index], kick: kick.value, index };
158
+ }, (next, previous) => {
159
+ 'worklet';
160
+ const target = next.target;
161
+ if (target < 0 || dragging.value || (previous !== null && target === previous.target && next.kick === previous.kick && next.index === previous.index))
162
+ return;
163
+ const space = roomValue.value;
164
+ if (position.value > space)
165
+ position.value = space;
166
+ const closes = target >= space;
167
+ if (closes && closing.value)
168
+ return;
169
+ const motion = { ...SHEET_SPRING, reduceMotion: reduce.value ? ReduceMotion.Always : ReduceMotion.System };
170
+ if (closes) {
171
+ closing.value = true;
172
+ position.value = withSpring(target, motion, finished => {
173
+ 'worklet';
174
+ if (finished)
175
+ runOnJS(finishClose)();
176
+ });
177
+ return;
178
+ }
179
+ const index = next.index;
180
+ active.value = index;
181
+ // Content that changed height while the sheet rests moves on the resize curve. Opening and a new detent index use the spring.
182
+ const resized = previous !== null && previous.target >= 0 && previous.target < space && next.kick === previous.kick && next.index === previous.index;
183
+ if (resized && !reduce.value) {
184
+ position.value = withTiming(target, RESIZE, finished => {
185
+ 'worklet';
186
+ if (finished)
187
+ runOnJS(settled)(index);
188
+ });
189
+ return;
190
+ }
191
+ position.value = withSpring(target, motion, finished => {
192
+ 'worklet';
193
+ if (finished)
194
+ runOnJS(settled)(index);
195
+ });
196
+ });
197
+ const pan = useMemo(() => Gesture.Pan().activeOffsetY([-6, 6]).failOffsetX([-28, 28])
198
+ .onStart(() => {
199
+ 'worklet';
200
+ cancelAnimation(position);
201
+ dragStart.value = position.value;
202
+ rebase.value = 0;
203
+ dragging.value = true;
204
+ closing.value = false;
205
+ })
206
+ .onChange(event => {
207
+ 'worklet';
208
+ const list = positions.value;
209
+ if (list.length === 0)
210
+ return;
211
+ const space = roomValue.value, highest = list[0], lowest = list[list.length - 1];
212
+ // At the top detent with the content scrolled, the scroller owns the drag. The sheet holds still and the drag is rebased, so it picks up from here once the content is back at its top.
213
+ if (scrollers.value > 0 && dragStart.value <= highest + 0.5 && (scrollY.value > 0 || event.translationY - rebase.value < 0)) {
214
+ rebase.value = event.translationY;
215
+ position.value = highest;
216
+ return;
217
+ }
218
+ position.value = dragPosition(dragStart.value + event.translationY - rebase.value, highest, lowest, space, canDismiss.value);
219
+ })
220
+ .onEnd(event => {
221
+ 'worklet';
222
+ dragging.value = false;
223
+ const list = positions.value;
224
+ if (list.length === 0)
225
+ return;
226
+ const space = roomValue.value, target = releaseTarget(position.value, event.velocityY, list, space, canDismiss.value);
227
+ const motion = { ...SHEET_SPRING, velocity: event.velocityY, reduceMotion: reduce.value ? ReduceMotion.Always : ReduceMotion.System };
228
+ if (target < 0) {
229
+ closing.value = true;
230
+ runOnJS(requestClose)();
231
+ position.value = withSpring(space, motion, finished => {
232
+ 'worklet';
233
+ if (finished)
234
+ runOnJS(finishClose)();
235
+ });
236
+ return;
237
+ }
238
+ const index = list.length - 1 - target;
239
+ active.value = index;
240
+ position.value = withSpring(list[target], motion, finished => {
241
+ 'worklet';
242
+ if (finished)
243
+ runOnJS(settled)(index);
244
+ });
245
+ })
246
+ .onFinalize(() => {
247
+ 'worklet';
248
+ dragging.value = false;
249
+ }), []);
250
+ const scroll = useMemo(() => ({ pan, scrollY, scrollers, atTop }), [pan, scrollY, scrollers, atTop]);
251
+ // Only transforms and opacity change while the sheet moves, so no frame lays anything out.
252
+ const surfaceStyle = useAnimatedStyle(() => {
253
+ 'worklet';
254
+ return { transform: [{ translateY: Math.max(0, position.value - keyboard.value) }] };
255
+ });
256
+ const backdropStyle = useAnimatedStyle(() => {
257
+ 'worklet';
258
+ const list = positions.value, space = roomValue.value;
259
+ return { opacity: list.length === 0 ? 0 : backdropProgress(position.value, list[list.length - 1], space) * backdropOpacity };
260
+ });
261
+ const onRoom = useCallback((event) => { const next = Math.max(0, event.nativeEvent.layout.height - top); roomValue.value = next; setRoom(current => current === next ? current : next); }, [top, roomValue]);
262
+ const onContent = useCallback((event) => { contentHeight.value = event.nativeEvent.layout.height; }, [contentHeight]);
263
+ const tallest = useMemo(() => enableDynamicSizing ? 0 : Math.max(0, ...detentHeights(snapPoints ?? [], room)), [enableDynamicSizing, pointsKey, room]);
264
+ const limit = enableDynamicSizing ? (maxDynamicContentSize ? Math.min(maxDynamicContentSize, room) : room) : tallest;
265
+ const modal = presentation === 'modal';
266
+ const accessibility = { ...(modal ? { accessibilityViewIsModal: true, onAccessibilityEscape: dismissible ? requestClose : undefined } : { accessibilityElementsHidden: !open, importantForAccessibility: open ? 'auto' : 'no-hide-descendants' }), ...(labelledBy ? { accessibilityLabelledBy: labelledBy } : {}) };
267
+ const hiddenTitle = !titleRef ? _jsx(Heading, { ref: heading, accessible: true, accessibilityLabel: title, style: styles.hidden, children: title }) : null;
268
+ const content = contentMode === 'custom'
269
+ ? _jsxs(View, { ...accessibility, testID: id('content'), collapsable: false, style: [enableDynamicSizing ? styles.shrink : styles.grow, { direction: env.direction }], children: [hiddenTitle, children] })
270
+ : _jsx(GestureSheetScrollView, { ...accessibility, testID: id('content'), style: enableDynamicSizing ? styles.shrink : styles.grow, contentContainerStyle: { padding: tokens.space.xl, paddingBottom: tokens.space.xl + bottom, direction: env.direction }, children: _jsxs(Stack, { children: [_jsx(Heading, { ref: heading, children: title }), description ? _jsx(Text, { children: description }) : null, children, _jsx(Button, { intent: 'secondary', onPress: requestClose, children: closeLabel ?? env.messages.close ?? en.close })] }) });
271
+ const lifted = raised ? _jsx(Raised, { children: content }) : content;
272
+ return _jsxs(View, { testID: id(''), pointerEvents: open ? 'box-none' : 'none', style: StyleSheet.absoluteFill, onLayout: onRoom, children: [backdropOpacity > 0 ? _jsx(Reanimated.View, { testID: id('backdrop'), pointerEvents: open ? 'auto' : 'none', style: [StyleSheet.absoluteFill, styles.backdrop, backdropStyle], children: _jsx(Pressable, { accessible: false, importantForAccessibility: 'no', style: styles.fill, onPress: dismissible ? requestClose : undefined }) }) : null, _jsx(GestureDetector, { gesture: pan, children: _jsx(Reanimated.View, { testID: id('surface'), renderToHardwareTextureAndroid: true, style: [styles.surface, { top, backgroundColor: colors.overlay, borderTopLeftRadius: tokens.radius.xl, borderTopRightRadius: tokens.radius.xl }, backgroundStyle, surfaceStyle], children: room > 0 ? _jsx(ScrollContext.Provider, { value: scroll, children: _jsxs(View, { onLayout: onContent, style: [enableDynamicSizing ? { maxHeight: limit } : { height: limit }, contentMode === 'custom' ? { paddingBottom: bottom } : null], children: [handle ? _jsx(View, { testID: id('handle'), accessible: false, importantForAccessibility: 'no', style: styles.handle, children: _jsx(View, { style: [styles.grip, { backgroundColor: colors.action }] }) }) : null, lifted] }) }) : null }) })] });
273
+ }
274
+ /**
275
+ * HIG's own sheet, one engine for iOS and Android: Reanimated moves it and Gesture Handler reads the finger, both on the UI
276
+ * thread. While it moves only a transform and the backdrop's opacity change, so content of any weight costs no layout per frame.
277
+ * Host supplies GestureHandlerRootView, SafeAreaProvider and, for modal sheets, GestureSheetHost.
278
+ */
279
+ export const GestureSheet = React.memo(function GestureSheet(props) {
280
+ if (!props.enableDynamicSizing)
281
+ validateSnapPoints(props.snapPoints ?? [], props.initialIndex);
282
+ if (props.enableDynamicSizing && props.snapPoints !== undefined)
283
+ throw new Error('Content-sized GestureSheet does not accept fixed snapPoints.');
284
+ if (!props.enableDynamicSizing && (props.snapPoints ?? []).length === 0)
285
+ throw new Error('GestureSheet requires at least one snap point.');
286
+ if (props.maxDynamicContentSize !== undefined && (!Number.isFinite(props.maxDynamicContentSize) || props.maxDynamicContentSize <= 0))
287
+ throw new Error('GestureSheet maxDynamicContentSize must be finite and greater than zero.');
288
+ const host = useContext(HostContext), key = useId(), inline = props.presentation === 'inline' || !host;
289
+ // A modal sheet stays mounted from the moment it opens until its closing motion has finished.
290
+ const [mounted, setMounted] = useState(props.open);
291
+ if (props.open && !mounted)
292
+ setMounted(true);
293
+ const onClosed = useCallback(() => setMounted(false), []);
294
+ const surface = _jsx(Surface, { ...props, onClosed: onClosed });
295
+ useEffect(() => { if (inline || !host)
296
+ return; if (mounted)
297
+ host.show(key, surface);
298
+ else
299
+ host.hide(key); });
300
+ useEffect(() => () => { if (host)
301
+ host.hide(key); }, [host, key]);
302
+ if (!inline)
303
+ return null;
304
+ return props.presentation === 'inline' || mounted ? surface : null;
305
+ });
306
+ const styles = StyleSheet.create({
307
+ fill: { flex: 1 },
308
+ backdrop: { backgroundColor: '#000b' },
309
+ surface: { position: 'absolute', left: 0, right: 0, bottom: 0, overflow: 'hidden' },
310
+ handle: { alignItems: 'center', paddingTop: 12, paddingBottom: 8 },
311
+ grip: { width: 36, height: 5, borderRadius: 3 },
312
+ grow: { flex: 1, minHeight: 0 },
313
+ shrink: { flexShrink: 1, minHeight: 0 },
314
+ hidden: { position: 'absolute', width: 1, height: 1, overflow: 'hidden' },
315
+ });
@@ -36,12 +36,16 @@ interface GestureSheetCommonProps {
36
36
  handleIndicatorStyle?: BottomSheetModalProps['handleIndicatorStyle'];
37
37
  backgroundComponent?: BottomSheetModalProps['backgroundComponent'];
38
38
  backgroundStyle?: BottomSheetModalProps['backgroundStyle'];
39
+ /** Content sits one elevation up, so wells, list rows and quiet fills step up one shade to stay visible on HIG's `overlay` fill. Pass `false` when `backgroundStyle` or `backgroundComponent` paints the page `background` instead; the fills then match the page. Defaults to `true`. */
40
+ raised?: boolean;
39
41
  /** Screen-level inline hosts may retain their existing sibling overlay order. */
40
42
  containerStyle?: BottomSheetModalProps['containerStyle'];
41
43
  /** Optional host animation and backdrop policies; HIG reduced-motion mapping remains applied. */
42
44
  animateOnMount?: BottomSheetModalProps['animateOnMount'];
43
45
  animationConfigs?: BottomSheetModalProps['animationConfigs'];
44
46
  backdropComponent?: BottomSheetModalProps['backdropComponent'];
47
+ /** `nativeID` of a heading inside the sheet that names it, such as a block's `headingId`: the sheet's content takes `accessibilityLabelledBy` (Android). The `title` still names the sheet elsewhere. Same prop as web. */
48
+ labelledBy?: string;
45
49
  }
46
50
  export type GestureSheetProps = GestureSheetCommonProps & (
47
51
  /** Modal is the default. Inline retains the screen-level backend and its child state while closed. */
@@ -69,5 +73,5 @@ export type GestureSheetProps = GestureSheetCommonProps & (
69
73
  maxDynamicContentSize?: BottomSheetModalProps['maxDynamicContentSize'];
70
74
  });
71
75
  /** Optional backend: host supplies GestureHandlerRootView, SafeAreaProvider and BottomSheetModalProvider. */
72
- export declare function GestureSheet({ open, onOpenChange, title, description, children, contentMode, titleRef, presentation, sheetRef, snapPoints, enableDynamicSizing, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, initialIndex, dismissible, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent }: GestureSheetProps): React.JSX.Element;
76
+ export declare function GestureSheet({ open, onOpenChange, title, description, children, contentMode, raised, titleRef, presentation, sheetRef, snapPoints, enableDynamicSizing, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, initialIndex, dismissible, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent, labelledBy }: GestureSheetProps): React.JSX.Element;
73
77
  export {};