@tamagui/toast 3.0.0-beta.922.1 → 3.0.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.
- package/dist/cjs/ToastComposable.cjs +61 -68
- package/dist/cjs/ToastComposable.native.cjs +80 -94
- package/dist/cjs/ToastComposable.native.js +80 -94
- package/dist/cjs/ToastComposable.native.js.map +1 -1
- package/dist/cjs/ToastItemFrame.cjs +4 -3
- package/dist/cjs/ToastItemFrame.native.cjs +4 -3
- package/dist/cjs/ToastItemFrame.native.js +4 -3
- package/dist/cjs/ToastItemFrame.native.js.map +1 -1
- package/dist/cjs/ToastState.cjs +1 -0
- package/dist/cjs/ToastState.native.cjs +3 -13
- package/dist/cjs/ToastState.native.js +3 -13
- package/dist/cjs/ToastState.native.js.map +1 -1
- package/dist/esm/ToastComposable.mjs +62 -69
- package/dist/esm/ToastComposable.mjs.map +1 -1
- package/dist/esm/ToastComposable.native.js +81 -95
- package/dist/esm/ToastComposable.native.js.map +1 -1
- package/dist/esm/ToastItemFrame.mjs +4 -3
- package/dist/esm/ToastItemFrame.mjs.map +1 -1
- package/dist/esm/ToastItemFrame.native.js +4 -3
- package/dist/esm/ToastItemFrame.native.js.map +1 -1
- package/dist/esm/ToastState.mjs +1 -0
- package/dist/esm/ToastState.mjs.map +1 -1
- package/dist/esm/ToastState.native.js +3 -13
- package/dist/esm/ToastState.native.js.map +1 -1
- package/dist/jsx/ToastComposable.mjs +62 -69
- package/dist/jsx/ToastComposable.mjs.map +1 -1
- package/dist/jsx/ToastComposable.native.cjs +80 -94
- package/dist/jsx/ToastComposable.native.js +80 -94
- package/dist/jsx/ToastComposable.native.js.map +1 -1
- package/dist/jsx/ToastItemFrame.mjs +4 -3
- package/dist/jsx/ToastItemFrame.mjs.map +1 -1
- package/dist/jsx/ToastItemFrame.native.cjs +4 -3
- package/dist/jsx/ToastItemFrame.native.js +4 -3
- package/dist/jsx/ToastItemFrame.native.js.map +1 -1
- package/dist/jsx/ToastState.mjs +1 -0
- package/dist/jsx/ToastState.mjs.map +1 -1
- package/dist/jsx/ToastState.native.cjs +3 -13
- package/dist/jsx/ToastState.native.js +3 -13
- package/dist/jsx/ToastState.native.js.map +1 -1
- package/package.json +22 -20
- package/src/ToastComposable.tsx +107 -113
- package/src/ToastItemFrame.tsx +7 -3
- package/src/ToastState.ts +4 -1
- package/src/useToastAnimations.ts +3 -4
- package/types/ToastComposable.d.ts +32 -72
- package/types/ToastComposable.d.ts.map +1 -1
- package/types/ToastItemFrame.d.ts +12 -36
- package/types/ToastItemFrame.d.ts.map +1 -1
- package/types/ToastState.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.native.d.ts +1 -1
- package/types/useToastAnimations.d.ts +2 -3
- package/types/useToastAnimations.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToastState.native.js","names":[],"sources":["jsx/ToastState.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar ToastState_exports = {};\n__export(ToastState_exports, {\n ToastState: () => ToastState,\n toast: () => toast\n});\nmodule.exports = __toCommonJS(ToastState_exports);\nfunction _class_call_check(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\nfunction _define_property(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\nfunction _instanceof(left, right) {\n if (right != null && typeof Symbol !== \"undefined\" && right[Symbol.hasInstance]) {\n return !!right[Symbol.hasInstance](left);\n } else {\n return left instanceof right;\n }\n}\nfunction _type_of(obj) {\n \"@swc/helpers - typeof\";\n return obj && typeof Symbol !== \"undefined\" && obj.constructor === Symbol ? \"symbol\" : typeof obj;\n}\nvar toastsCounter = 1;\nvar Observer = function Observer2() {\n \"use strict\";\n var _this = this;\n _class_call_check(this, Observer2);\n _define_property(this, \"subscribers\", []);\n _define_property(this, \"toasts\", []);\n _define_property(this, \"dismissedToasts\", /* @__PURE__ */ new Set());\n _define_property(this, \"subscribe\", function(subscriber) {\n _this.subscribers.push(subscriber);\n return function() {\n var index = _this.subscribers.indexOf(subscriber);\n if (index > -1) {\n _this.subscribers.splice(index, 1);\n }\n };\n });\n _define_property(this, \"publish\", function(data) {\n _this.subscribers.forEach(function(subscriber) {\n return subscriber(data);\n });\n });\n _define_property(this, \"addToast\", function(data) {\n _this.publish(data);\n _this.toasts = [\n ..._this.toasts,\n data\n ];\n });\n _define_property(this, \"create\", function(data) {\n var { title, ...rest } = data;\n var id = typeof (data === null || data === void 0 ? void 0 : data.id) === \"number\" || typeof (data === null || data === void 0 ? void 0 : data.id) === \"string\" && data.id.length > 0 ? data.id : toastsCounter++;\n var alreadyExists = _this.toasts.find(function(toast2) {\n return toast2.id === id;\n });\n var _data_dismissible;\n var dismissible = (_data_dismissible = data.dismissible) !== null && _data_dismissible !== void 0 ? _data_dismissible : true;\n if (_this.dismissedToasts.has(id)) {\n _this.dismissedToasts.delete(id);\n }\n if (alreadyExists) {\n _this.toasts = _this.toasts.map(function(toast2) {\n if (toast2.id === id) {\n _this.publish({\n ...toast2,\n ...data,\n id,\n title,\n dismissible\n });\n return {\n ...toast2,\n ...data,\n id,\n title,\n dismissible\n };\n }\n return toast2;\n });\n } else {\n _this.addToast({\n title,\n ...rest,\n dismissible,\n id\n });\n }\n return id;\n });\n _define_property(this, \"dismiss\", function(id) {\n if (id !== void 0) {\n _this.dismissedToasts.add(id);\n requestAnimationFrame(function() {\n _this.subscribers.forEach(function(subscriber) {\n return subscriber({\n id,\n dismiss: true\n });\n });\n });\n } else {\n _this.toasts.forEach(function(toast2) {\n _this.subscribers.forEach(function(subscriber) {\n return subscriber({\n id: toast2.id,\n dismiss: true\n });\n });\n });\n }\n return id;\n });\n _define_property(this, \"message\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"default\"\n });\n });\n _define_property(this, \"success\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"success\"\n });\n });\n _define_property(this, \"error\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"error\"\n });\n });\n _define_property(this, \"warning\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"warning\"\n });\n });\n _define_property(this, \"info\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"info\"\n });\n });\n _define_property(this, \"loading\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"loading\"\n });\n });\n _define_property(this, \"promise\", function(promise, data) {\n if (!data) {\n return;\n }\n var id = void 0;\n if (data.loading !== void 0) {\n id = _this.create({\n promise,\n type: \"loading\",\n title: data.loading,\n description: typeof data.description !== \"function\" ? data.description : void 0,\n // loading toasts shouldn't auto-dismiss\n duration: Number.POSITIVE_INFINITY\n });\n }\n var p = Promise.resolve(_instanceof(promise, Function) ? promise() : promise);\n var shouldDismiss = id !== void 0;\n var result;\n var originalPromise = p.then(async function(response) {\n result = [\n \"resolve\",\n response\n ];\n if (isHttpResponse(response) && !response.ok) {\n shouldDismiss = false;\n var errorMsg = typeof data.error === \"function\" ? await data.error(`HTTP error! status: ${response.status}`) : data.error;\n var description = typeof data.description === \"function\" ? await data.description(`HTTP error! status: ${response.status}`) : data.description;\n _this.create({\n id,\n type: \"error\",\n title: errorMsg,\n description\n });\n } else if (data.success !== void 0) {\n shouldDismiss = false;\n var successMsg = typeof data.success === \"function\" ? await data.success(response) : data.success;\n var description1 = typeof data.description === \"function\" ? await data.description(response) : data.description;\n _this.create({\n id,\n type: \"success\",\n title: successMsg,\n description: description1\n });\n }\n }).catch(async function(error) {\n result = [\n \"reject\",\n error\n ];\n if (data.error !== void 0) {\n shouldDismiss = false;\n var errorMsg = typeof data.error === \"function\" ? await data.error(error) : data.error;\n var description = typeof data.description === \"function\" ? await data.description(error) : data.description;\n _this.create({\n id,\n type: \"error\",\n title: errorMsg,\n description\n });\n }\n }).finally(function() {\n var _data_finally;\n if (shouldDismiss) {\n _this.dismiss(id);\n id = void 0;\n }\n (_data_finally = data.finally) === null || _data_finally === void 0 ? void 0 : _data_finally.call(data);\n });\n var unwrap = function() {\n return new Promise(function(resolve, reject) {\n return originalPromise.then(function() {\n return result[0] === \"reject\" ? reject(result[1]) : resolve(result[1]);\n }).catch(reject);\n });\n };\n if (typeof id !== \"string\" && typeof id !== \"number\") {\n return {\n unwrap\n };\n } else {\n return Object.assign(id, {\n unwrap\n });\n }\n });\n _define_property(this, \"custom\", function(jsx, data) {\n var _data_id;\n var id = (_data_id = data === null || data === void 0 ? void 0 : data.id) !== null && _data_id !== void 0 ? _data_id : toastsCounter++;\n _this.create({\n jsx: jsx(id),\n ...data,\n id\n });\n return id;\n });\n _define_property(this, \"getActiveToasts\", function() {\n return _this.toasts.filter(function(toast2) {\n return !_this.dismissedToasts.has(toast2.id);\n });\n });\n _define_property(this, \"getHistory\", function() {\n return _this.toasts;\n });\n};\nfunction isHttpResponse(data) {\n return data && (typeof data === \"undefined\" ? \"undefined\" : _type_of(data)) === \"object\" && \"ok\" in data && typeof data.ok === \"boolean\" && \"status\" in data && typeof data.status === \"number\";\n}\nvar ToastState = new Observer();\nvar toastFunction = function(title, data) {\n return ToastState.create({\n ...data,\n title\n });\n};\nvar getHistory = function() {\n return ToastState.getHistory();\n};\nvar getToasts = function() {\n return ToastState.getActiveToasts();\n};\nvar toast = Object.assign(toastFunction, {\n success: ToastState.success,\n error: ToastState.error,\n warning: ToastState.warning,\n info: ToastState.info,\n loading: ToastState.loading,\n promise: ToastState.promise,\n custom: ToastState.custom,\n dismiss: ToastState.dismiss,\n message: ToastState.message,\n getHistory,\n getToasts\n});\n//# sourceMappingURL=ToastState.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,qBAAqB,CAAC;AAC1B,SAAS,oBAAoB;CAC3B,kBAAkB;CAClB,aAAa;AACf,CAAC;AACD,OAAO,UAAU,aAAa,kBAAkB;AAChD,SAAS,kBAAkB,UAAU,aAAa;CAChD,IAAI,EAAE,oBAAoB,cAAc;EACtC,MAAM,IAAI,UAAU,mCAAmC;CACzD;AACF;AACA,SAAS,iBAAiB,KAAK,KAAK,OAAO;CACzC,IAAI,OAAO,KAAK;EACd,OAAO,eAAe,KAAK,KAAK;GAC9B;GACA,YAAY;GACZ,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version":3,"file":"ToastState.native.js","names":[],"sources":["jsx/ToastState.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar ToastState_exports = {};\n__export(ToastState_exports, {\n ToastState: () => ToastState,\n toast: () => toast\n});\nmodule.exports = __toCommonJS(ToastState_exports);\nfunction _class_call_check(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\nfunction _define_property(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\nvar toastsCounter = 1;\nvar Observer = function Observer2() {\n \"use strict\";\n var _this = this;\n _class_call_check(this, Observer2);\n _define_property(this, \"subscribers\", []);\n _define_property(this, \"toasts\", []);\n _define_property(this, \"dismissedToasts\", /* @__PURE__ */ new Set());\n _define_property(this, \"subscribe\", function(subscriber) {\n _this.subscribers.push(subscriber);\n return function() {\n var index = _this.subscribers.indexOf(subscriber);\n if (index > -1) {\n _this.subscribers.splice(index, 1);\n }\n };\n });\n _define_property(this, \"publish\", function(data) {\n _this.subscribers.forEach(function(subscriber) {\n return subscriber(data);\n });\n });\n _define_property(this, \"addToast\", function(data) {\n _this.publish(data);\n _this.toasts = [\n ..._this.toasts,\n data\n ];\n });\n _define_property(this, \"create\", function(data) {\n var { title, ...rest } = data;\n var id = typeof (data === null || data === void 0 ? void 0 : data.id) === \"number\" || typeof (data === null || data === void 0 ? void 0 : data.id) === \"string\" && data.id.length > 0 ? data.id : toastsCounter++;\n var alreadyExists = _this.toasts.find(function(toast2) {\n return toast2.id === id;\n });\n var _data_dismissible;\n var dismissible = (_data_dismissible = data.dismissible) !== null && _data_dismissible !== void 0 ? _data_dismissible : true;\n if (_this.dismissedToasts.has(id)) {\n _this.dismissedToasts.delete(id);\n }\n if (alreadyExists) {\n _this.toasts = _this.toasts.map(function(toast2) {\n if (toast2.id === id) {\n _this.publish({\n ...toast2,\n ...data,\n id,\n title,\n dismissible\n });\n return {\n ...toast2,\n ...data,\n id,\n title,\n dismissible\n };\n }\n return toast2;\n });\n } else {\n _this.addToast({\n title,\n ...rest,\n dismissible,\n id\n });\n }\n return id;\n });\n _define_property(this, \"dismiss\", function(id) {\n if (id !== void 0) {\n _this.dismissedToasts.add(id);\n requestAnimationFrame(function() {\n if (!_this.dismissedToasts.has(id)) return;\n _this.subscribers.forEach(function(subscriber) {\n return subscriber({\n id,\n dismiss: true\n });\n });\n });\n } else {\n _this.toasts.forEach(function(toast2) {\n _this.subscribers.forEach(function(subscriber) {\n return subscriber({\n id: toast2.id,\n dismiss: true\n });\n });\n });\n }\n return id;\n });\n _define_property(this, \"message\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"default\"\n });\n });\n _define_property(this, \"success\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"success\"\n });\n });\n _define_property(this, \"error\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"error\"\n });\n });\n _define_property(this, \"warning\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"warning\"\n });\n });\n _define_property(this, \"info\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"info\"\n });\n });\n _define_property(this, \"loading\", function(title, data) {\n return _this.create({\n ...data,\n title,\n type: \"loading\"\n });\n });\n _define_property(this, \"promise\", function(promise, data) {\n if (!data) {\n return;\n }\n var id = void 0;\n if (data.loading !== void 0) {\n id = _this.create({\n promise,\n type: \"loading\",\n title: data.loading,\n description: typeof data.description !== \"function\" ? data.description : void 0,\n // loading toasts shouldn't auto-dismiss\n duration: Number.POSITIVE_INFINITY\n });\n }\n var p = Promise.resolve(promise instanceof Function ? promise() : promise);\n var shouldDismiss = id !== void 0;\n var result;\n var originalPromise = p.then(async function(response) {\n result = [\n \"resolve\",\n response\n ];\n if (isHttpResponse(response) && !response.ok) {\n shouldDismiss = false;\n var errorMsg = typeof data.error === \"function\" ? await data.error(`HTTP error! status: ${response.status}`) : data.error;\n var description = typeof data.description === \"function\" ? await data.description(`HTTP error! status: ${response.status}`) : data.description;\n _this.create({\n id,\n type: \"error\",\n title: errorMsg,\n description\n });\n } else if (data.success !== void 0) {\n shouldDismiss = false;\n var successMsg = typeof data.success === \"function\" ? await data.success(response) : data.success;\n var description1 = typeof data.description === \"function\" ? await data.description(response) : data.description;\n _this.create({\n id,\n type: \"success\",\n title: successMsg,\n description: description1\n });\n }\n }).catch(async function(error) {\n result = [\n \"reject\",\n error\n ];\n if (data.error !== void 0) {\n shouldDismiss = false;\n var errorMsg = typeof data.error === \"function\" ? await data.error(error) : data.error;\n var description = typeof data.description === \"function\" ? await data.description(error) : data.description;\n _this.create({\n id,\n type: \"error\",\n title: errorMsg,\n description\n });\n }\n }).finally(function() {\n var _data_finally;\n if (shouldDismiss) {\n _this.dismiss(id);\n id = void 0;\n }\n (_data_finally = data.finally) === null || _data_finally === void 0 ? void 0 : _data_finally.call(data);\n });\n var unwrap = function() {\n return new Promise(function(resolve, reject) {\n return originalPromise.then(function() {\n return result[0] === \"reject\" ? reject(result[1]) : resolve(result[1]);\n }).catch(reject);\n });\n };\n if (typeof id !== \"string\" && typeof id !== \"number\") {\n return {\n unwrap\n };\n } else {\n return Object.assign(id, {\n unwrap\n });\n }\n });\n _define_property(this, \"custom\", function(jsx, data) {\n var _data_id;\n var id = (_data_id = data === null || data === void 0 ? void 0 : data.id) !== null && _data_id !== void 0 ? _data_id : toastsCounter++;\n _this.create({\n jsx: jsx(id),\n ...data,\n id\n });\n return id;\n });\n _define_property(this, \"getActiveToasts\", function() {\n return _this.toasts.filter(function(toast2) {\n return !_this.dismissedToasts.has(toast2.id);\n });\n });\n _define_property(this, \"getHistory\", function() {\n return _this.toasts;\n });\n};\nfunction isHttpResponse(data) {\n return data && typeof data === \"object\" && \"ok\" in data && typeof data.ok === \"boolean\" && \"status\" in data && typeof data.status === \"number\";\n}\nvar ToastState = new Observer();\nvar toastFunction = function(title, data) {\n return ToastState.create({\n ...data,\n title\n });\n};\nvar getHistory = function() {\n return ToastState.getHistory();\n};\nvar getToasts = function() {\n return ToastState.getActiveToasts();\n};\nvar toast = Object.assign(toastFunction, {\n success: ToastState.success,\n error: ToastState.error,\n warning: ToastState.warning,\n info: ToastState.info,\n loading: ToastState.loading,\n promise: ToastState.promise,\n custom: ToastState.custom,\n dismiss: ToastState.dismiss,\n message: ToastState.message,\n getHistory,\n getToasts\n});\n//# sourceMappingURL=ToastState.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,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C,SAAS,WAAW;CACpB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CACjB,SAAS,WAAW;CACpB,SAAS,WAAW;CACpB,QAAQ,WAAW;CACnB,SAAS,WAAW;CACpB,SAAS,WAAW;CACpB;CACA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/toast",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"source": "src/index.ts",
|
|
5
6
|
"files": [
|
|
6
7
|
"src",
|
|
@@ -34,27 +35,27 @@
|
|
|
34
35
|
"clean:build": "tamagui-build clean:build"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@tamagui/animate-presence": "3.0.0
|
|
38
|
-
"@tamagui/collection": "3.0.0
|
|
39
|
-
"@tamagui/compose-refs": "3.0.0
|
|
40
|
-
"@tamagui/constants": "3.0.0
|
|
41
|
-
"@tamagui/core": "3.0.0
|
|
42
|
-
"@tamagui/create-context": "3.0.0
|
|
43
|
-
"@tamagui/dismissable": "3.0.0
|
|
44
|
-
"@tamagui/helpers": "3.0.0
|
|
45
|
-
"@tamagui/native": "3.0.0
|
|
46
|
-
"@tamagui/polyfill-dev": "3.0.0
|
|
47
|
-
"@tamagui/portal": "3.0.0
|
|
48
|
-
"@tamagui/stacks": "3.0.0
|
|
49
|
-
"@tamagui/start-transition": "3.0.0
|
|
50
|
-
"@tamagui/text": "3.0.0
|
|
51
|
-
"@tamagui/use-controllable-state": "3.0.0
|
|
52
|
-
"@tamagui/visually-hidden": "3.0.0
|
|
38
|
+
"@tamagui/animate-presence": "3.0.0",
|
|
39
|
+
"@tamagui/collection": "3.0.0",
|
|
40
|
+
"@tamagui/compose-refs": "3.0.0",
|
|
41
|
+
"@tamagui/constants": "3.0.0",
|
|
42
|
+
"@tamagui/core": "3.0.0",
|
|
43
|
+
"@tamagui/create-context": "3.0.0",
|
|
44
|
+
"@tamagui/dismissable": "3.0.0",
|
|
45
|
+
"@tamagui/helpers": "3.0.0",
|
|
46
|
+
"@tamagui/native": "3.0.0",
|
|
47
|
+
"@tamagui/polyfill-dev": "3.0.0",
|
|
48
|
+
"@tamagui/portal": "3.0.0",
|
|
49
|
+
"@tamagui/stacks": "3.0.0",
|
|
50
|
+
"@tamagui/start-transition": "3.0.0",
|
|
51
|
+
"@tamagui/text": "3.0.0",
|
|
52
|
+
"@tamagui/use-controllable-state": "3.0.0",
|
|
53
|
+
"@tamagui/visually-hidden": "3.0.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@tamagui/build": "3.0.0
|
|
56
|
+
"@tamagui/build": "3.0.0",
|
|
56
57
|
"react": "19.2.3",
|
|
57
|
-
"react-native": "0.
|
|
58
|
+
"react-native": "0.87.1"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"react": ">=19"
|
|
@@ -64,5 +65,6 @@
|
|
|
64
65
|
"type": "git",
|
|
65
66
|
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
66
67
|
"directory": "code/ui/toast"
|
|
67
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"releaseSourceCommit": "15fbca480b143f876f6975601e23a17d3f90d2ee"
|
|
68
70
|
}
|
package/src/ToastComposable.tsx
CHANGED
|
@@ -3,15 +3,7 @@ import { AnimatePresence } from '@tamagui/animate-presence'
|
|
|
3
3
|
import { isWeb } from '@tamagui/constants'
|
|
4
4
|
import { getGestureHandler } from '@tamagui/native'
|
|
5
5
|
import type { GetProps, TamaguiElement } from '@tamagui/core'
|
|
6
|
-
import {
|
|
7
|
-
createStyledContext,
|
|
8
|
-
styled,
|
|
9
|
-
Theme,
|
|
10
|
-
useConfiguration,
|
|
11
|
-
useEvent,
|
|
12
|
-
useThemeName,
|
|
13
|
-
View,
|
|
14
|
-
} from '@tamagui/core'
|
|
6
|
+
import { createStyledContext, styled, useEvent, View } from '@tamagui/core'
|
|
15
7
|
import { withStaticProperties } from '@tamagui/helpers'
|
|
16
8
|
import { Portal } from '@tamagui/portal'
|
|
17
9
|
import { XStack, YStack } from '@tamagui/stacks'
|
|
@@ -200,10 +192,6 @@ export interface ToastRootProps {
|
|
|
200
192
|
* @default false
|
|
201
193
|
*/
|
|
202
194
|
expand?: boolean
|
|
203
|
-
/**
|
|
204
|
-
* Theme for toasts
|
|
205
|
-
*/
|
|
206
|
-
theme?: 'light' | 'dark' | 'system'
|
|
207
195
|
/**
|
|
208
196
|
* Force reduced motion mode
|
|
209
197
|
*/
|
|
@@ -261,7 +249,6 @@ const ToastRoot = createRefComponent<TamaguiElement, ToastRootProps>(
|
|
|
261
249
|
toastHeight = FIXED_TOAST_HEIGHT,
|
|
262
250
|
closeButton = false,
|
|
263
251
|
expand = false,
|
|
264
|
-
theme: themeProp,
|
|
265
252
|
reducedMotion: reducedMotionProp,
|
|
266
253
|
native = false,
|
|
267
254
|
burntOptions,
|
|
@@ -376,7 +363,9 @@ const ToastRoot = createRefComponent<TamaguiElement, ToastRootProps>(
|
|
|
376
363
|
if (idx !== -1) {
|
|
377
364
|
return [
|
|
378
365
|
...toasts.slice(0, idx),
|
|
379
|
-
|
|
366
|
+
// a re-created toast is shown again: drop the delete flag a
|
|
367
|
+
// previous dismiss left on it, or it would never render again.
|
|
368
|
+
{ ...toasts[idx], ...toast, delete: false },
|
|
380
369
|
...toasts.slice(idx + 1),
|
|
381
370
|
]
|
|
382
371
|
}
|
|
@@ -410,14 +399,6 @@ const ToastRoot = createRefComponent<TamaguiElement, ToastRootProps>(
|
|
|
410
399
|
|
|
411
400
|
const swipeDirection = resolveSwipeDirection(swipeDirectionProp, position)
|
|
412
401
|
|
|
413
|
-
const currentTheme = useThemeName()
|
|
414
|
-
const resolvedTheme =
|
|
415
|
-
themeProp === 'system' || !themeProp
|
|
416
|
-
? currentTheme?.includes('dark')
|
|
417
|
-
? 'dark'
|
|
418
|
-
: 'light'
|
|
419
|
-
: themeProp
|
|
420
|
-
|
|
421
402
|
const contextValue: ToastContextValue = {
|
|
422
403
|
toasts,
|
|
423
404
|
heights,
|
|
@@ -445,11 +426,7 @@ const ToastRoot = createRefComponent<TamaguiElement, ToastRootProps>(
|
|
|
445
426
|
icons,
|
|
446
427
|
}
|
|
447
428
|
|
|
448
|
-
return
|
|
449
|
-
<ToastContext.Provider {...contextValue}>
|
|
450
|
-
<Theme name={resolvedTheme as any}>{children}</Theme>
|
|
451
|
-
</ToastContext.Provider>
|
|
452
|
-
)
|
|
429
|
+
return <ToastContext.Provider {...contextValue}>{children}</ToastContext.Provider>
|
|
453
430
|
}
|
|
454
431
|
)
|
|
455
432
|
|
|
@@ -467,10 +444,15 @@ const ToastViewportFrame = styled(View, {
|
|
|
467
444
|
minHeight: 1,
|
|
468
445
|
})
|
|
469
446
|
|
|
470
|
-
export type ToastViewportProps = GetProps<typeof ToastViewportFrame> & {
|
|
447
|
+
export type ToastViewportProps = Omit<GetProps<typeof ToastViewportFrame>, 'offset'> & {
|
|
471
448
|
/**
|
|
472
|
-
* Offset from screen edge
|
|
473
|
-
*
|
|
449
|
+
* Offset from screen edge, kept as breathing room past the safe area: the
|
|
450
|
+
* viewport edge itself sits at the `safe` style value (setup-safe-area on
|
|
451
|
+
* native, env(safe-area-inset-*) on web), so pass a plain number here, not
|
|
452
|
+
* `insets.top + 8`. A number sets all four sides (on native left/right
|
|
453
|
+
* define the width); use the object form to move one edge without resizing
|
|
454
|
+
* the toast.
|
|
455
|
+
* @default 16
|
|
474
456
|
*/
|
|
475
457
|
offset?: number | { top?: number; right?: number; bottom?: number; left?: number }
|
|
476
458
|
/**
|
|
@@ -519,52 +501,49 @@ const ToastViewport = createStyledHOC(
|
|
|
519
501
|
'left' | 'center' | 'right',
|
|
520
502
|
]
|
|
521
503
|
|
|
522
|
-
//
|
|
523
|
-
// on native,
|
|
524
|
-
//
|
|
525
|
-
//
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
right: defaultOffset,
|
|
537
|
-
bottom: defaultOffset,
|
|
538
|
-
left: defaultOffset,
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
const safeTop = safeInsets?.top ?? 0
|
|
542
|
-
const safeBottom = safeInsets?.bottom ?? 0
|
|
543
|
-
|
|
544
|
-
// if safe area already provides spacing, skip the offset to avoid double padding
|
|
545
|
-
const topOffset = safeTop > 0 ? safeTop : (offsetObj.top ?? defaultOffset)
|
|
546
|
-
const bottomOffset =
|
|
547
|
-
safeBottom > 0 ? safeBottom : (offsetObj.bottom ?? defaultOffset)
|
|
548
|
-
|
|
549
|
-
if (yPosition === 'top') styles.top = topOffset
|
|
550
|
-
else styles.bottom = bottomOffset
|
|
504
|
+
// placement: the viewport edge sits at the `safe` style value
|
|
505
|
+
// (setup-safe-area on native, env(safe-area-inset-*) on web) and the
|
|
506
|
+
// offset stays breathing room past it via margin. one path for both
|
|
507
|
+
// platforms — no provider-insets plumbing here.
|
|
508
|
+
const defaultOffset = typeof offset === 'number' ? offset : VIEWPORT_OFFSET
|
|
509
|
+
const offsetObj =
|
|
510
|
+
typeof offset === 'object'
|
|
511
|
+
? offset
|
|
512
|
+
: {
|
|
513
|
+
top: defaultOffset,
|
|
514
|
+
right: defaultOffset,
|
|
515
|
+
bottom: defaultOffset,
|
|
516
|
+
left: defaultOffset,
|
|
517
|
+
}
|
|
551
518
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
519
|
+
// a number sets all four sides — on native left/right define the width,
|
|
520
|
+
// so carrying a safe-area top in a number squeezes the toast into a
|
|
521
|
+
// narrow column; use the object form to move one edge.
|
|
522
|
+
const edgeProps =
|
|
523
|
+
yPosition === 'top'
|
|
524
|
+
? { top: 'safe' as const, marginTop: offsetObj.top ?? defaultOffset }
|
|
525
|
+
: { bottom: 'safe' as const, marginBottom: offsetObj.bottom ?? defaultOffset }
|
|
526
|
+
|
|
527
|
+
const sideProps = isWeb
|
|
528
|
+
? xPosition === 'left'
|
|
529
|
+
? { left: 'safe' as const, marginLeft: offsetObj.left ?? defaultOffset }
|
|
530
|
+
: xPosition === 'right'
|
|
531
|
+
? { right: 'safe' as const, marginRight: offsetObj.right ?? defaultOffset }
|
|
532
|
+
: null
|
|
533
|
+
: // native: always set both left + right so viewport fills screen
|
|
561
534
|
// (no fixed width on native — left/right offsets define the width)
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
535
|
+
{
|
|
536
|
+
left: 'safe' as const,
|
|
537
|
+
marginLeft: offsetObj.left ?? defaultOffset,
|
|
538
|
+
right: 'safe' as const,
|
|
539
|
+
marginRight: offsetObj.right ?? defaultOffset,
|
|
540
|
+
}
|
|
565
541
|
|
|
566
|
-
|
|
567
|
-
|
|
542
|
+
// web center keeps its 50% + translate centering (margins would uncenter it)
|
|
543
|
+
const centerStyle =
|
|
544
|
+
isWeb && xPosition === 'center'
|
|
545
|
+
? { left: '50%', transform: 'translateX(-50%)' }
|
|
546
|
+
: null
|
|
568
547
|
|
|
569
548
|
// hotkey
|
|
570
549
|
React.useEffect(() => {
|
|
@@ -588,13 +567,17 @@ const ToastViewport = createStyledHOC(
|
|
|
588
567
|
|
|
589
568
|
const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '')
|
|
590
569
|
|
|
570
|
+
// the toast has no theme of its own. the portal re-establishes the theme
|
|
571
|
+
// it was mounted in at the root, and that is the theme toasts render in.
|
|
591
572
|
const content = (
|
|
592
573
|
<ToastViewportFrame
|
|
593
574
|
ref={listRef}
|
|
594
575
|
aria-label={`${label} ${hotkeyLabel}`}
|
|
595
576
|
tabIndex={-1}
|
|
596
577
|
aria-live="polite"
|
|
597
|
-
|
|
578
|
+
{...edgeProps}
|
|
579
|
+
{...sideProps}
|
|
580
|
+
{...(centerStyle ? { style: centerStyle } : null)}
|
|
598
581
|
data-y-position={yPosition}
|
|
599
582
|
data-x-position={xPosition}
|
|
600
583
|
{...(isWeb
|
|
@@ -977,15 +960,20 @@ const ToastItemInner = createStyledHOC(
|
|
|
977
960
|
setMounted(true)
|
|
978
961
|
}, [])
|
|
979
962
|
|
|
980
|
-
// handle deletion — only zero height when expanded (Sonner rebalance)
|
|
963
|
+
// handle deletion — only zero height when expanded (Sonner rebalance).
|
|
964
|
+
// a toast re-created with the same id while it is exiting comes back with
|
|
965
|
+
// delete cleared: cancel the pending unmount and show it again.
|
|
981
966
|
React.useEffect(() => {
|
|
982
|
-
if (toast.delete) {
|
|
983
|
-
setRemoved(
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
967
|
+
if (!toast.delete) {
|
|
968
|
+
setRemoved(false)
|
|
969
|
+
return
|
|
970
|
+
}
|
|
971
|
+
setRemoved(true)
|
|
972
|
+
if (isExpandedRef.current) {
|
|
973
|
+
setOffsetBeforeRemove(expandedOffsetRef.current)
|
|
988
974
|
}
|
|
975
|
+
const timer = setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT)
|
|
976
|
+
return () => clearTimeout(timer)
|
|
989
977
|
}, [toast.delete, toast, ctx.removeToast])
|
|
990
978
|
|
|
991
979
|
React.useEffect(() => {
|
|
@@ -1052,21 +1040,21 @@ const ToastItemInner = createStyledHOC(
|
|
|
1052
1040
|
},
|
|
1053
1041
|
})
|
|
1054
1042
|
|
|
1055
|
-
// measure height
|
|
1043
|
+
// measure height. web measures every toast for the expanded offsets; native
|
|
1044
|
+
// expands at the fixed toastHeight pitch, so it only measures the front toast,
|
|
1045
|
+
// which the collapsed stack sizes the cards behind it to
|
|
1056
1046
|
const handleLayout = React.useCallback(
|
|
1057
1047
|
(event: any) => {
|
|
1058
|
-
if (!isWeb) return
|
|
1059
1048
|
if (removed) return
|
|
1060
|
-
if (!ctx.expanded && index !== 0) return
|
|
1049
|
+
if ((!isWeb || !ctx.expanded) && index !== 0) return
|
|
1061
1050
|
const { height } = event.nativeEvent.layout
|
|
1062
1051
|
ctx.setToastHeight(toast.id, height)
|
|
1063
1052
|
},
|
|
1064
1053
|
[toast.id, ctx.setToastHeight, index, ctx.expanded, removed]
|
|
1065
1054
|
)
|
|
1066
1055
|
|
|
1067
|
-
// remove height on unmount
|
|
1056
|
+
// remove height on unmount
|
|
1068
1057
|
React.useEffect(() => {
|
|
1069
|
-
if (!isWeb) return
|
|
1070
1058
|
return () => {
|
|
1071
1059
|
ctx.removeToastHeight(toast.id)
|
|
1072
1060
|
}
|
|
@@ -1088,15 +1076,13 @@ const ToastItemInner = createStyledHOC(
|
|
|
1088
1076
|
[toast, handleClose]
|
|
1089
1077
|
)
|
|
1090
1078
|
|
|
1091
|
-
// front toast height for collapsed stacking
|
|
1079
|
+
// front toast height for collapsed stacking
|
|
1092
1080
|
let frontToastHeight = -1
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
break
|
|
1099
|
-
}
|
|
1081
|
+
for (const t of ctx.toasts) {
|
|
1082
|
+
const h = ctx.heights[t.id]
|
|
1083
|
+
if (h != null && h > 0) {
|
|
1084
|
+
frontToastHeight = h
|
|
1085
|
+
break
|
|
1100
1086
|
}
|
|
1101
1087
|
}
|
|
1102
1088
|
|
|
@@ -1118,15 +1104,16 @@ const ToastItemInner = createStyledHOC(
|
|
|
1118
1104
|
|
|
1119
1105
|
const computedOpacity = removed && !swipeOut ? 0 : index >= ctx.visibleToasts ? 0 : 1
|
|
1120
1106
|
const computedZIndex = removed ? 0 : ctx.visibleToasts - index + 1
|
|
1121
|
-
//
|
|
1122
|
-
//
|
|
1123
|
-
|
|
1124
|
-
|
|
1107
|
+
// collapsed, the cards behind the front toast take its height, so a taller
|
|
1108
|
+
// toast never hangs out below the stack. web also pins the measured height
|
|
1109
|
+
// while expanded for smooth expand/collapse transitions
|
|
1110
|
+
const collapsedHeight =
|
|
1111
|
+
!isFront && frontToastHeight > 0 ? frontToastHeight : undefined
|
|
1112
|
+
const computedHeight = ctx.expanded
|
|
1113
|
+
? isWeb
|
|
1125
1114
|
? ctx.heights[toast.id] || undefined
|
|
1126
|
-
:
|
|
1127
|
-
|
|
1128
|
-
: undefined
|
|
1129
|
-
: undefined
|
|
1115
|
+
: undefined
|
|
1116
|
+
: collapsedHeight
|
|
1130
1117
|
const computedPointerEvents = index >= ctx.visibleToasts ? 'none' : 'auto'
|
|
1131
1118
|
|
|
1132
1119
|
// gap filler for hover stability
|
|
@@ -1148,15 +1135,23 @@ const ToastItemInner = createStyledHOC(
|
|
|
1148
1135
|
<ToastPositionWrapper
|
|
1149
1136
|
ref={ref}
|
|
1150
1137
|
testID={rest.testID}
|
|
1151
|
-
aria-label={rest['aria-label']}
|
|
1152
1138
|
{...dataAttributes}
|
|
1153
1139
|
transition={
|
|
1154
|
-
isDragging || ctx.reducedMotion
|
|
1140
|
+
isDragging || ctx.reducedMotion
|
|
1141
|
+
? undefined
|
|
1142
|
+
: {
|
|
1143
|
+
duration: removed ? 200 : 400,
|
|
1144
|
+
// height only collapses the stack on web; native relayouts
|
|
1145
|
+
properties: isWeb ? 'transform, opacity, height' : 'transform, opacity',
|
|
1146
|
+
}
|
|
1155
1147
|
}
|
|
1156
1148
|
y={
|
|
1157
1149
|
ctx.reducedMotion
|
|
1158
1150
|
? stackY
|
|
1159
|
-
:
|
|
1151
|
+
: // every value needs an explicit `px` — a bare number inside a
|
|
1152
|
+
// transition string is a string, so `-14` would resolve as the
|
|
1153
|
+
// space token `-14` (= -56px) instead of -14 pixels
|
|
1154
|
+
`${stackY}px enter:${isTop ? -80 : 80}px exit:${
|
|
1160
1155
|
swipeOut ? (swipeExitYRef.current ?? stackY) : stackY
|
|
1161
1156
|
}px`
|
|
1162
1157
|
}
|
|
@@ -1168,13 +1163,9 @@ const ToastItemInner = createStyledHOC(
|
|
|
1168
1163
|
pointerEvents={computedPointerEvents as any}
|
|
1169
1164
|
top={isTop ? 0 : undefined}
|
|
1170
1165
|
bottom={isTop ? undefined : 0}
|
|
1171
|
-
{...(
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
})}
|
|
1175
|
-
animateOnly={
|
|
1176
|
-
isWeb ? ['transform', 'opacity', 'height'] : ['transform', 'opacity']
|
|
1177
|
-
}
|
|
1166
|
+
{...(!isFront && {
|
|
1167
|
+
style: { transformOrigin: isTop ? 'top center' : 'bottom center' },
|
|
1168
|
+
})}
|
|
1178
1169
|
>
|
|
1179
1170
|
<DragWrapper
|
|
1180
1171
|
animatedStyle={animatedStyle}
|
|
@@ -1206,6 +1197,9 @@ const ToastItemInner = createStyledHOC(
|
|
|
1206
1197
|
}
|
|
1207
1198
|
},
|
|
1208
1199
|
})}
|
|
1200
|
+
// native stacks in a column, so a card sized to the front toast only
|
|
1201
|
+
// shrinks to that height when it fills it (web stretches in its row)
|
|
1202
|
+
{...(!isWeb && computedHeight != null && { flex: 1 })}
|
|
1209
1203
|
{...rest}
|
|
1210
1204
|
>
|
|
1211
1205
|
{/* gap filler to prevent hover flicker */}
|
package/src/ToastItemFrame.tsx
CHANGED
|
@@ -53,8 +53,8 @@ export const ToastCloseFrame = styled(XStack, {
|
|
|
53
53
|
alignItems: 'center',
|
|
54
54
|
justifyContent: 'center',
|
|
55
55
|
cursor: 'pointer',
|
|
56
|
-
width:
|
|
57
|
-
height:
|
|
56
|
+
width: 24,
|
|
57
|
+
height: 24,
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -74,4 +74,8 @@ export const ToastActionFrame = styled(XStack, {
|
|
|
74
74
|
* DefaultCloseIcon - dependency-free glyph (inherits color; the skin sets it).
|
|
75
75
|
* -----------------------------------------------------------------------------------------------*/
|
|
76
76
|
|
|
77
|
-
export const DefaultCloseIcon = () =>
|
|
77
|
+
export const DefaultCloseIcon = () => (
|
|
78
|
+
<SizableText size="5" lineHeight="1">
|
|
79
|
+
✕
|
|
80
|
+
</SizableText>
|
|
81
|
+
)
|
package/src/ToastState.ts
CHANGED
|
@@ -149,8 +149,11 @@ class Observer {
|
|
|
149
149
|
dismiss = (id?: string | number) => {
|
|
150
150
|
if (id !== undefined) {
|
|
151
151
|
this.dismissedToasts.add(id)
|
|
152
|
-
// use requestAnimationFrame to batch updates
|
|
152
|
+
// use requestAnimationFrame to batch updates. a create() for the same id
|
|
153
|
+
// before the frame re-shows the toast and cancels this dismiss, otherwise
|
|
154
|
+
// the late dismiss would hide the toast that was just shown.
|
|
153
155
|
requestAnimationFrame(() => {
|
|
156
|
+
if (!this.dismissedToasts.has(id)) return
|
|
154
157
|
this.subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }))
|
|
155
158
|
})
|
|
156
159
|
} else {
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
View as TamaguiView,
|
|
23
23
|
} from '@tamagui/core'
|
|
24
24
|
import * as React from 'react'
|
|
25
|
-
import type { Animated } from 'react-native'
|
|
26
25
|
|
|
27
26
|
export interface UseToastAnimationsOptions {
|
|
28
27
|
/**
|
|
@@ -50,8 +49,8 @@ export interface ToastAnimationValues {
|
|
|
50
49
|
stop: () => void
|
|
51
50
|
/** the animated style to spread on the AnimatedView (for motion/reanimated drivers) */
|
|
52
51
|
animatedStyle: any
|
|
53
|
-
/** the animated view component from the driver */
|
|
54
|
-
AnimatedView:
|
|
52
|
+
/** the animated view component from the driver, whose props are driver-specific */
|
|
53
|
+
AnimatedView: React.ComponentType<any>
|
|
55
54
|
/** ref to attach to the drag wrapper element (for CSS driver direct DOM updates) */
|
|
56
55
|
dragRef: React.RefObject<HTMLDivElement | null>
|
|
57
56
|
}
|
|
@@ -160,7 +159,7 @@ export function useToastAnimations(
|
|
|
160
159
|
const { onExitComplete, reducedMotion } = options
|
|
161
160
|
|
|
162
161
|
const animationDriver = useAnimationDriver()
|
|
163
|
-
const AnimatedView = (animationDriver.View ?? TamaguiView) as
|
|
162
|
+
const AnimatedView = (animationDriver.View ?? TamaguiView) as React.ComponentType<any>
|
|
164
163
|
|
|
165
164
|
// ref for direct DOM manipulation during web pointer moves
|
|
166
165
|
const dragRef = React.useRef<HTMLDivElement>(null)
|