glacia-native 0.5.1 → 0.6.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 (403) hide show
  1. package/LICENSE +29 -4
  2. package/README.md +111 -17
  3. package/lib/module/Accordion.js +58 -0
  4. package/lib/module/ActionSheet.js +38 -0
  5. package/lib/module/Alert.js +23 -0
  6. package/lib/module/AlertDialog.js +47 -0
  7. package/lib/module/Avatar.js +48 -0
  8. package/lib/module/Badge.js +36 -0
  9. package/lib/module/Bars.js +13 -267
  10. package/lib/module/Button.js +57 -36
  11. package/lib/module/Card.js +32 -20
  12. package/lib/module/Checkbox.js +42 -0
  13. package/lib/module/Chip.js +80 -0
  14. package/lib/module/Collapsible.js +26 -0
  15. package/lib/module/ContextMenu.js +33 -0
  16. package/lib/module/Dialog.js +39 -124
  17. package/lib/module/DropdownMenu.js +33 -0
  18. package/lib/module/Field.js +22 -0
  19. package/lib/module/Glass.js +12 -5
  20. package/lib/module/Group.js +36 -0
  21. package/lib/module/IconButton.js +40 -0
  22. package/lib/module/Input.js +47 -40
  23. package/lib/module/Label.js +17 -0
  24. package/lib/module/MorphGroup.js +47 -0
  25. package/lib/module/Popover.js +29 -0
  26. package/lib/module/Progress.js +32 -0
  27. package/lib/module/RadioGroup.js +51 -0
  28. package/lib/module/Scrim.js +44 -0
  29. package/lib/module/SegmentedControl.js +74 -58
  30. package/lib/module/Select.js +51 -0
  31. package/lib/module/Separator.js +25 -0
  32. package/lib/module/Sheet.js +51 -0
  33. package/lib/module/Skeleton.js +48 -0
  34. package/lib/module/Slider.js +60 -40
  35. package/lib/module/Stepper.js +167 -0
  36. package/lib/module/Switch.js +45 -43
  37. package/lib/module/TabBar.js +62 -50
  38. package/lib/module/Tabs.js +3 -2
  39. package/lib/module/Textarea.js +18 -0
  40. package/lib/module/Toast.js +55 -0
  41. package/lib/module/Toggle.js +47 -0
  42. package/lib/module/ToggleGroup.js +56 -0
  43. package/lib/module/Toolbar.js +37 -0
  44. package/lib/module/Tooltip.js +31 -0
  45. package/lib/module/glass-provider.js +28 -0
  46. package/lib/module/glass-stack.js +61 -0
  47. package/lib/module/index.js +78 -109
  48. package/lib/module/internal/GlassBackdrop.js +36 -0
  49. package/lib/module/internal/GlassView.js +45 -13
  50. package/lib/module/internal/blur-community.js +20 -0
  51. package/lib/module/internal/blur-community.web.js +9 -0
  52. package/lib/module/internal/blur.js +75 -0
  53. package/lib/module/internal/fallback.js +110 -20
  54. package/lib/module/internal/glass-routing.js +154 -30
  55. package/lib/module/internal/glow.js +36 -0
  56. package/lib/module/internal/initials.js +12 -0
  57. package/lib/module/internal/lens.js +70 -0
  58. package/lib/module/internal/material.js +64 -0
  59. package/lib/module/internal/overlay.js +147 -0
  60. package/lib/module/internal/primitives.js +17 -0
  61. package/lib/module/internal/rim.js +35 -0
  62. package/lib/module/internal/tokens.js +34 -2
  63. package/lib/typescript/Accordion.d.ts +22 -0
  64. package/lib/typescript/ActionSheet.d.ts +24 -0
  65. package/lib/typescript/Alert.d.ts +15 -0
  66. package/lib/typescript/AlertDialog.d.ts +17 -0
  67. package/lib/typescript/Avatar.d.ts +22 -0
  68. package/lib/typescript/Badge.d.ts +12 -0
  69. package/lib/typescript/Bars.d.ts +3 -188
  70. package/lib/typescript/Button.d.ts +44 -10
  71. package/lib/typescript/Card.d.ts +30 -3
  72. package/lib/typescript/Checkbox.d.ts +14 -0
  73. package/lib/typescript/Chip.d.ts +19 -0
  74. package/lib/typescript/Collapsible.d.ts +17 -0
  75. package/lib/typescript/ContextMenu.d.ts +23 -0
  76. package/lib/typescript/Dialog.d.ts +8 -68
  77. package/lib/typescript/DropdownMenu.d.ts +23 -0
  78. package/lib/typescript/Field.d.ts +19 -0
  79. package/lib/typescript/Glass.d.ts +11 -2
  80. package/lib/typescript/Group.d.ts +35 -0
  81. package/lib/typescript/IconButton.d.ts +21 -0
  82. package/lib/typescript/Input.d.ts +17 -18
  83. package/lib/typescript/Label.d.ts +14 -0
  84. package/lib/typescript/MorphGroup.d.ts +46 -0
  85. package/lib/typescript/Popover.d.ts +17 -0
  86. package/lib/typescript/Progress.d.ts +13 -0
  87. package/lib/typescript/RadioGroup.d.ts +21 -0
  88. package/lib/typescript/Scrim.d.ts +33 -0
  89. package/lib/typescript/SegmentedControl.d.ts +24 -13
  90. package/lib/typescript/Select.d.ts +19 -0
  91. package/lib/typescript/Separator.d.ts +10 -0
  92. package/lib/typescript/Sheet.d.ts +45 -0
  93. package/lib/typescript/Skeleton.d.ts +10 -0
  94. package/lib/typescript/Slider.d.ts +15 -7
  95. package/lib/typescript/Stepper.d.ts +49 -0
  96. package/lib/typescript/Switch.d.ts +19 -12
  97. package/lib/typescript/TabBar.d.ts +18 -6
  98. package/lib/typescript/Textarea.d.ts +6 -0
  99. package/lib/typescript/Toast.d.ts +40 -0
  100. package/lib/typescript/Toggle.d.ts +21 -0
  101. package/lib/typescript/ToggleGroup.d.ts +22 -0
  102. package/lib/typescript/Toolbar.d.ts +35 -0
  103. package/lib/typescript/Tooltip.d.ts +16 -0
  104. package/lib/typescript/glass-provider.d.ts +34 -0
  105. package/lib/typescript/glass-stack.d.ts +54 -0
  106. package/lib/typescript/index.d.ts +39 -17
  107. package/lib/typescript/internal/GlassBackdrop.d.ts +33 -0
  108. package/lib/typescript/internal/GlassView.d.ts +31 -2
  109. package/lib/typescript/internal/blur-community.d.ts +2 -0
  110. package/lib/typescript/internal/blur-community.web.d.ts +2 -0
  111. package/lib/typescript/internal/blur.d.ts +24 -0
  112. package/lib/typescript/internal/fallback.d.ts +27 -2
  113. package/lib/typescript/internal/glass-routing.d.ts +83 -15
  114. package/lib/typescript/internal/glow.d.ts +11 -0
  115. package/lib/typescript/internal/initials.d.ts +2 -0
  116. package/lib/typescript/internal/lens.d.ts +47 -0
  117. package/lib/typescript/internal/material.d.ts +27 -0
  118. package/lib/typescript/internal/overlay.d.ts +74 -0
  119. package/lib/typescript/internal/primitives.d.ts +13 -0
  120. package/lib/typescript/internal/rim.d.ts +16 -0
  121. package/lib/typescript/internal/tokens.d.ts +36 -0
  122. package/package.json +15 -4
  123. package/src/Accordion.tsx +165 -0
  124. package/src/ActionSheet.tsx +149 -0
  125. package/src/Alert.tsx +85 -0
  126. package/src/AlertDialog.tsx +124 -0
  127. package/src/Avatar.tsx +102 -0
  128. package/src/Badge.tsx +80 -0
  129. package/src/Bars.tsx +10 -797
  130. package/src/Button.tsx +196 -60
  131. package/src/Card.tsx +106 -33
  132. package/src/Checkbox.tsx +98 -0
  133. package/src/Chip.tsx +149 -0
  134. package/src/Collapsible.tsx +66 -0
  135. package/src/ContextMenu.tsx +103 -0
  136. package/src/Dialog.tsx +86 -325
  137. package/src/DropdownMenu.tsx +103 -0
  138. package/src/Field.tsx +65 -0
  139. package/src/Glass.tsx +19 -5
  140. package/src/Group.tsx +98 -0
  141. package/src/IconButton.tsx +110 -0
  142. package/src/Input.tsx +143 -87
  143. package/src/Label.tsx +56 -0
  144. package/src/MorphGroup.tsx +134 -0
  145. package/src/Popover.tsx +81 -0
  146. package/src/Progress.tsx +83 -0
  147. package/src/RadioGroup.tsx +122 -0
  148. package/src/Scrim.tsx +94 -0
  149. package/src/SegmentedControl.tsx +147 -90
  150. package/src/Select.tsx +136 -0
  151. package/src/Separator.tsx +52 -0
  152. package/src/Sheet.tsx +139 -0
  153. package/src/Skeleton.tsx +77 -0
  154. package/src/Slider.tsx +100 -54
  155. package/src/Stepper.tsx +315 -0
  156. package/src/Switch.tsx +80 -58
  157. package/src/TabBar.tsx +118 -84
  158. package/src/Tabs.tsx +5 -0
  159. package/src/Textarea.tsx +34 -0
  160. package/src/Toast.tsx +131 -0
  161. package/src/Toggle.tsx +113 -0
  162. package/src/ToggleGroup.tsx +129 -0
  163. package/src/Toolbar.tsx +111 -0
  164. package/src/Tooltip.tsx +79 -0
  165. package/src/engine/CHANGELOG.md +430 -0
  166. package/src/engine/NOTICE +54 -0
  167. package/src/engine/README.md +975 -0
  168. package/src/engine/android/build.gradle +18 -0
  169. package/src/engine/android/src/main/AndroidManifest.xml +2 -0
  170. package/src/engine/android/src/main/java/expo/modules/liquidglass/ExpoLiquidGlassModule.kt +174 -0
  171. package/src/engine/android/src/main/java/expo/modules/liquidglass/GlassConstants.kt +7 -0
  172. package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassContainerView.kt +16 -0
  173. package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassProviderView.kt +165 -0
  174. package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassView.kt +1731 -0
  175. package/src/engine/android/src/main/java/expo/modules/liquidglass/enums/GlassEnums.kt +171 -0
  176. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/BackdropGraph.kt +146 -0
  177. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/BackdropSource.kt +53 -0
  178. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/ContinuousCorners.kt +188 -0
  179. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/CornerRadii.kt +62 -0
  180. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassAppearance.kt +352 -0
  181. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassDebug.kt +109 -0
  182. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassEnvironment.kt +139 -0
  183. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassHdr.kt +85 -0
  184. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassLuminanceProbe.kt +189 -0
  185. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassPressAnimator.kt +264 -0
  186. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassProgressiveBlur.kt +249 -0
  187. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassShaderCache.kt +256 -0
  188. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassShaderSource.kt +845 -0
  189. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassTier.kt +63 -0
  190. package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/ProviderRegistry.kt +71 -0
  191. package/src/engine/android/src/main/java/expo/modules/liquidglass/records/GlassRecords.kt +288 -0
  192. package/src/engine/index.ts +24 -0
  193. package/src/engine/ios/Enums/GlassBlurDirection.swift +21 -0
  194. package/src/engine/ios/Enums/GlassVariant.swift +86 -0
  195. package/src/engine/ios/ExpoLiquidGlass.podspec +93 -0
  196. package/src/engine/ios/ExpoLiquidGlassModule.swift +77 -0
  197. package/src/engine/ios/Glass/BackdropCapturer.swift +811 -0
  198. package/src/engine/ios/Glass/ContinuousCorners.swift +165 -0
  199. package/src/engine/ios/Glass/GlassBackdrop.swift +176 -0
  200. package/src/engine/ios/Glass/GlassFramePhase.swift +126 -0
  201. package/src/engine/ios/Glass/GlassFrameScheduler.swift +261 -0
  202. package/src/engine/ios/Glass/GlassPressAnimator.swift +250 -0
  203. package/src/engine/ios/Glass/GlassRenderContext.swift +168 -0
  204. package/src/engine/ios/Glass/GlassRenderer.swift +186 -0
  205. package/src/engine/ios/Glass/GlassSurfaceView.swift +452 -0
  206. package/src/engine/ios/Glass/NonRenderableView.swift +54 -0
  207. package/src/engine/ios/Glass/StripCache.swift +545 -0
  208. package/src/engine/ios/Records/GlassCornerRadii.swift +79 -0
  209. package/src/engine/ios/Records/GlassMetalOptions.swift +180 -0
  210. package/src/engine/ios/Records/GlassRefractionCurve.swift +14 -0
  211. package/src/engine/ios/Shaders/LiquidGlass.metal +480 -0
  212. package/src/engine/ios/Shaders/bundle-marker.txt +6 -0
  213. package/src/engine/ios/Views/LiquidGlassContainerView.swift +99 -0
  214. package/src/engine/ios/Views/LiquidGlassView.swift +859 -0
  215. package/src/engine/package.json +70 -0
  216. package/src/engine/src/components/LiquidGlassButton/LiquidGlassButton.tsx +424 -0
  217. package/src/engine/src/components/LiquidGlassCard/LiquidGlassCard.tsx +98 -0
  218. package/src/engine/src/components/LiquidGlassChip/LiquidGlassChip.tsx +65 -0
  219. package/src/engine/src/components/LiquidGlassGroup/LiquidGlassGroup.tsx +350 -0
  220. package/src/engine/src/components/LiquidGlassIconButton/LiquidGlassIconButton.tsx +24 -0
  221. package/src/engine/src/components/LiquidGlassMorphGroup/LiquidGlassMorphGroup.tsx +434 -0
  222. package/src/engine/src/components/LiquidGlassScrim/LiquidGlassScrim.tsx +100 -0
  223. package/src/engine/src/components/LiquidGlassSegmentedControl/LiquidGlassSegmentedControl.tsx +213 -0
  224. package/src/engine/src/components/LiquidGlassSheet/LiquidGlassSheet.tsx +218 -0
  225. package/src/engine/src/components/LiquidGlassSlider/LiquidGlassSlider.tsx +327 -0
  226. package/src/engine/src/components/LiquidGlassStepper/LiquidGlassStepper.tsx +321 -0
  227. package/src/engine/src/components/LiquidGlassSwitch/LiquidGlassSwitch.tsx +296 -0
  228. package/src/engine/src/components/LiquidGlassTabBar/LiquidGlassTabBar.tsx +952 -0
  229. package/src/engine/src/components/LiquidGlassTextInput/LiquidGlassTextInput.tsx +151 -0
  230. package/src/engine/src/components/LiquidGlassToast/LiquidGlassToast.tsx +169 -0
  231. package/src/engine/src/components/LiquidGlassToolbar/LiquidGlassToolbar.tsx +124 -0
  232. package/src/engine/src/components/index.ts +16 -0
  233. package/src/engine/src/constants/index.ts +4 -0
  234. package/src/engine/src/constants/metal.constants.ts +327 -0
  235. package/src/engine/src/constants/metrics.constants.ts +325 -0
  236. package/src/engine/src/constants/springs.constants.ts +107 -0
  237. package/src/engine/src/constants/styles.constants.ts +12 -0
  238. package/src/engine/src/context/glass-group.context.ts +65 -0
  239. package/src/engine/src/context/index.ts +6 -0
  240. package/src/engine/src/core/components/LiquidGlassContainer/LiquidGlassContainer.tsx +32 -0
  241. package/src/engine/src/core/components/LiquidGlassContainer/index.ts +1 -0
  242. package/src/engine/src/core/components/LiquidGlassProvider/LiquidGlassProvider.tsx +66 -0
  243. package/src/engine/src/core/components/LiquidGlassProvider/index.ts +1 -0
  244. package/src/engine/src/core/components/LiquidGlassStack/LiquidGlassStack.tsx +184 -0
  245. package/src/engine/src/core/components/LiquidGlassStack/index.ts +1 -0
  246. package/src/engine/src/core/components/LiquidGlassView/LiquidGlassView.tsx +126 -0
  247. package/src/engine/src/core/components/LiquidGlassView/index.ts +1 -0
  248. package/src/engine/src/core/components/index.ts +4 -0
  249. package/src/engine/src/core/constants/glass.constants.ts +57 -0
  250. package/src/engine/src/core/constants/index.ts +20 -0
  251. package/src/engine/src/core/constants/native.constants.ts +16 -0
  252. package/src/engine/src/core/context/glass-stack.context.ts +30 -0
  253. package/src/engine/src/core/context/index.ts +4 -0
  254. package/src/engine/src/core/enum/index.ts +12 -0
  255. package/src/engine/src/core/index.ts +1 -0
  256. package/src/engine/src/core/interfaces/glass-hdr.interface.ts +15 -0
  257. package/src/engine/src/core/interfaces/glass-metal.interface.ts +248 -0
  258. package/src/engine/src/core/interfaces/glass-surface.interface.ts +9 -0
  259. package/src/engine/src/core/interfaces/index.ts +31 -0
  260. package/src/engine/src/core/interfaces/liquid-glass-container.interface.ts +6 -0
  261. package/src/engine/src/core/interfaces/liquid-glass-provider.interface.ts +14 -0
  262. package/src/engine/src/core/interfaces/liquid-glass-stack.interface.ts +21 -0
  263. package/src/engine/src/core/interfaces/liquid-glass-view.interface.ts +129 -0
  264. package/src/engine/src/core/interfaces/native-liquid-glass-view.interface.ts +19 -0
  265. package/src/engine/src/core/modules/ExpoLiquidGlassModule.ts +26 -0
  266. package/src/engine/src/core/modules/index.ts +2 -0
  267. package/src/engine/src/core/root/index.ts +51 -0
  268. package/src/engine/src/core/types/glass.types.ts +25 -0
  269. package/src/engine/src/core/types/index.ts +8 -0
  270. package/src/engine/src/core/utils/debug.utils.ts +17 -0
  271. package/src/engine/src/core/utils/dev-warn.utils.ts +17 -0
  272. package/src/engine/src/core/utils/hdr.utils.ts +37 -0
  273. package/src/engine/src/core/utils/index.ts +5 -0
  274. package/src/engine/src/core/utils/native-view.utils.ts +33 -0
  275. package/src/engine/src/core/utils/platform.utils.ts +34 -0
  276. package/src/engine/src/core/views/NativeGlassBackdropView.ts +24 -0
  277. package/src/engine/src/core/views/NativeLiquidGlassContainerView.ts +13 -0
  278. package/src/engine/src/core/views/NativeLiquidGlassContainerView.web.ts +10 -0
  279. package/src/engine/src/core/views/NativeLiquidGlassProviderView.ts +13 -0
  280. package/src/engine/src/core/views/NativeLiquidGlassProviderView.web.ts +10 -0
  281. package/src/engine/src/core/views/NativeLiquidGlassView.ts +19 -0
  282. package/src/engine/src/core/views/NativeLiquidGlassView.web.ts +14 -0
  283. package/src/engine/src/core/views/index.ts +4 -0
  284. package/src/engine/src/hooks/index.ts +18 -0
  285. package/src/engine/src/hooks/use-adaptive-glass.ts +91 -0
  286. package/src/engine/src/hooks/use-damped-drag.ts +332 -0
  287. package/src/engine/src/hooks/use-echo-filter.ts +55 -0
  288. package/src/engine/src/hooks/use-glass-group-member.ts +169 -0
  289. package/src/engine/src/hooks/use-gravity-highlight.ts +79 -0
  290. package/src/engine/src/hooks/use-press-progress.ts +44 -0
  291. package/src/engine/src/index.ts +120 -0
  292. package/src/engine/src/interfaces/index.ts +28 -0
  293. package/src/engine/src/interfaces/liquid-glass-button.interface.ts +94 -0
  294. package/src/engine/src/interfaces/liquid-glass-card.interface.ts +40 -0
  295. package/src/engine/src/interfaces/liquid-glass-chip.interface.ts +29 -0
  296. package/src/engine/src/interfaces/liquid-glass-group.interface.ts +32 -0
  297. package/src/engine/src/interfaces/liquid-glass-icon-button.interface.ts +19 -0
  298. package/src/engine/src/interfaces/liquid-glass-morph-group.interface.ts +59 -0
  299. package/src/engine/src/interfaces/liquid-glass-scrim.interface.ts +36 -0
  300. package/src/engine/src/interfaces/liquid-glass-segmented-control.interface.ts +32 -0
  301. package/src/engine/src/interfaces/liquid-glass-sheet.interface.ts +38 -0
  302. package/src/engine/src/interfaces/liquid-glass-slider.interface.ts +37 -0
  303. package/src/engine/src/interfaces/liquid-glass-stepper.interface.ts +35 -0
  304. package/src/engine/src/interfaces/liquid-glass-switch.interface.ts +27 -0
  305. package/src/engine/src/interfaces/liquid-glass-tab-bar.interface.ts +116 -0
  306. package/src/engine/src/interfaces/liquid-glass-text-input.interface.ts +42 -0
  307. package/src/engine/src/interfaces/liquid-glass-toast.interface.ts +36 -0
  308. package/src/engine/src/interfaces/liquid-glass-toolbar.interface.ts +33 -0
  309. package/src/engine/src/theme/glass-ui-theme.ts +100 -0
  310. package/src/engine/src/theme/index.ts +2 -0
  311. package/src/engine/src/utils/button-press.utils.ts +63 -0
  312. package/src/engine/src/utils/index.ts +3 -0
  313. package/src/engine/src/utils/metal.utils.ts +164 -0
  314. package/src/glass-provider.tsx +60 -0
  315. package/src/glass-stack.tsx +115 -0
  316. package/src/index.ts +48 -190
  317. package/src/internal/GlassBackdrop.tsx +60 -0
  318. package/src/internal/GlassView.tsx +70 -18
  319. package/src/internal/blur-community.ts +19 -0
  320. package/src/internal/blur-community.web.ts +7 -0
  321. package/src/internal/blur.ts +89 -0
  322. package/src/internal/fallback.tsx +158 -20
  323. package/src/internal/glass-routing.ts +211 -34
  324. package/src/internal/glow.tsx +62 -0
  325. package/src/internal/initials.ts +7 -0
  326. package/src/internal/lens.tsx +105 -0
  327. package/src/internal/material.ts +92 -0
  328. package/src/internal/overlay.tsx +258 -0
  329. package/src/internal/primitives.ts +26 -0
  330. package/src/internal/rim.tsx +79 -0
  331. package/src/internal/tokens.ts +34 -1
  332. package/lib/module/Carousel.js +0 -103
  333. package/lib/module/Display.js +0 -317
  334. package/lib/module/Feedback.js +0 -386
  335. package/lib/module/Form.js +0 -164
  336. package/lib/module/Forms2.js +0 -454
  337. package/lib/module/Message.js +0 -88
  338. package/lib/module/Overlays.js +0 -328
  339. package/lib/module/Pickers.js +0 -243
  340. package/lib/module/Table.js +0 -99
  341. package/lib/module/ai.js +0 -280
  342. package/lib/module/charts/AreaChart.js +0 -32
  343. package/lib/module/charts/BarChart.js +0 -67
  344. package/lib/module/charts/FunnelChart.js +0 -50
  345. package/lib/module/charts/HeatmapChart.js +0 -71
  346. package/lib/module/charts/LineChart.js +0 -81
  347. package/lib/module/charts/PlotChart.js +0 -52
  348. package/lib/module/charts/RadarChart.js +0 -78
  349. package/lib/module/charts/RingChart.js +0 -52
  350. package/lib/module/charts/ScatterChart.js +0 -95
  351. package/lib/module/charts/WaterfallChart.js +0 -85
  352. package/lib/module/charts/advanced.js +0 -313
  353. package/lib/module/charts/extra.js +0 -108
  354. package/lib/module/charts/index.js +0 -50
  355. package/lib/module/charts/scales.js +0 -140
  356. package/lib/typescript/Carousel.d.ts +0 -47
  357. package/lib/typescript/Display.d.ts +0 -178
  358. package/lib/typescript/Feedback.d.ts +0 -196
  359. package/lib/typescript/Form.d.ts +0 -97
  360. package/lib/typescript/Forms2.d.ts +0 -209
  361. package/lib/typescript/Message.d.ts +0 -71
  362. package/lib/typescript/Overlays.d.ts +0 -146
  363. package/lib/typescript/Pickers.d.ts +0 -105
  364. package/lib/typescript/Table.d.ts +0 -64
  365. package/lib/typescript/ai.d.ts +0 -166
  366. package/lib/typescript/charts/AreaChart.d.ts +0 -44
  367. package/lib/typescript/charts/BarChart.d.ts +0 -19
  368. package/lib/typescript/charts/FunnelChart.d.ts +0 -25
  369. package/lib/typescript/charts/HeatmapChart.d.ts +0 -23
  370. package/lib/typescript/charts/LineChart.d.ts +0 -30
  371. package/lib/typescript/charts/PlotChart.d.ts +0 -31
  372. package/lib/typescript/charts/RadarChart.d.ts +0 -27
  373. package/lib/typescript/charts/RingChart.d.ts +0 -28
  374. package/lib/typescript/charts/ScatterChart.d.ts +0 -34
  375. package/lib/typescript/charts/WaterfallChart.d.ts +0 -22
  376. package/lib/typescript/charts/advanced.d.ts +0 -107
  377. package/lib/typescript/charts/extra.d.ts +0 -63
  378. package/lib/typescript/charts/index.d.ts +0 -13
  379. package/lib/typescript/charts/scales.d.ts +0 -35
  380. package/src/Carousel.tsx +0 -233
  381. package/src/Display.tsx +0 -778
  382. package/src/Feedback.tsx +0 -969
  383. package/src/Form.tsx +0 -425
  384. package/src/Forms2.tsx +0 -1014
  385. package/src/Message.tsx +0 -219
  386. package/src/Overlays.tsx +0 -685
  387. package/src/Pickers.tsx +0 -590
  388. package/src/Table.tsx +0 -231
  389. package/src/ai.tsx +0 -707
  390. package/src/charts/AreaChart.tsx +0 -73
  391. package/src/charts/BarChart.tsx +0 -183
  392. package/src/charts/FunnelChart.tsx +0 -125
  393. package/src/charts/HeatmapChart.tsx +0 -155
  394. package/src/charts/LineChart.tsx +0 -247
  395. package/src/charts/PlotChart.tsx +0 -168
  396. package/src/charts/RadarChart.tsx +0 -208
  397. package/src/charts/RingChart.tsx +0 -133
  398. package/src/charts/ScatterChart.tsx +0 -223
  399. package/src/charts/WaterfallChart.tsx +0 -201
  400. package/src/charts/advanced.tsx +0 -676
  401. package/src/charts/extra.tsx +0 -242
  402. package/src/charts/index.ts +0 -86
  403. package/src/charts/scales.ts +0 -163
