@tamagui/v2-toast 2.0.0-1769464493958

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 (307) hide show
  1. package/dist/cjs/Toast.cjs +170 -0
  2. package/dist/cjs/Toast.js +119 -0
  3. package/dist/cjs/Toast.js.map +6 -0
  4. package/dist/cjs/Toast.native.js +174 -0
  5. package/dist/cjs/Toast.native.js.map +1 -0
  6. package/dist/cjs/ToastAnnounce.cjs +97 -0
  7. package/dist/cjs/ToastAnnounce.js +72 -0
  8. package/dist/cjs/ToastAnnounce.js.map +6 -0
  9. package/dist/cjs/ToastAnnounce.native.js +105 -0
  10. package/dist/cjs/ToastAnnounce.native.js.map +1 -0
  11. package/dist/cjs/ToastImperative.cjs +100 -0
  12. package/dist/cjs/ToastImperative.js +71 -0
  13. package/dist/cjs/ToastImperative.js.map +6 -0
  14. package/dist/cjs/ToastImperative.native.js +122 -0
  15. package/dist/cjs/ToastImperative.native.js.map +1 -0
  16. package/dist/cjs/ToastImpl.cjs +292 -0
  17. package/dist/cjs/ToastImpl.js +227 -0
  18. package/dist/cjs/ToastImpl.js.map +6 -0
  19. package/dist/cjs/ToastImpl.native.js +327 -0
  20. package/dist/cjs/ToastImpl.native.js.map +1 -0
  21. package/dist/cjs/ToastItem.cjs +466 -0
  22. package/dist/cjs/ToastItem.js +356 -0
  23. package/dist/cjs/ToastItem.js.map +6 -0
  24. package/dist/cjs/ToastItem.native.js +547 -0
  25. package/dist/cjs/ToastItem.native.js.map +1 -0
  26. package/dist/cjs/ToastPortal.cjs +44 -0
  27. package/dist/cjs/ToastPortal.js +26 -0
  28. package/dist/cjs/ToastPortal.js.map +6 -0
  29. package/dist/cjs/ToastPortal.native.js +47 -0
  30. package/dist/cjs/ToastPortal.native.js.map +1 -0
  31. package/dist/cjs/ToastProvider.cjs +146 -0
  32. package/dist/cjs/ToastProvider.js +105 -0
  33. package/dist/cjs/ToastProvider.js.map +6 -0
  34. package/dist/cjs/ToastProvider.native.js +159 -0
  35. package/dist/cjs/ToastProvider.native.js.map +1 -0
  36. package/dist/cjs/ToastState.cjs +248 -0
  37. package/dist/cjs/ToastState.js +160 -0
  38. package/dist/cjs/ToastState.js.map +6 -0
  39. package/dist/cjs/ToastState.native.js +257 -0
  40. package/dist/cjs/ToastState.native.js.map +1 -0
  41. package/dist/cjs/ToastViewport.cjs +278 -0
  42. package/dist/cjs/ToastViewport.js +263 -0
  43. package/dist/cjs/ToastViewport.js.map +6 -0
  44. package/dist/cjs/ToastViewport.native.js +316 -0
  45. package/dist/cjs/ToastViewport.native.js.map +1 -0
  46. package/dist/cjs/Toaster.cjs +219 -0
  47. package/dist/cjs/Toaster.js +177 -0
  48. package/dist/cjs/Toaster.js.map +6 -0
  49. package/dist/cjs/Toaster.native.js +279 -0
  50. package/dist/cjs/Toaster.native.js.map +1 -0
  51. package/dist/cjs/constants.cjs +28 -0
  52. package/dist/cjs/constants.js +22 -0
  53. package/dist/cjs/constants.js.map +6 -0
  54. package/dist/cjs/constants.native.js +31 -0
  55. package/dist/cjs/constants.native.js.map +1 -0
  56. package/dist/cjs/createNativeToast.cjs +51 -0
  57. package/dist/cjs/createNativeToast.js +44 -0
  58. package/dist/cjs/createNativeToast.js.map +6 -0
  59. package/dist/cjs/createNativeToast.native.js +47 -0
  60. package/dist/cjs/createNativeToast.native.js.map +1 -0
  61. package/dist/cjs/index.cjs +28 -0
  62. package/dist/cjs/index.js +22 -0
  63. package/dist/cjs/index.js.map +6 -0
  64. package/dist/cjs/index.native.js +31 -0
  65. package/dist/cjs/index.native.js.map +1 -0
  66. package/dist/cjs/types.cjs +16 -0
  67. package/dist/cjs/types.js +14 -0
  68. package/dist/cjs/types.js.map +6 -0
  69. package/dist/cjs/types.native.js +19 -0
  70. package/dist/cjs/types.native.js.map +1 -0
  71. package/dist/cjs/useDragGesture.cjs +129 -0
  72. package/dist/cjs/useDragGesture.js +100 -0
  73. package/dist/cjs/useDragGesture.js.map +6 -0
  74. package/dist/cjs/useDragGesture.native.js +146 -0
  75. package/dist/cjs/useDragGesture.native.js.map +1 -0
  76. package/dist/esm/Toast.js +107 -0
  77. package/dist/esm/Toast.js.map +6 -0
  78. package/dist/esm/Toast.mjs +131 -0
  79. package/dist/esm/Toast.mjs.map +1 -0
  80. package/dist/esm/Toast.native.js +132 -0
  81. package/dist/esm/Toast.native.js.map +1 -0
  82. package/dist/esm/ToastAnnounce.js +55 -0
  83. package/dist/esm/ToastAnnounce.js.map +6 -0
  84. package/dist/esm/ToastAnnounce.mjs +62 -0
  85. package/dist/esm/ToastAnnounce.mjs.map +1 -0
  86. package/dist/esm/ToastAnnounce.native.js +67 -0
  87. package/dist/esm/ToastAnnounce.native.js.map +1 -0
  88. package/dist/esm/ToastImperative.js +50 -0
  89. package/dist/esm/ToastImperative.js.map +6 -0
  90. package/dist/esm/ToastImperative.mjs +63 -0
  91. package/dist/esm/ToastImperative.mjs.map +1 -0
  92. package/dist/esm/ToastImperative.native.js +82 -0
  93. package/dist/esm/ToastImperative.native.js.map +1 -0
  94. package/dist/esm/ToastImpl.js +225 -0
  95. package/dist/esm/ToastImpl.js.map +6 -0
  96. package/dist/esm/ToastImpl.mjs +256 -0
  97. package/dist/esm/ToastImpl.mjs.map +1 -0
  98. package/dist/esm/ToastImpl.native.js +288 -0
  99. package/dist/esm/ToastImpl.native.js.map +1 -0
  100. package/dist/esm/ToastItem.js +339 -0
  101. package/dist/esm/ToastItem.js.map +6 -0
  102. package/dist/esm/ToastItem.mjs +432 -0
  103. package/dist/esm/ToastItem.mjs.map +1 -0
  104. package/dist/esm/ToastItem.native.js +510 -0
  105. package/dist/esm/ToastItem.native.js.map +1 -0
  106. package/dist/esm/ToastPortal.js +13 -0
  107. package/dist/esm/ToastPortal.js.map +6 -0
  108. package/dist/esm/ToastPortal.mjs +21 -0
  109. package/dist/esm/ToastPortal.mjs.map +1 -0
  110. package/dist/esm/ToastPortal.native.js +21 -0
  111. package/dist/esm/ToastPortal.native.js.map +1 -0
  112. package/dist/esm/ToastProvider.js +87 -0
  113. package/dist/esm/ToastProvider.js.map +6 -0
  114. package/dist/esm/ToastProvider.mjs +108 -0
  115. package/dist/esm/ToastProvider.mjs.map +1 -0
  116. package/dist/esm/ToastProvider.native.js +118 -0
  117. package/dist/esm/ToastProvider.native.js.map +1 -0
  118. package/dist/esm/ToastState.js +144 -0
  119. package/dist/esm/ToastState.js.map +6 -0
  120. package/dist/esm/ToastState.mjs +224 -0
  121. package/dist/esm/ToastState.mjs.map +1 -0
  122. package/dist/esm/ToastState.native.js +230 -0
  123. package/dist/esm/ToastState.native.js.map +1 -0
  124. package/dist/esm/ToastViewport.js +250 -0
  125. package/dist/esm/ToastViewport.js.map +6 -0
  126. package/dist/esm/ToastViewport.mjs +241 -0
  127. package/dist/esm/ToastViewport.mjs.map +1 -0
  128. package/dist/esm/ToastViewport.native.js +276 -0
  129. package/dist/esm/ToastViewport.native.js.map +1 -0
  130. package/dist/esm/Toaster.js +160 -0
  131. package/dist/esm/Toaster.js.map +6 -0
  132. package/dist/esm/Toaster.mjs +185 -0
  133. package/dist/esm/Toaster.mjs.map +1 -0
  134. package/dist/esm/Toaster.native.js +242 -0
  135. package/dist/esm/Toaster.native.js.map +1 -0
  136. package/dist/esm/constants.js +6 -0
  137. package/dist/esm/constants.js.map +6 -0
  138. package/dist/esm/constants.mjs +4 -0
  139. package/dist/esm/constants.mjs.map +1 -0
  140. package/dist/esm/constants.native.js +4 -0
  141. package/dist/esm/constants.native.js.map +1 -0
  142. package/dist/esm/createNativeToast.js +28 -0
  143. package/dist/esm/createNativeToast.js.map +6 -0
  144. package/dist/esm/createNativeToast.mjs +27 -0
  145. package/dist/esm/createNativeToast.mjs.map +1 -0
  146. package/dist/esm/createNativeToast.native.js +20 -0
  147. package/dist/esm/createNativeToast.native.js.map +1 -0
  148. package/dist/esm/index.js +7 -0
  149. package/dist/esm/index.js.map +6 -0
  150. package/dist/esm/index.mjs +4 -0
  151. package/dist/esm/index.mjs.map +1 -0
  152. package/dist/esm/index.native.js +4 -0
  153. package/dist/esm/index.native.js.map +1 -0
  154. package/dist/esm/types.js +1 -0
  155. package/dist/esm/types.js.map +6 -0
  156. package/dist/esm/types.mjs +2 -0
  157. package/dist/esm/types.mjs.map +1 -0
  158. package/dist/esm/types.native.js +2 -0
  159. package/dist/esm/types.native.js.map +1 -0
  160. package/dist/esm/useDragGesture.js +76 -0
  161. package/dist/esm/useDragGesture.js.map +6 -0
  162. package/dist/esm/useDragGesture.mjs +95 -0
  163. package/dist/esm/useDragGesture.mjs.map +1 -0
  164. package/dist/esm/useDragGesture.native.js +109 -0
  165. package/dist/esm/useDragGesture.native.js.map +1 -0
  166. package/dist/jsx/Toast.js +107 -0
  167. package/dist/jsx/Toast.js.map +6 -0
  168. package/dist/jsx/Toast.mjs +131 -0
  169. package/dist/jsx/Toast.mjs.map +1 -0
  170. package/dist/jsx/Toast.native.js +174 -0
  171. package/dist/jsx/Toast.native.js.map +1 -0
  172. package/dist/jsx/ToastAnnounce.js +55 -0
  173. package/dist/jsx/ToastAnnounce.js.map +6 -0
  174. package/dist/jsx/ToastAnnounce.mjs +62 -0
  175. package/dist/jsx/ToastAnnounce.mjs.map +1 -0
  176. package/dist/jsx/ToastAnnounce.native.js +105 -0
  177. package/dist/jsx/ToastAnnounce.native.js.map +1 -0
  178. package/dist/jsx/ToastImperative.js +50 -0
  179. package/dist/jsx/ToastImperative.js.map +6 -0
  180. package/dist/jsx/ToastImperative.mjs +63 -0
  181. package/dist/jsx/ToastImperative.mjs.map +1 -0
  182. package/dist/jsx/ToastImperative.native.js +122 -0
  183. package/dist/jsx/ToastImperative.native.js.map +1 -0
  184. package/dist/jsx/ToastImpl.js +225 -0
  185. package/dist/jsx/ToastImpl.js.map +6 -0
  186. package/dist/jsx/ToastImpl.mjs +256 -0
  187. package/dist/jsx/ToastImpl.mjs.map +1 -0
  188. package/dist/jsx/ToastImpl.native.js +327 -0
  189. package/dist/jsx/ToastImpl.native.js.map +1 -0
  190. package/dist/jsx/ToastItem.js +339 -0
  191. package/dist/jsx/ToastItem.js.map +6 -0
  192. package/dist/jsx/ToastItem.mjs +432 -0
  193. package/dist/jsx/ToastItem.mjs.map +1 -0
  194. package/dist/jsx/ToastItem.native.js +547 -0
  195. package/dist/jsx/ToastItem.native.js.map +1 -0
  196. package/dist/jsx/ToastPortal.js +13 -0
  197. package/dist/jsx/ToastPortal.js.map +6 -0
  198. package/dist/jsx/ToastPortal.mjs +21 -0
  199. package/dist/jsx/ToastPortal.mjs.map +1 -0
  200. package/dist/jsx/ToastPortal.native.js +47 -0
  201. package/dist/jsx/ToastPortal.native.js.map +1 -0
  202. package/dist/jsx/ToastProvider.js +87 -0
  203. package/dist/jsx/ToastProvider.js.map +6 -0
  204. package/dist/jsx/ToastProvider.mjs +108 -0
  205. package/dist/jsx/ToastProvider.mjs.map +1 -0
  206. package/dist/jsx/ToastProvider.native.js +159 -0
  207. package/dist/jsx/ToastProvider.native.js.map +1 -0
  208. package/dist/jsx/ToastState.js +144 -0
  209. package/dist/jsx/ToastState.js.map +6 -0
  210. package/dist/jsx/ToastState.mjs +224 -0
  211. package/dist/jsx/ToastState.mjs.map +1 -0
  212. package/dist/jsx/ToastState.native.js +257 -0
  213. package/dist/jsx/ToastState.native.js.map +1 -0
  214. package/dist/jsx/ToastViewport.js +250 -0
  215. package/dist/jsx/ToastViewport.js.map +6 -0
  216. package/dist/jsx/ToastViewport.mjs +241 -0
  217. package/dist/jsx/ToastViewport.mjs.map +1 -0
  218. package/dist/jsx/ToastViewport.native.js +316 -0
  219. package/dist/jsx/ToastViewport.native.js.map +1 -0
  220. package/dist/jsx/Toaster.js +160 -0
  221. package/dist/jsx/Toaster.js.map +6 -0
  222. package/dist/jsx/Toaster.mjs +185 -0
  223. package/dist/jsx/Toaster.mjs.map +1 -0
  224. package/dist/jsx/Toaster.native.js +279 -0
  225. package/dist/jsx/Toaster.native.js.map +1 -0
  226. package/dist/jsx/constants.js +6 -0
  227. package/dist/jsx/constants.js.map +6 -0
  228. package/dist/jsx/constants.mjs +4 -0
  229. package/dist/jsx/constants.mjs.map +1 -0
  230. package/dist/jsx/constants.native.js +31 -0
  231. package/dist/jsx/constants.native.js.map +1 -0
  232. package/dist/jsx/createNativeToast.js +28 -0
  233. package/dist/jsx/createNativeToast.js.map +6 -0
  234. package/dist/jsx/createNativeToast.mjs +27 -0
  235. package/dist/jsx/createNativeToast.mjs.map +1 -0
  236. package/dist/jsx/createNativeToast.native.js +47 -0
  237. package/dist/jsx/createNativeToast.native.js.map +1 -0
  238. package/dist/jsx/index.js +7 -0
  239. package/dist/jsx/index.js.map +6 -0
  240. package/dist/jsx/index.mjs +4 -0
  241. package/dist/jsx/index.mjs.map +1 -0
  242. package/dist/jsx/index.native.js +31 -0
  243. package/dist/jsx/index.native.js.map +1 -0
  244. package/dist/jsx/types.js +1 -0
  245. package/dist/jsx/types.js.map +6 -0
  246. package/dist/jsx/types.mjs +2 -0
  247. package/dist/jsx/types.mjs.map +1 -0
  248. package/dist/jsx/types.native.js +19 -0
  249. package/dist/jsx/types.native.js.map +1 -0
  250. package/dist/jsx/useDragGesture.js +76 -0
  251. package/dist/jsx/useDragGesture.js.map +6 -0
  252. package/dist/jsx/useDragGesture.mjs +95 -0
  253. package/dist/jsx/useDragGesture.mjs.map +1 -0
  254. package/dist/jsx/useDragGesture.native.js +146 -0
  255. package/dist/jsx/useDragGesture.native.js.map +1 -0
  256. package/package.json +77 -0
  257. package/src/Toast.tsx +219 -0
  258. package/src/ToastAnnounce.tsx +102 -0
  259. package/src/ToastImperative.tsx +190 -0
  260. package/src/ToastImpl.tsx +503 -0
  261. package/src/ToastItem.tsx +694 -0
  262. package/src/ToastPortal.tsx +19 -0
  263. package/src/ToastProvider.tsx +197 -0
  264. package/src/ToastState.ts +397 -0
  265. package/src/ToastViewport.tsx +430 -0
  266. package/src/Toaster.tsx +445 -0
  267. package/src/constants.ts +2 -0
  268. package/src/createNativeToast.native.tsx +22 -0
  269. package/src/createNativeToast.tsx +48 -0
  270. package/src/index.ts +17 -0
  271. package/src/types.ts +71 -0
  272. package/src/useDragGesture.native.ts +199 -0
  273. package/src/useDragGesture.ts +218 -0
  274. package/types/Toast.d.ts +84 -0
  275. package/types/Toast.d.ts.map +1 -0
  276. package/types/ToastAnnounce.d.ts +18 -0
  277. package/types/ToastAnnounce.d.ts.map +1 -0
  278. package/types/ToastImperative.d.ts +95 -0
  279. package/types/ToastImperative.d.ts.map +1 -0
  280. package/types/ToastImpl.d.ts +109 -0
  281. package/types/ToastImpl.d.ts.map +1 -0
  282. package/types/ToastItem.d.ts +34 -0
  283. package/types/ToastItem.d.ts.map +1 -0
  284. package/types/ToastPortal.d.ts +8 -0
  285. package/types/ToastPortal.d.ts.map +1 -0
  286. package/types/ToastProvider.d.ts +92 -0
  287. package/types/ToastProvider.d.ts.map +1 -0
  288. package/types/ToastState.d.ts +177 -0
  289. package/types/ToastState.d.ts.map +1 -0
  290. package/types/ToastViewport.d.ts +75 -0
  291. package/types/ToastViewport.d.ts.map +1 -0
  292. package/types/Toaster.d.ts +120 -0
  293. package/types/Toaster.d.ts.map +1 -0
  294. package/types/constants.d.ts +3 -0
  295. package/types/constants.d.ts.map +1 -0
  296. package/types/createNativeToast.d.ts +4 -0
  297. package/types/createNativeToast.d.ts.map +1 -0
  298. package/types/createNativeToast.native.d.ts +4 -0
  299. package/types/createNativeToast.native.d.ts.map +1 -0
  300. package/types/index.d.ts +7 -0
  301. package/types/index.d.ts.map +1 -0
  302. package/types/types.d.ts +61 -0
  303. package/types/types.d.ts.map +1 -0
  304. package/types/useDragGesture.d.ts +32 -0
  305. package/types/useDragGesture.d.ts.map +1 -0
  306. package/types/useDragGesture.native.d.ts +26 -0
  307. package/types/useDragGesture.native.d.ts.map +1 -0
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Native implementation of drag gesture handling for toast swipe-to-dismiss.
3
+ * Uses react-native-gesture-handler when available, falls back to PanResponder.
4
+ */
5
+
6
+ import * as React from 'react'
7
+ import type { PanResponderGestureState } from 'react-native'
8
+ import { PanResponder } from 'react-native'
9
+ import type { SwipeDirection } from './ToastProvider'
10
+
11
+ export interface DragState {
12
+ isDragging: boolean
13
+ offsetX: number
14
+ offsetY: number
15
+ velocityX: number
16
+ velocityY: number
17
+ }
18
+
19
+ export interface UseDragGestureOptions {
20
+ direction: SwipeDirection
21
+ threshold: number
22
+ onDragStart?: () => void
23
+ onDragEnd?: (dismissed: boolean) => void
24
+ onDragCancel?: () => void
25
+ disabled?: boolean
26
+ }
27
+
28
+ const GESTURE_GRANT_THRESHOLD = 10
29
+ const VELOCITY_THRESHOLD = 0.11
30
+
31
+ function getDampening(delta: number): number {
32
+ const factor = Math.abs(delta) / 20
33
+ return 1 / (1.5 + factor)
34
+ }
35
+
36
+ function shouldGrantGestureMove(dir: SwipeDirection, dx: number, dy: number): boolean {
37
+ if ((dir === 'horizontal' || dir === 'left') && dx < -GESTURE_GRANT_THRESHOLD) {
38
+ return true
39
+ }
40
+ if ((dir === 'horizontal' || dir === 'right') && dx > GESTURE_GRANT_THRESHOLD) {
41
+ return true
42
+ }
43
+ if ((dir === 'vertical' || dir === 'up') && dy < -GESTURE_GRANT_THRESHOLD) {
44
+ return true
45
+ }
46
+ if ((dir === 'vertical' || dir === 'down') && dy > GESTURE_GRANT_THRESHOLD) {
47
+ return true
48
+ }
49
+ return false
50
+ }
51
+
52
+ export function useDragGesture(options: UseDragGestureOptions) {
53
+ const { direction, threshold, onDragStart, onDragEnd, onDragCancel, disabled } = options
54
+
55
+ const [dragState, setDragState] = React.useState<DragState>({
56
+ isDragging: false,
57
+ offsetX: 0,
58
+ offsetY: 0,
59
+ velocityX: 0,
60
+ velocityY: 0,
61
+ })
62
+
63
+ const dragStartTimeRef = React.useRef<number>(0)
64
+
65
+ const isHorizontal =
66
+ direction === 'left' || direction === 'right' || direction === 'horizontal'
67
+ const isVertical =
68
+ direction === 'up' || direction === 'down' || direction === 'vertical'
69
+
70
+ const panResponder = React.useMemo(() => {
71
+ if (disabled) return null
72
+
73
+ return PanResponder.create({
74
+ onMoveShouldSetPanResponder: (_e, gesture) => {
75
+ return shouldGrantGestureMove(direction, gesture.dx, gesture.dy)
76
+ },
77
+
78
+ onPanResponderGrant: () => {
79
+ dragStartTimeRef.current = Date.now()
80
+ setDragState((prev) => ({ ...prev, isDragging: true }))
81
+ onDragStart?.()
82
+ },
83
+
84
+ onPanResponderMove: (_e, gesture) => {
85
+ const { dx, dy } = gesture
86
+
87
+ let offsetX = 0
88
+ let offsetY = 0
89
+
90
+ // apply direction-aware movement with dampening
91
+ if (isHorizontal) {
92
+ if (
93
+ (direction === 'right' && dx > 0) ||
94
+ (direction === 'left' && dx < 0) ||
95
+ direction === 'horizontal'
96
+ ) {
97
+ offsetX = dx
98
+ } else {
99
+ // dampened movement (resistive pull)
100
+ offsetX = dx * getDampening(dx)
101
+ }
102
+ }
103
+
104
+ if (isVertical) {
105
+ if (
106
+ (direction === 'down' && dy > 0) ||
107
+ (direction === 'up' && dy < 0) ||
108
+ direction === 'vertical'
109
+ ) {
110
+ offsetY = dy
111
+ } else {
112
+ // dampened movement (resistive pull)
113
+ offsetY = dy * getDampening(dy)
114
+ }
115
+ }
116
+
117
+ setDragState((prev) => ({
118
+ ...prev,
119
+ offsetX,
120
+ offsetY,
121
+ }))
122
+ },
123
+
124
+ onPanResponderRelease: (_e, gesture) => {
125
+ const { dx, dy, vx, vy } = gesture
126
+
127
+ const relevantDelta = isHorizontal ? dx : dy
128
+ const relevantVelocity = isHorizontal ? Math.abs(vx) : Math.abs(vy)
129
+
130
+ // check if swipe should dismiss
131
+ const passedThreshold = Math.abs(relevantDelta) >= threshold
132
+ const hasVelocity = relevantVelocity > VELOCITY_THRESHOLD
133
+
134
+ // check if swipe is in the correct direction
135
+ let isCorrectDirection = false
136
+ if (direction === 'right' && dx > 0) isCorrectDirection = true
137
+ else if (direction === 'left' && dx < 0) isCorrectDirection = true
138
+ else if (direction === 'horizontal' && Math.abs(dx) > Math.abs(dy))
139
+ isCorrectDirection = true
140
+ else if (direction === 'down' && dy > 0) isCorrectDirection = true
141
+ else if (direction === 'up' && dy < 0) isCorrectDirection = true
142
+ else if (direction === 'vertical' && Math.abs(dy) > Math.abs(dx))
143
+ isCorrectDirection = true
144
+
145
+ const shouldDismiss = isCorrectDirection && (passedThreshold || hasVelocity)
146
+
147
+ if (shouldDismiss) {
148
+ onDragEnd?.(true)
149
+ } else {
150
+ // snap back
151
+ setDragState({
152
+ isDragging: false,
153
+ offsetX: 0,
154
+ offsetY: 0,
155
+ velocityX: 0,
156
+ velocityY: 0,
157
+ })
158
+ onDragCancel?.()
159
+ }
160
+ },
161
+
162
+ onPanResponderTerminate: () => {
163
+ setDragState({
164
+ isDragging: false,
165
+ offsetX: 0,
166
+ offsetY: 0,
167
+ velocityX: 0,
168
+ velocityY: 0,
169
+ })
170
+ onDragCancel?.()
171
+ },
172
+ })
173
+ }, [
174
+ disabled,
175
+ direction,
176
+ threshold,
177
+ isHorizontal,
178
+ isVertical,
179
+ onDragStart,
180
+ onDragEnd,
181
+ onDragCancel,
182
+ ])
183
+
184
+ const resetDrag = React.useCallback(() => {
185
+ setDragState({
186
+ isDragging: false,
187
+ offsetX: 0,
188
+ offsetY: 0,
189
+ velocityX: 0,
190
+ velocityY: 0,
191
+ })
192
+ }, [])
193
+
194
+ return {
195
+ dragState,
196
+ gestureHandlers: panResponder?.panHandlers ?? {},
197
+ resetDrag,
198
+ }
199
+ }
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Web implementation of drag gesture handling for toast swipe-to-dismiss.
3
+ * Uses pointer events for smooth drag tracking.
4
+ */
5
+
6
+ import * as React from 'react'
7
+ import type { SwipeDirection } from './ToastProvider'
8
+
9
+ export interface DragState {
10
+ isDragging: boolean
11
+ offsetX: number
12
+ offsetY: number
13
+ velocityX: number
14
+ velocityY: number
15
+ }
16
+
17
+ export interface UseDragGestureOptions {
18
+ direction: SwipeDirection
19
+ threshold: number
20
+ onDragStart?: () => void
21
+ onDragEnd?: (dismissed: boolean) => void
22
+ onDragCancel?: () => void
23
+ disabled?: boolean
24
+ }
25
+
26
+ interface DragStartData {
27
+ startX: number
28
+ startY: number
29
+ startTime: number
30
+ }
31
+
32
+ const VELOCITY_THRESHOLD = 0.11
33
+
34
+ /**
35
+ * Apply resistance when dragging past a boundary.
36
+ * Uses a square root curve for natural-feeling resistance (same as Sheet).
37
+ * @param delta - the drag distance
38
+ * @param maxResist - maximum resistant distance (default 25px)
39
+ */
40
+ function resisted(delta: number, maxResist = 25): number {
41
+ // no resistance for drag in allowed direction
42
+ if (delta >= 0) return delta
43
+
44
+ // square root curve for gentle resistance
45
+ const pastBoundary = Math.abs(delta)
46
+ const resistedDistance = Math.sqrt(pastBoundary) * 2
47
+
48
+ // cap at max resist distance
49
+ return -Math.min(resistedDistance, maxResist)
50
+ }
51
+
52
+ export function useDragGesture(options: UseDragGestureOptions) {
53
+ const { direction, threshold, onDragStart, onDragEnd, onDragCancel, disabled } = options
54
+
55
+ const [dragState, setDragState] = React.useState<DragState>({
56
+ isDragging: false,
57
+ offsetX: 0,
58
+ offsetY: 0,
59
+ velocityX: 0,
60
+ velocityY: 0,
61
+ })
62
+
63
+ const dragStartRef = React.useRef<DragStartData | null>(null)
64
+ const lockedDirectionRef = React.useRef<'x' | 'y' | null>(null)
65
+
66
+ const isHorizontal =
67
+ direction === 'left' || direction === 'right' || direction === 'horizontal'
68
+ const isVertical =
69
+ direction === 'up' || direction === 'down' || direction === 'vertical'
70
+
71
+ const handlePointerDown = React.useCallback(
72
+ (event: React.PointerEvent) => {
73
+ if (disabled) return
74
+ if (event.button !== 0)
75
+ return // only left click
76
+ // capture pointer for drag outside element
77
+ ;(event.target as HTMLElement).setPointerCapture(event.pointerId)
78
+
79
+ dragStartRef.current = {
80
+ startX: event.clientX,
81
+ startY: event.clientY,
82
+ startTime: Date.now(),
83
+ }
84
+
85
+ setDragState((prev) => ({ ...prev, isDragging: true }))
86
+ onDragStart?.()
87
+ },
88
+ [disabled, onDragStart]
89
+ )
90
+
91
+ const handlePointerMove = React.useCallback(
92
+ (event: React.PointerEvent) => {
93
+ if (!dragStartRef.current || disabled) return
94
+
95
+ const deltaX = event.clientX - dragStartRef.current.startX
96
+ const deltaY = event.clientY - dragStartRef.current.startY
97
+
98
+ // detect direction lock on first significant movement
99
+ if (!lockedDirectionRef.current && (Math.abs(deltaX) > 1 || Math.abs(deltaY) > 1)) {
100
+ lockedDirectionRef.current = Math.abs(deltaX) > Math.abs(deltaY) ? 'x' : 'y'
101
+ }
102
+
103
+ let offsetX = 0
104
+ let offsetY = 0
105
+
106
+ // apply direction-aware movement with resistance for wrong direction
107
+ if (lockedDirectionRef.current === 'x' && isHorizontal) {
108
+ if (direction === 'right') {
109
+ // swipe right: free movement right (positive), resisted left (negative)
110
+ offsetX = deltaX > 0 ? deltaX : resisted(deltaX)
111
+ } else if (direction === 'left') {
112
+ // swipe left: free movement left (negative), resisted right (positive)
113
+ offsetX = deltaX < 0 ? deltaX : -resisted(-deltaX)
114
+ } else {
115
+ // horizontal: free movement both directions
116
+ offsetX = deltaX
117
+ }
118
+ } else if (lockedDirectionRef.current === 'y' && isVertical) {
119
+ if (direction === 'down') {
120
+ // swipe down: free movement down (positive), resisted up (negative)
121
+ offsetY = deltaY > 0 ? deltaY : resisted(deltaY)
122
+ } else if (direction === 'up') {
123
+ // swipe up: free movement up (negative), resisted down (positive)
124
+ offsetY = deltaY < 0 ? deltaY : -resisted(-deltaY)
125
+ } else {
126
+ // vertical: free movement both directions
127
+ offsetY = deltaY
128
+ }
129
+ }
130
+
131
+ setDragState((prev) => ({
132
+ ...prev,
133
+ offsetX,
134
+ offsetY,
135
+ }))
136
+ },
137
+ [disabled, direction, isHorizontal, isVertical]
138
+ )
139
+
140
+ const handlePointerUp = React.useCallback(
141
+ (event: React.PointerEvent) => {
142
+ if (!dragStartRef.current || disabled) return
143
+
144
+ const deltaX = event.clientX - dragStartRef.current.startX
145
+ const deltaY = event.clientY - dragStartRef.current.startY
146
+ const timeTaken = Date.now() - dragStartRef.current.startTime
147
+
148
+ // calculate velocity
149
+ const velocityX = Math.abs(deltaX) / timeTaken
150
+ const velocityY = Math.abs(deltaY) / timeTaken
151
+
152
+ const relevantDelta = isHorizontal ? deltaX : deltaY
153
+ const relevantVelocity = isHorizontal ? velocityX : velocityY
154
+
155
+ // check if swipe should dismiss
156
+ const passedThreshold = Math.abs(relevantDelta) >= threshold
157
+ const hasVelocity = relevantVelocity > VELOCITY_THRESHOLD
158
+
159
+ // check if swipe is in the correct direction
160
+ let isCorrectDirection = false
161
+ if (direction === 'right' && deltaX > 0) isCorrectDirection = true
162
+ else if (direction === 'left' && deltaX < 0) isCorrectDirection = true
163
+ else if (direction === 'horizontal' && Math.abs(deltaX) > Math.abs(deltaY))
164
+ isCorrectDirection = true
165
+ else if (direction === 'down' && deltaY > 0) isCorrectDirection = true
166
+ else if (direction === 'up' && deltaY < 0) isCorrectDirection = true
167
+ else if (direction === 'vertical' && Math.abs(deltaY) > Math.abs(deltaX))
168
+ isCorrectDirection = true
169
+
170
+ const shouldDismiss = isCorrectDirection && (passedThreshold || hasVelocity)
171
+
172
+ // reset state
173
+ dragStartRef.current = null
174
+ lockedDirectionRef.current = null
175
+
176
+ if (shouldDismiss) {
177
+ onDragEnd?.(true)
178
+ } else {
179
+ // snap back
180
+ setDragState({
181
+ isDragging: false,
182
+ offsetX: 0,
183
+ offsetY: 0,
184
+ velocityX: 0,
185
+ velocityY: 0,
186
+ })
187
+ onDragCancel?.()
188
+ }
189
+ },
190
+ [disabled, direction, threshold, isHorizontal, onDragEnd, onDragCancel]
191
+ )
192
+
193
+ const handlePointerCancel = React.useCallback(() => {
194
+ dragStartRef.current = null
195
+ lockedDirectionRef.current = null
196
+ setDragState({
197
+ isDragging: false,
198
+ offsetX: 0,
199
+ offsetY: 0,
200
+ velocityX: 0,
201
+ velocityY: 0,
202
+ })
203
+ onDragCancel?.()
204
+ }, [onDragCancel])
205
+
206
+ const gestureHandlers = {
207
+ onPointerDown: handlePointerDown,
208
+ onPointerMove: handlePointerMove,
209
+ onPointerUp: handlePointerUp,
210
+ onPointerCancel: handlePointerCancel,
211
+ }
212
+
213
+ return {
214
+ dragState,
215
+ gestureHandlers,
216
+ resetDrag: handlePointerCancel,
217
+ }
218
+ }
@@ -0,0 +1,84 @@
1
+ import type { GetProps, NativePlatform, NativeValue, TamaguiElement } from '@tamagui/core';
2
+ import * as React from 'react';
3
+ import type { CustomData } from './ToastImperative';
4
+ import { useToast, useToastController, useToastState } from './ToastImperative';
5
+ import type { ToastExtraProps, ToastProps } from './ToastImpl';
6
+ import type { ScopedProps, ToastProviderProps } from './ToastProvider';
7
+ import { ToastProvider } from './ToastProvider';
8
+ import type { ToastViewportProps } from './ToastViewport';
9
+ import { ToastViewport } from './ToastViewport';
10
+ declare const ToastTitle: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiTextElement, import("@tamagui/core").TextNonStyleProps, import("@tamagui/core").TextStylePropsBase, {
11
+ size?: import("@tamagui/core").FontSizeTokens | undefined;
12
+ unstyled?: boolean | undefined;
13
+ }, import("@tamagui/core").StaticConfigPublic>;
14
+ type ToastTitleProps = GetProps<typeof ToastTitle>;
15
+ declare const ToastDescription: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiTextElement, import("@tamagui/core").TextNonStyleProps, import("@tamagui/core").TextStylePropsBase, {
16
+ size?: import("@tamagui/core").FontSizeTokens | undefined;
17
+ unstyled?: boolean | undefined;
18
+ }, import("@tamagui/core").StaticConfigPublic>;
19
+ type ToastDescriptionProps = GetProps<typeof ToastDescription>;
20
+ type ToastActionProps = ScopedProps<ToastCloseProps & {
21
+ /**
22
+ * A short description for an alternate way to carry out the action. For screen reader users
23
+ * who will not be able to navigate to the button easily/quickly.
24
+ * @example <ToastAction altText="Goto account settings to updgrade">Upgrade</ToastAction>
25
+ * @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
26
+ */
27
+ altText: string;
28
+ }>;
29
+ declare const ToastCloseFrame: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
30
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
31
+ fullscreen?: boolean | undefined;
32
+ }, import("@tamagui/core").StaticConfigPublic>;
33
+ type ToastCloseFrameProps = GetProps<typeof ToastCloseFrame>;
34
+ type ToastCloseProps = ScopedProps<ToastCloseFrameProps & {}>;
35
+ declare const Toast: React.ForwardRefExoticComponent<Omit<import("@tamagui/core").GetFinalProps<import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
36
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
37
+ fullscreen?: boolean | undefined;
38
+ unstyled?: boolean | undefined;
39
+ }>, keyof ToastExtraProps> & ToastExtraProps & React.RefAttributes<TamaguiElement>> & import("@tamagui/core").StaticComponentObject<Omit<import("@tamagui/core").GetFinalProps<import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
40
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
41
+ fullscreen?: boolean | undefined;
42
+ unstyled?: boolean | undefined;
43
+ }>, keyof ToastExtraProps> & ToastExtraProps, TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps & ToastExtraProps, import("@tamagui/core").StackStyleBase, {
44
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
45
+ fullscreen?: boolean | undefined;
46
+ unstyled?: boolean | undefined;
47
+ }, import("@tamagui/core").StaticConfigPublic> & Omit<import("@tamagui/core").StaticConfigPublic, "staticConfig" | "styleable"> & {
48
+ __tama: [Omit<import("@tamagui/core").GetFinalProps<import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
49
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
50
+ fullscreen?: boolean | undefined;
51
+ unstyled?: boolean | undefined;
52
+ }>, keyof ToastExtraProps> & ToastExtraProps, TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps & ToastExtraProps, import("@tamagui/core").StackStyleBase, {
53
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
54
+ fullscreen?: boolean | undefined;
55
+ unstyled?: boolean | undefined;
56
+ }, import("@tamagui/core").StaticConfigPublic];
57
+ } & {
58
+ Title: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiTextElement, import("@tamagui/core").TextNonStyleProps, import("@tamagui/core").TextStylePropsBase, {
59
+ size?: import("@tamagui/core").FontSizeTokens | undefined;
60
+ unstyled?: boolean | undefined;
61
+ }, import("@tamagui/core").StaticConfigPublic>;
62
+ Description: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiTextElement, import("@tamagui/core").TextNonStyleProps, import("@tamagui/core").TextStylePropsBase, {
63
+ size?: import("@tamagui/core").FontSizeTokens | undefined;
64
+ unstyled?: boolean | undefined;
65
+ }, import("@tamagui/core").StaticConfigPublic>;
66
+ Action: React.ForwardRefExoticComponent<Omit<ToastActionProps, "scope"> & {
67
+ scope?: import("./ToastProvider").ToastScopes;
68
+ } & React.RefAttributes<TamaguiElement>>;
69
+ Close: React.ForwardRefExoticComponent<Omit<Omit<import("@tamagui/core").RNTamaguiViewNonStyleProps, "elevation" | keyof import("@tamagui/core").StackStyleBase | "fullscreen"> & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase> & {
70
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
71
+ fullscreen?: boolean | undefined;
72
+ } & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase>> & import("@tamagui/core").WithPseudoProps<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase> & {
73
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
74
+ fullscreen?: boolean | undefined;
75
+ } & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase>>> & import("@tamagui/core").WithMediaProps<import("@tamagui/core").WithThemeShorthandsAndPseudos<import("@tamagui/core").StackStyleBase, {
76
+ elevation?: number | import("@tamagui/core").SizeTokens | undefined;
77
+ fullscreen?: boolean | undefined;
78
+ }>>, "scope"> & {
79
+ scope?: import("./ToastProvider").ToastScopes;
80
+ } & React.RefAttributes<TamaguiElement>>;
81
+ };
82
+ export { Toast, ToastProvider, ToastViewport, useToast, useToastController, useToastState, };
83
+ export type { CustomData, ToastActionProps, ToastCloseProps, ToastDescriptionProps, NativePlatform as ToastNativePlatform, NativeValue as ToastNativeValue, ToastProps, ToastProviderProps, ToastTitleProps, ToastViewportProps, };
84
+ //# sourceMappingURL=Toast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAM1F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAQ/C,QAAA,MAAM,UAAU;;;8CAed,CAAA;AAEF,KAAK,eAAe,GAAG,QAAQ,CAAC,OAAO,UAAU,CAAC,CAAA;AAQlD,QAAA,MAAM,gBAAgB;;;8CAepB,CAAA;AAEF,KAAK,qBAAqB,GAAG,QAAQ,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAQ9D,KAAK,gBAAgB,GAAG,WAAW,CACjC,eAAe,GAAG;IAChB;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB,CACF,CAAA;AA6BD,QAAA,MAAM,eAAe;;;8CAGnB,CAAA;AAEF,KAAK,oBAAoB,GAAG,QAAQ,CAAC,OAAO,eAAe,CAAC,CAAA;AAC5D,KAAK,eAAe,GAAG,WAAW,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAA;AAmE7D,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAKT,CAAA;AAIF,OAAO,EACL,KAAK,EACL,aAAa,EACb,aAAa,EAGb,QAAQ,EACR,kBAAkB,EAClB,aAAa,GACd,CAAA;AACD,YAAY,EAEV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,cAAc,IAAI,mBAAmB,EAErC,WAAW,IAAI,gBAAgB,EAC/B,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACnB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { GetProps, TamaguiElement } from '@tamagui/core';
2
+ import { VisuallyHidden } from '@tamagui/visually-hidden';
3
+ import * as React from 'react';
4
+ import type { ScopedProps } from './ToastProvider';
5
+ declare const ToastAnnounceExcludeFrame: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {}, import("@tamagui/core").StaticConfigPublic>;
6
+ type ToastAnnounceExcludeFrameProps = GetProps<typeof ToastAnnounceExcludeFrame>;
7
+ type ToastAnnounceExcludeExtraProps = {
8
+ altText?: string;
9
+ };
10
+ type ToastAnnounceExcludeProps = ToastAnnounceExcludeFrameProps & ToastAnnounceExcludeExtraProps;
11
+ declare const ToastAnnounceExclude: React.ForwardRefExoticComponent<Omit<import("@tamagui/core").RNTamaguiViewNonStyleProps, keyof import("@tamagui/core").StackStyleBase> & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase>> & import("@tamagui/core").WithPseudoProps<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase>>> & import("@tamagui/core").WithMediaProps<import("@tamagui/core").WithThemeShorthandsAndPseudos<import("@tamagui/core").StackStyleBase, {}>> & ToastAnnounceExcludeExtraProps & React.RefAttributes<TamaguiElement>>;
12
+ interface ToastAnnounceProps extends Omit<GetProps<typeof VisuallyHidden>, 'children'>, ScopedProps<{
13
+ children: string[];
14
+ }> {
15
+ }
16
+ declare const ToastAnnounce: React.FC<ToastAnnounceProps>;
17
+ export { ToastAnnounce, ToastAnnounceExclude, type ToastAnnounceExcludeProps, type ToastAnnounceProps, };
18
+ //# sourceMappingURL=ToastAnnounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastAnnounce.d.ts","sourceRoot":"","sources":["../src/ToastAnnounce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAI7D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGlD,QAAA,MAAM,yBAAyB,yOAE7B,CAAA;AAEF,KAAK,8BAA8B,GAAG,QAAQ,CAAC,OAAO,yBAAyB,CAAC,CAAA;AAEhF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG,8BAA8B,GAC7D,8BAA8B,CAAA;AAEhC,QAAA,MAAM,oBAAoB,6xBAazB,CAAA;AAID,UAAU,kBACR,SAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,cAAc,CAAC,EAAE,UAAU,CAAC,EACvD,WAAW,CAAC;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;CAAG;AAE1C,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAgC/C,CAAA;AAmBD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACxB,CAAA"}
@@ -0,0 +1,95 @@
1
+ import type { NativePlatform, NativeValue } from '@tamagui/core';
2
+ import React from 'react';
3
+ import type { CreateNativeToastOptions, NativeToastRef } from './types';
4
+ export interface ToastImperativeOptions extends Omit<CreateNativeToastOptions, 'message'> {
5
+ /**
6
+ * Will show a native toast if is true or is set to the current platform. On iOS, it wraps `SPIndicator` and `SPAlert`. On Android, it wraps `ToastAndroid`. On web, it wraps Notification API. Mobile's native features are handled by `burnt`.
7
+ */
8
+ native?: NativeValue;
9
+ }
10
+ /**
11
+ * Override this in your application to get custom toast fields.
12
+ *
13
+ * e.g.
14
+ * ```ts
15
+ * declare module '@tamagui/toast' {
16
+ * interface CustomData {
17
+ * preset: 'error' | 'success'
18
+ * isUrgent: true
19
+ * }
20
+ * }
21
+ *```
22
+ * You will get auto-completion:
23
+ * ```ts
24
+ * toast.show("Message", { preset: 'error', isUrgent: true })
25
+ * ```
26
+ */
27
+ export interface CustomData {
28
+ [key: string]: any;
29
+ }
30
+ type ShowOptions = CreateNativeToastOptions & CustomData & {
31
+ /**
32
+ * Used when need custom data
33
+ */
34
+ customData?: CustomData;
35
+ /**
36
+ * Overrides the native option on `ToastImperativeProvider`
37
+ */
38
+ native?: NativeValue;
39
+ /**
40
+ * Which viewport to send this toast to. This is only intended to be used with custom toasts and you should wire it up when creating the toast.
41
+ */
42
+ viewportName?: string | 'default';
43
+ };
44
+ type ToastData = {
45
+ title: string;
46
+ id: string;
47
+ } & ShowOptions & {
48
+ isHandledNatively: boolean;
49
+ } & CustomData;
50
+ interface ToastContextI {
51
+ nativeToast: NativeToastRef | null;
52
+ /**
53
+ * Call it to show a new toast. If you're using native toasts, you can pass native options using \`burntOptions\` or \`notificationOptions\` depending on the native platform (mobile/web).
54
+ */
55
+ show: (title: string, options?: ShowOptions) => boolean;
56
+ /**
57
+ * Call it to hide the currently displayed toast.
58
+ *
59
+ * _NOTE_: does not work on Android native toasts
60
+ *
61
+ * _NOTE_: hides the last toast on web notification toasts
62
+ */
63
+ hide: () => void;
64
+ options?: ToastImperativeOptions;
65
+ }
66
+ export declare const useToastController: () => ToastContextI;
67
+ export declare const useToastState: () => ToastData | null;
68
+ /** @deprecated use `useToastController` and `useToastState` instead to avoid performance pitfalls */
69
+ export declare const useToast: () => {
70
+ currentToast: ToastData | null;
71
+ nativeToast: NativeToastRef | null;
72
+ /**
73
+ * Call it to show a new toast. If you're using native toasts, you can pass native options using \`burntOptions\` or \`notificationOptions\` depending on the native platform (mobile/web).
74
+ */
75
+ show: (title: string, options?: ShowOptions) => boolean;
76
+ /**
77
+ * Call it to hide the currently displayed toast.
78
+ *
79
+ * _NOTE_: does not work on Android native toasts
80
+ *
81
+ * _NOTE_: hides the last toast on web notification toasts
82
+ */
83
+ hide: () => void;
84
+ options?: ToastImperativeOptions;
85
+ };
86
+ interface ToastImperativeProviderProps {
87
+ children: React.ReactNode;
88
+ /**
89
+ * Used to provide defaults to imperative API. Options can be overwritten when calling `show()`.
90
+ */
91
+ options: ToastImperativeOptions;
92
+ }
93
+ export declare const ToastImperativeProvider: ({ children, options, }: ToastImperativeProviderProps) => import("react/jsx-runtime").JSX.Element;
94
+ export type { NativePlatform, NativeValue, ToastImperativeProviderProps };
95
+ //# sourceMappingURL=ToastImperative.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastImperative.d.ts","sourceRoot":"","sources":["../src/ToastImperative.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEvE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,wBAAwB,EAAE,SAAS,CAAC;IACjD;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,KAAK,WAAW,GAAG,wBAAwB,GACzC,UAAU,GAAG;IACX;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClC,CAAA;AAEH,KAAK,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,GAAG;IAC3D,iBAAiB,EAAE,OAAO,CAAA;CAC3B,GAAG,UAAU,CAAA;AAEhB,UAAU,aAAa;IACrB,WAAW,EAAE,cAAc,GAAG,IAAI,CAAA;IAElC;;OAEG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAA;IAEvD;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,IAAI,CAAA;IAEhB,OAAO,CAAC,EAAE,sBAAsB,CAAA;CACjC;AAKD,eAAO,MAAM,kBAAkB,qBAE9B,CAAA;AAED,eAAO,MAAM,aAAa,wBAEzB,CAAA;AAED,qGAAqG;AACrG,eAAO,MAAM,QAAQ;;iBA/BN,cAAc,GAAG,IAAI;IAElC;;OAEG;UACG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO;IAEvD;;;;;;OAMG;UACG,MAAM,IAAI;cAEN,sBAAsB;CAoBjC,CAAA;AAED,UAAU,4BAA4B;IACpC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB;;OAEG;IACH,OAAO,EAAE,sBAAsB,CAAA;CAChC;AAED,eAAO,MAAM,uBAAuB,GAAI,wBAGrC,4BAA4B,4CAkF9B,CAAA;AAED,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAAA"}