package/src/Overlays.tsx DELETED
@@ -1,685 +0,0 @@
1
- import { forwardRef, useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
2
- import type { StyleProp, ViewStyle } from "react-native";
3
-
4
- import { Glass } from "./Glass";
5
- import { Text } from "./Text";
6
- import { colors, radii } from "./internal/tokens";
7
- import { primitives } from "./internal/primitives";
8
- import { useIsDark, useSpring } from "./internal/motion";
9
- import { hapticSelection } from "./internal/haptics";
10
-
11
- /**
12
- * Registers Android's hardware back while an overlay is open.
13
- *
14
- * Shared by Menu, Sheet and Drawer so every overlay dismisses the same way a
15
- * Dialog does: the back button closes the layer, not the screen behind it.
16
- */
17
- function useBackDismiss(open: boolean, onDismiss: () => void) {
18
- useEffect(() => {
19
- if (!open) return;
20
- const BackHandler = primitives().getBackHandler();
21
- if (!BackHandler) return;
22
- const sub = BackHandler.addEventListener("hardwareBackPress", () => {
23
- onDismiss();
24
- return true;
25
- });
26
- return () => sub.remove();
27
- }, [open, onDismiss]);
28
- }
29
-
30
- /**
31
- * Keeps a popover inside the window.
32
- *
33
- * Called with the trigger's measured frame and the popover's own size; returns
34
- * the offsets that bring it back on screen. A menu near the bottom edge flips
35
- * above its trigger rather than hanging off the display.
36
- */
37
- export function anchorPopover(
38
- trigger: { x: number; y: number; width: number; height: number },
39
- popover: { width: number; height: number },
40
- viewport: { width: number; height: number },
41
- gap = 6,
42
- ): { left: number; top: number; flipped: boolean } {
43
- const below = trigger.y + trigger.height + gap;
44
- const above = trigger.y - popover.height - gap;
45
- const fitsBelow = below + popover.height <= viewport.height;
46
- const flipped = !fitsBelow && above >= 0;
47
- const top = Math.max(0, Math.min(flipped ? above : below, viewport.height - popover.height));
48
- const left = Math.max(0, Math.min(trigger.x, viewport.width - popover.width));
49
- return { left, top, flipped };
50
- }
51
-
52
- // ---------------------------------------------------------------------------
53
- // Menu
54
-
55
- export interface MenuItem {
56
- label: string;
57
- onPress: () => void;
58
- icon?: ReactNode;
59
- disabled?: boolean;
60
- /** Renders in the destructive tone, for delete-and-similar. */
61
- destructive?: boolean;
62
- accessibilityLabel?: string;
63
- }
64
-
65
- export interface MenuProps {
66
- /** The control that opens the menu. */
67
- trigger: ReactNode;
68
- items: MenuItem[];
69
- /** Controlled open state. Omit and the menu keeps its own. */
70
- open?: boolean;
71
- onOpenChange?: (open: boolean) => void;
72
- /** The menu's width. The list scrolls if the items exceed the screen. */
73
- width?: number;
74
- accessibilityLabel?: string;
75
- style?: StyleProp<ViewStyle>;
76
- isDark?: boolean;
77
- testID?: string;
78
- }
79
-
80
- /**
81
- * An anchored dropdown menu.
82
- *
83
- * A press outside or on an item closes it; Android's back button does too. The
84
- * popover is a glass surface with `glassActive` rows, matching the way the
85
- * library marks a tappable row rather than nesting another glass panel.
86
- */
87
- export const Menu = forwardRef<any, MenuProps>(function Menu(
88
- {
89
- trigger,
90
- items,
91
- open: openProp,
92
- onOpenChange,
93
- width = 220,
94
- accessibilityLabel = "Menu",
95
- style,
96
- isDark: isDarkProp,
97
- testID,
98
- ...props
99
- },
100
- ref,
101
- ) {
102
- const isDark = useIsDark(isDarkProp);
103
- const theme = isDark ? colors.dark : colors.light;
104
- const { View, Text: RNText, Pressable, Modal } = primitives();
105
-
106
- const [internalOpen, setInternalOpen] = useState(false);
107
- const open = openProp !== undefined ? openProp : internalOpen;
108
-
109
- const setOpen = useCallback(
110
- (next: boolean) => {
111
- if (openProp === undefined) setInternalOpen(next);
112
- onOpenChange?.(next);
113
- },
114
- [openProp, onOpenChange],
115
- );
116
-
117
- const dismiss = useCallback(() => setOpen(false), [setOpen]);
118
- useBackDismiss(open, dismiss);
119
-
120
- const { value: enter, animated } = useSpring(open ? 1 : 0, "snappy");
121
- const scale = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [0.96, 1] }) : 1;
122
-
123
- const popover = (
124
- <Glass
125
- effect="regular"
126
- isDark={isDark}
127
- testID={testID ? `${testID}-popover` : undefined}
128
- style={{ width, borderRadius: radii.md, paddingVertical: 4, overflow: "hidden", ...(style as ViewStyle) }}
129
- >
130
- {items.map((item, index) => (
131
- <Pressable
132
- key={`${item.label}-${index}`}
133
- accessibilityRole="button"
134
- accessibilityLabel={item.accessibilityLabel ?? item.label}
135
- accessibilityState={{ disabled: item.disabled }}
136
- disabled={item.disabled}
137
- onPress={() => {
138
- setOpen(false);
139
- item.onPress();
140
- }}
141
- style={{ flexDirection: "row", alignItems: "center", gap: 10, paddingVertical: 10, paddingHorizontal: 12, opacity: item.disabled ? 0.38 : 1 }}
142
- >
143
- {item.icon ? <View>{item.icon}</View> : null}
144
- <RNText
145
- numberOfLines={1}
146
- style={{ fontSize: 15, color: item.destructive ? theme.destructive : theme.foreground }}
147
- >
148
- {item.label}
149
- </RNText>
150
- </Pressable>
151
- ))}
152
- </Glass>
153
- );
154
-
155
- return (
156
- <View ref={ref} style={{ alignSelf: "flex-start" }} {...props}>
157
- <Pressable
158
- accessibilityRole="button"
159
- accessibilityLabel={accessibilityLabel}
160
- accessibilityState={{ expanded: open }}
161
- onPress={() => setOpen(!open)}
162
- >
163
- {trigger}
164
- </Pressable>
165
-
166
- <Modal visible={open} transparent animationType="fade" onRequestClose={dismiss}>
167
- {/* The backdrop: any press outside the popover dismisses the menu. */}
168
- <Pressable
169
- accessibilityRole="button"
170
- accessibilityLabel="Close menu"
171
- onPress={dismiss}
172
- style={{ flex: 1, backgroundColor: theme.scrim }}
173
- >
174
- <View style={{ flex: 1, alignItems: "center", justifyContent: "center", padding: 24 }}>
175
- <Pressable accessibilityRole="none" onPress={() => {}}>
176
- {animated ? (
177
- <AnimatedScale scale={scale}>{popover}</AnimatedScale>
178
- ) : (
179
- popover
180
- )}
181
- </Pressable>
182
- </View>
183
- </Pressable>
184
- </Modal>
185
- </View>
186
- );
187
- });
188
-
189
- /** Wraps a popover in the entrance scale, which must land on an Animated.View. */
190
- function AnimatedScale({ scale, children }: { scale: any; children: ReactNode }) {
191
- const { Animated } = primitives();
192
- return <Animated.View style={{ transform: [{ scale }] }}>{children}</Animated.View>;
193
- }
194
-
195
- // ---------------------------------------------------------------------------
196
- // Sheet
197
-
198
- export interface SheetProps {
199
- /** Controlled visibility. Omit and the sheet keeps its own. */
200
- open?: boolean;
201
- defaultOpen?: boolean;
202
- onOpenChange?: (open: boolean) => void;
203
- title?: string;
204
- children?: ReactNode;
205
- footer?: ReactNode;
206
- /** Tapping the scrim dismisses. */
207
- dismissOnBackdropPress?: boolean;
208
- /** The drag handle at the top of the panel. */
209
- showHandle?: boolean;
210
- /**
211
- * Resting heights the sheet can settle at, smallest first. A number is
212
- * points; a fraction below 1 is a share of the window height. With one
213
- * point the sheet opens there; with several it can be dragged between them.
214
- * Omitted, the sheet uses its own natural height.
215
- */
216
- snapPoints?: number[];
217
- /** Which snap point to open at. Defaults to the first. */
218
- initialSnapIndex?: number;
219
- /** Controlled snap point. Omit and the sheet tracks its own. */
220
- snapIndex?: number;
221
- onSnapIndexChange?: (index: number) => void;
222
- /** Dragging below the lowest point dismisses instead of springing back. */
223
- dismissOnSnapToBottom?: boolean;
224
- /** Turns the drag gesture off, leaving press-and-back dismissal only. */
225
- draggable?: boolean;
226
- /** Opt out of the selection tick on snap changes. */
227
- haptics?: boolean;
228
- style?: StyleProp<ViewStyle>;
229
- isDark?: boolean;
230
- testID?: string;
231
- }
232
-
233
- /**
234
- * A bottom sheet.
235
- *
236
- * The general-purpose container: it slides up on the springs token, dismisses
237
- * on a scrim press and on Android back. ActionSheet remains the action-menu
238
- * specialisation of this shape; Sheet is for arbitrary content — a form, a
239
- * calendar, a detail panel.
240
- */
241
- /**
242
- * Turns a snap point into a pixel height.
243
- *
244
- * A number under 1 is a fraction of the window; anything else is points. The
245
- * result is clamped so a sheet can never be taller than the space it has.
246
- */
247
- export function resolveSnapPoint(point: number, windowHeight: number): number {
248
- const height = point > 0 && point < 1 ? point * windowHeight : point;
249
- return Math.max(0, Math.min(height, windowHeight));
250
- }
251
-
252
- /**
253
- * Picks the snap point nearest to where the user let go.
254
- *
255
- * `height` is how tall the sheet currently is. Ties go to the smaller sheet,
256
- * so a small flick does not jump the panel to full height.
257
- */
258
- export function nearestSnapPoint(heights: number[], height: number): number {
259
- let best = 0;
260
- let bestDistance = Number.POSITIVE_INFINITY;
261
- heights.forEach((candidate, index) => {
262
- const distance = Math.abs(candidate - height);
263
- if (distance < bestDistance) {
264
- bestDistance = distance;
265
- best = index;
266
- }
267
- });
268
- return best;
269
- }
270
-
271
- export const Sheet = forwardRef<any, SheetProps>(function Sheet(
272
- {
273
- open: openProp,
274
- defaultOpen = false,
275
- onOpenChange,
276
- title,
277
- children,
278
- footer,
279
- dismissOnBackdropPress = true,
280
- showHandle = true,
281
- snapPoints,
282
- initialSnapIndex = 0,
283
- snapIndex: snapIndexProp,
284
- onSnapIndexChange,
285
- dismissOnSnapToBottom = false,
286
- draggable = true,
287
- haptics = true,
288
- style,
289
- isDark: isDarkProp,
290
- testID,
291
- ...props
292
- },
293
- ref,
294
- ) {
295
- const isDark = useIsDark(isDarkProp);
296
- const theme = isDark ? colors.dark : colors.light;
297
- const { View, Text: RNText, Pressable, Modal, PanResponder, useWindowDimensions } = primitives();
298
-
299
- const [internalOpen, setInternalOpen] = useState(defaultOpen);
300
- const open = openProp !== undefined ? openProp : internalOpen;
301
-
302
- const setOpen = useCallback(
303
- (next: boolean) => {
304
- if (openProp === undefined) setInternalOpen(next);
305
- onOpenChange?.(next);
306
- },
307
- [openProp, onOpenChange],
308
- );
309
-
310
- const dismiss = useCallback(() => setOpen(false), [setOpen]);
311
- useBackDismiss(open, dismiss);
312
-
313
- // Snap points in pixels, smallest first so index 0 is the shortest sheet.
314
- const windowHeight = useWindowDimensions?.().height ?? 800;
315
- const heights = useMemo(() => {
316
- if (!snapPoints || snapPoints.length === 0) return [];
317
- return snapPoints.map((point) => resolveSnapPoint(point, windowHeight)).sort((a, b) => a - b);
318
- }, [snapPoints, windowHeight]);
319
-
320
- const [internalSnap, setInternalSnap] = useState(initialSnapIndex);
321
- const snapIndex = snapIndexProp !== undefined ? snapIndexProp : internalSnap;
322
- const activeHeight = heights.length > 0 ? heights[Math.min(snapIndex, heights.length - 1)]! : null;
323
-
324
- // Drag offset in pixels: 0 is resting at the active snap point, positive is
325
- // dragged down. It resets to 0 after a release, because the settle either
326
- // changes the snap index or dismisses.
327
- const dragRef = useRef(0);
328
- const [drag, setDrag] = useState(0);
329
-
330
- const { value: rise, animated } = useSpring(open ? 1 : 0, "gentle");
331
- const slideIn = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: [420, 0] }) : 0;
332
-
333
- const heightsRef = useRef(heights);
334
- heightsRef.current = heights;
335
- const activeHeightRef = useRef(activeHeight);
336
- activeHeightRef.current = activeHeight;
337
- const snapIndexRef = useRef(snapIndex);
338
- snapIndexRef.current = snapIndex;
339
-
340
- const goToSnap = useCallback(
341
- (index: number) => {
342
- if (snapIndexProp === undefined) setInternalSnap(index);
343
- onSnapIndexChange?.(index);
344
- if (haptics) hapticSelection();
345
- },
346
- [snapIndexProp, onSnapIndexChange, haptics],
347
- );
348
-
349
- /**
350
- * The release decision.
351
- *
352
- * Below the lowest snap point the sheet dismisses when allowed, otherwise it
353
- * snaps back; anywhere else it settles at the nearest point, with a fast
354
- * downward flick counting as a step towards the smaller sheet.
355
- */
356
- const release = useCallback(
357
- (dy: number, vy: number) => {
358
- const list = heightsRef.current;
359
- const current = list[snapIndexRef.current] ?? activeHeightRef.current ?? 0;
360
- const restingAfterDrag = current - dy;
361
-
362
- if (list.length === 0) {
363
- // No snap points: a decisive downward drag dismisses.
364
- if (dy > 120 || vy > 0.8) dismiss();
365
- return;
366
- }
367
-
368
- const lowest = list[0]!;
369
- const belowLowest = restingAfterDrag < lowest - 40;
370
- if (belowLowest && dismissOnSnapToBottom) {
371
- dismiss();
372
- return;
373
- }
374
-
375
- // A fast flick moves one step in its direction before distance decides.
376
- let index = nearestSnapPoint(list, restingAfterDrag);
377
- if (vy > 0.5) index = Math.max(0, Math.min(index, snapIndexRef.current - 1));
378
- if (vy < -0.5) index = Math.max(index, Math.min(snapIndexRef.current + 1, list.length - 1));
379
-
380
- if (index !== snapIndexRef.current) goToSnap(index);
381
- },
382
- [dismiss, dismissOnSnapToBottom, goToSnap],
383
- );
384
-
385
- const panResponder = useMemo(() => {
386
- if (!draggable || !PanResponder?.create) return null;
387
- return PanResponder.create({
388
- // Vertical drags belong to the sheet; horizontal ones are left alone.
389
- onStartShouldSetPanResponder: () => false,
390
- onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
391
- Math.abs(gesture.dy) > Math.abs(gesture.dx) && Math.abs(gesture.dy) > 6,
392
- onPanResponderGrant: () => {
393
- dragRef.current = 0;
394
- },
395
- onPanResponderMove: (_event: any, gesture: any) => {
396
- // Dragging up past the tallest point has nowhere to go; clamp at 0.
397
- const next = Math.max(-40, gesture.dy);
398
- dragRef.current = next;
399
- setDrag(next);
400
- },
401
- onPanResponderRelease: (_event: any, gesture: any) => {
402
- release(gesture.dy, gesture.vy);
403
- dragRef.current = 0;
404
- setDrag(0);
405
- },
406
- onPanResponderTerminate: () => {
407
- dragRef.current = 0;
408
- setDrag(0);
409
- },
410
- onPanResponderTerminationRequest: () => false,
411
- });
412
- }, [draggable, PanResponder, release]);
413
-
414
- // Reduce Motion is honoured by useSpring: when it is on, `animated` is false
415
- // and the panel is already in position, so the sheet opens and snaps without
416
- // a transition.
417
- const translateY = drag !== 0 ? drag : animated ? slideIn : 0;
418
-
419
- const panel = (
420
- <SheetPanel
421
- title={title}
422
- footer={footer}
423
- showHandle={showHandle}
424
- isDark={isDark}
425
- testID={testID}
426
- style={style}
427
- height={activeHeight}
428
- >
429
- {children}
430
- </SheetPanel>
431
- );
432
-
433
- return (
434
- <Modal visible={open} transparent animationType="fade" onRequestClose={dismiss}>
435
- <Pressable
436
- accessibilityRole="button"
437
- accessibilityLabel="Close sheet"
438
- onPress={dismissOnBackdropPress ? dismiss : undefined}
439
- style={{ flex: 1, justifyContent: "flex-end", backgroundColor: theme.scrim }}
440
- >
441
- <Pressable
442
- accessibilityRole="none"
443
- onPress={() => {}}
444
- style={{ width: "100%" }}
445
- {...(panResponder ? panResponder.panHandlers : {})}
446
- >
447
- {animated || drag !== 0 ? (
448
- <SheetRise translateY={translateY}>{panel}</SheetRise>
449
- ) : (
450
- panel
451
- )}
452
- </Pressable>
453
- </Pressable>
454
- </Modal>
455
- );
456
- });
457
-
458
- function SheetRise({ translateY, children }: { translateY: any; children: ReactNode }) {
459
- const { Animated } = primitives();
460
- return <Animated.View style={{ transform: [{ translateY }] }}>{children}</Animated.View>;
461
- }
462
-
463
- /** The panel itself: a glass surface with a handle, a title and a footer. */
464
- function SheetPanel({
465
- title,
466
- footer,
467
- showHandle,
468
- isDark,
469
- testID,
470
- style,
471
- height,
472
- children,
473
- }: {
474
- title?: string;
475
- footer?: ReactNode;
476
- showHandle: boolean;
477
- isDark: boolean;
478
- testID?: string;
479
- style?: StyleProp<ViewStyle>;
480
- /** The snap point's height, or null for the panel's natural height. */
481
- height?: number | null;
482
- children?: ReactNode;
483
- }) {
484
- const theme = isDark ? colors.dark : colors.light;
485
- const { View, Text: RNText } = primitives();
486
-
487
- return (
488
- <Glass
489
- effect="regular"
490
- isDark={isDark}
491
- testID={testID}
492
- style={{
493
- borderTopLeftRadius: radii.xl,
494
- borderTopRightRadius: radii.xl,
495
- borderBottomLeftRadius: 0,
496
- borderBottomRightRadius: 0,
497
- paddingBottom: 20,
498
- // A snap point fixes the height; without one the panel is natural.
499
- ...(height != null ? { height } : { maxHeight: 560 }),
500
- ...(style as ViewStyle),
501
- }}
502
- >
503
- {showHandle ? (
504
- <View style={{ alignItems: "center", paddingTop: 8, paddingBottom: 4 }}>
505
- <View
506
- accessibilityElementsHidden
507
- // A capsule: the radius is half the handle's own height.
508
- style={{ width: 36, height: 5, borderRadius: 5 / 2, backgroundColor: theme.separator }}
509
- />
510
- </View>
511
- ) : null}
512
- {title ? (
513
- <View style={{ paddingHorizontal: 20, paddingVertical: 10 }}>
514
- <RNText accessibilityRole="heading" style={{ fontSize: 17, fontWeight: "600", color: theme.foreground }}>
515
- {title}
516
- </RNText>
517
- </View>
518
- ) : null}
519
- <View style={{ paddingHorizontal: 20 }}>{children}</View>
520
- {footer ? <View style={{ paddingHorizontal: 20, paddingTop: 12, gap: 8 }}>{footer}</View> : null}
521
- </Glass>
522
- );
523
- }
524
-
525
- // ---------------------------------------------------------------------------
526
- // Drawer
527
-
528
- export interface DrawerProps {
529
- /** Controlled visibility. Omit and the drawer keeps its own. */
530
- open?: boolean;
531
- defaultOpen?: boolean;
532
- onOpenChange?: (open: boolean) => void;
533
- /** The edge the panel slides in from. */
534
- side?: "left" | "right";
535
- /** Panel width. */
536
- width?: number;
537
- children?: ReactNode;
538
- /** Tapping the scrim dismisses. */
539
- dismissOnBackdropPress?: boolean;
540
- /** Turns the drag-to-close gesture off. */
541
- draggable?: boolean;
542
- /** Opt out of the selection tick when the drawer is thrown closed. */
543
- haptics?: boolean;
544
- style?: StyleProp<ViewStyle>;
545
- isDark?: boolean;
546
- testID?: string;
547
- }
548
-
549
- /**
550
- * A side navigation drawer.
551
- *
552
- * The same overlay discipline as Sheet — scrim, spring slide, Android back —
553
- * but anchored to a side edge, with a square panel that runs the full height.
554
- * The caller supplies the content, typically a List.
555
- *
556
- * Dragging the panel towards its own edge follows the finger; releasing past
557
- * the halfway point, or with enough outward velocity, closes it, and a drag
558
- * that stays inside springs it back open. Reduce Motion is honoured: with it
559
- * on, the drawer appears and disappears without sliding.
560
- */
561
- export const Drawer = forwardRef<any, DrawerProps>(function Drawer(
562
- {
563
- open: openProp,
564
- defaultOpen = false,
565
- onOpenChange,
566
- side = "left",
567
- width = 280,
568
- children,
569
- dismissOnBackdropPress = true,
570
- draggable = true,
571
- haptics = true,
572
- style,
573
- isDark: isDarkProp,
574
- testID,
575
- ...props
576
- },
577
- ref,
578
- ) {
579
- const isDark = useIsDark(isDarkProp);
580
- const theme = isDark ? colors.dark : colors.light;
581
- const { View, Pressable, Modal, PanResponder } = primitives();
582
-
583
- const [internalOpen, setInternalOpen] = useState(defaultOpen);
584
- const open = openProp !== undefined ? openProp : internalOpen;
585
-
586
- const setOpen = useCallback(
587
- (next: boolean) => {
588
- if (openProp === undefined) setInternalOpen(next);
589
- onOpenChange?.(next);
590
- },
591
- [openProp, onOpenChange],
592
- );
593
-
594
- const dismiss = useCallback(() => setOpen(false), [setOpen]);
595
- useBackDismiss(open, dismiss);
596
-
597
- const { value: slide, animated } = useSpring(open ? 1 : 0, "gentle");
598
- // Slide in from off-screen: negative from the left, positive from the right.
599
- const slideIn = animated
600
- ? slide.interpolate({ inputRange: [0, 1], outputRange: [side === "left" ? -width : width, 0] })
601
- : 0;
602
-
603
- // The drag is measured in the drawer's own closing direction, so a drag
604
- // towards the anchored edge is always positive whichever side it is on.
605
- const [drag, setDrag] = useState(0);
606
-
607
- const panResponder = useMemo(() => {
608
- if (!draggable || !PanResponder?.create) return null;
609
- const outward = side === "left" ? -1 : 1;
610
- return PanResponder.create({
611
- onStartShouldSetPanResponder: () => false,
612
- onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
613
- // Only a horizontal drag towards the edge is ours; the other way has
614
- // nowhere to go and should not fight content inside the panel.
615
- Math.abs(gesture.dx) > Math.abs(gesture.dy) && gesture.dx * outward > 6,
616
- onPanResponderMove: (_event: any, gesture: any) => {
617
- setDrag(Math.max(0, gesture.dx * outward));
618
- },
619
- onPanResponderRelease: (_event: any, gesture: any) => {
620
- const travelled = Math.max(0, gesture.dx * outward);
621
- const thrown = gesture.vx * outward > 0.4;
622
- setDrag(0);
623
- if (travelled > width / 2 || thrown) {
624
- if (haptics) hapticSelection();
625
- dismiss();
626
- }
627
- },
628
- onPanResponderTerminate: () => setDrag(0),
629
- onPanResponderTerminationRequest: () => false,
630
- });
631
- // `dismiss` is stable; the gesture only needs rebuilding when its shape
632
- // (side or width) changes.
633
- }, [draggable, PanResponder, side, width, haptics, dismiss]);
634
-
635
- const translateX = drag !== 0 ? (side === "left" ? -drag : drag) : animated ? slideIn : 0;
636
-
637
- const panel = (
638
- <Glass
639
- effect="regular"
640
- isDark={isDark}
641
- testID={testID}
642
- style={{
643
- width,
644
- height: "100%",
645
- borderRadius: 0,
646
- paddingTop: 56,
647
- ...(style as ViewStyle),
648
- }}
649
- >
650
- {children}
651
- </Glass>
652
- );
653
-
654
- return (
655
- <Modal visible={open} transparent animationType="fade" onRequestClose={dismiss}>
656
- <Pressable
657
- accessibilityRole="button"
658
- accessibilityLabel="Close drawer"
659
- onPress={dismissOnBackdropPress ? dismiss : undefined}
660
- style={{ flex: 1, backgroundColor: theme.scrim }}
661
- >
662
- <View
663
- style={{
664
- flex: 1,
665
- alignItems: side === "left" ? "flex-start" : "flex-end",
666
- }}
667
- >
668
- <Pressable
669
- accessibilityRole="none"
670
- onPress={() => {}}
671
- style={{ height: "100%" }}
672
- {...(panResponder ? panResponder.panHandlers : {})}
673
- >
674
- {animated || drag !== 0 ? <DrawerSlide translateX={translateX}>{panel}</DrawerSlide> : panel}
675
- </Pressable>
676
- </View>
677
- </Pressable>
678
- </Modal>
679
- );
680
- });
681
-
682
- function DrawerSlide({ translateX, children }: { translateX: any; children: ReactNode }) {
683
- const { Animated } = primitives();
684
- return <Animated.View style={{ height: "100%", transform: [{ translateX }] }}>{children}</Animated.View>;
685
- }