expo-error-toast
Version:
Toast to show error messages for Expo applications
426 lines (425 loc) • 12.5 kB
JavaScript
import ie, { useState as P, createContext as le, useContext as ce, useCallback as W } from "react";
import { StyleSheet as ue, Pressable as S, View as g, ScrollView as fe, Text as de } from "react-native";
import O from "@expo/vector-icons/FontAwesome";
import * as me from "expo-clipboard";
var A = { exports: {} }, R = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var L;
function Ee() {
if (L) return R;
L = 1;
var o = Symbol.for("react.transitional.element"), m = Symbol.for("react.fragment");
function c(d, n, l) {
var b = null;
if (l !== void 0 && (b = "" + l), n.key !== void 0 && (b = "" + n.key), "key" in n) {
l = {};
for (var p in n)
p !== "key" && (l[p] = n[p]);
} else l = n;
return n = l.ref, {
$$typeof: o,
type: d,
key: b,
ref: n !== void 0 ? n : null,
props: l
};
}
return R.Fragment = m, R.jsx = c, R.jsxs = c, R;
}
var v = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var U;
function be() {
return U || (U = 1, process.env.NODE_ENV !== "production" && function() {
function o(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === ne ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case x:
return "Fragment";
case H:
return "Profiler";
case X:
return "StrictMode";
case ee:
return "Suspense";
case re:
return "SuspenseList";
case oe:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case G:
return "Portal";
case Q:
return (e.displayName || "Context") + ".Provider";
case Z:
return (e._context.displayName || "Context") + ".Consumer";
case K:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case te:
return r = e.displayName || null, r !== null ? r : o(e.type) || "Memo";
case Y:
r = e._payload, e = e._init;
try {
return o(e(r));
} catch {
}
}
return null;
}
function m(e) {
return "" + e;
}
function c(e) {
try {
m(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
a
), m(e);
}
}
function d(e) {
if (e === x) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === Y)
return "<...>";
try {
var r = o(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function n() {
var e = _.A;
return e === null ? null : e.getOwner();
}
function l() {
return Error("react-stack-top-frame");
}
function b(e) {
if (D.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function p(e, r) {
function t() {
F || (F = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
r
));
}
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
function q() {
var e = o(this.type);
return $[e] || ($[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function B(e, r, t, a, E, u, y, j) {
return t = u.ref, e = {
$$typeof: I,
type: e,
key: r,
props: u,
_owner: E
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: q
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: y
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: j
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function C(e, r, t, a, E, u, y, j) {
var s = r.children;
if (s !== void 0)
if (a)
if (ae(s)) {
for (a = 0; a < s.length; a++)
N(s[a]);
Object.freeze && Object.freeze(s);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else N(s);
if (D.call(r, "key")) {
s = o(e);
var h = Object.keys(r).filter(function(se) {
return se !== "key";
});
a = 0 < h.length ? "{key: someKey, " + h.join(": ..., ") + ": ...}" : "{key: someKey}", V[s + a] || (h = 0 < h.length ? "{" + h.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
a,
s,
h,
s
), V[s + a] = !0);
}
if (s = null, t !== void 0 && (c(t), s = "" + t), b(r) && (c(r.key), s = "" + r.key), "key" in r) {
t = {};
for (var k in r)
k !== "key" && (t[k] = r[k]);
} else t = r;
return s && p(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), B(
e,
s,
u,
E,
n(),
t,
y,
j
);
}
function N(e) {
typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
}
var T = ie, I = Symbol.for("react.transitional.element"), G = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), X = Symbol.for("react.strict_mode"), H = Symbol.for("react.profiler"), Z = Symbol.for("react.consumer"), Q = Symbol.for("react.context"), K = Symbol.for("react.forward_ref"), ee = Symbol.for("react.suspense"), re = Symbol.for("react.suspense_list"), te = Symbol.for("react.memo"), Y = Symbol.for("react.lazy"), oe = Symbol.for("react.activity"), ne = Symbol.for("react.client.reference"), _ = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, ae = Array.isArray, w = console.createTask ? console.createTask : function() {
return null;
};
T = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var F, $ = {}, M = T["react-stack-bottom-frame"].bind(
T,
l
)(), z = w(d(l)), V = {};
v.Fragment = x, v.jsx = function(e, r, t, a, E) {
var u = 1e4 > _.recentlyCreatedOwnerStacks++;
return C(
e,
r,
t,
!1,
a,
E,
u ? Error("react-stack-top-frame") : M,
u ? w(d(e)) : z
);
}, v.jsxs = function(e, r, t, a, E) {
var u = 1e4 > _.recentlyCreatedOwnerStacks++;
return C(
e,
r,
t,
!0,
a,
E,
u ? Error("react-stack-top-frame") : M,
u ? w(d(e)) : z
);
};
}()), v;
}
process.env.NODE_ENV === "production" ? A.exports = Ee() : A.exports = be();
var i = A.exports;
const pe = ({
message: o,
onClose: m,
visible: c
}) => {
const [d, n] = P(!1), l = async () => {
await me.setStringAsync(o), n(!0), setTimeout(() => n(!1), 2e3);
};
return c ? /* @__PURE__ */ i.jsxs(i.Fragment, { children: [
/* @__PURE__ */ i.jsx(S, { style: f.overlay }),
/* @__PURE__ */ i.jsx(g, { style: f.container, children: /* @__PURE__ */ i.jsxs(g, { style: f.content, children: [
/* @__PURE__ */ i.jsxs(g, { style: f.messageContainer, children: [
/* @__PURE__ */ i.jsx(
O,
{
name: "exclamation-circle",
size: 20,
color: "white",
style: f.icon
}
),
/* @__PURE__ */ i.jsx(
fe,
{
style: f.scrollView,
showsVerticalScrollIndicator: !0,
children: /* @__PURE__ */ i.jsx(de, { style: f.message, children: o })
}
)
] }),
/* @__PURE__ */ i.jsxs(g, { style: f.buttonsContainer, children: [
/* @__PURE__ */ i.jsx(S, { onPress: m, style: f.closeButton, hitSlop: 8, children: /* @__PURE__ */ i.jsx(O, { name: "times", size: 20, color: "white" }) }),
/* @__PURE__ */ i.jsx(
S,
{
onPress: l,
style: f.copyButton,
hitSlop: 8,
children: /* @__PURE__ */ i.jsx(
O,
{
name: d ? "check" : "copy",
size: 18,
color: "white"
}
)
}
)
] })
] }) })
] }) : null;
}, f = ue.create({
overlay: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: "rgba(0, 0, 0, 0.5)",
zIndex: 9998
},
container: {
position: "absolute",
top: 140,
left: 16,
right: 16,
zIndex: 9999
},
content: {
backgroundColor: "rgba(255, 59, 48, 0.9)",
borderRadius: 8,
padding: 16,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "flex-start",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
maxWidth: "100%"
},
messageContainer: {
flexDirection: "row",
flex: 1,
marginRight: 12
},
scrollView: {
flex: 1,
maxHeight: 200
},
icon: {
marginRight: 12
},
message: {
color: "white",
fontSize: 16,
fontWeight: "600"
},
buttonsContainer: {
flexDirection: "column",
alignItems: "center",
gap: 16
},
closeButton: {
padding: 4
},
copyButton: {
padding: 4
}
}), J = le(void 0);
function ge() {
const o = ce(J);
if (!o)
throw new Error("useErrorToast must be used within an ErrorToastProvider");
return o;
}
const he = (o) => o instanceof Error ? o.message : typeof o == "string" ? o : JSON.stringify(o);
function xe({ children: o }) {
const [m, c] = P(""), [d, n] = P(!1), l = W((p) => {
c(he(p)), n(!0);
}, []), b = W(() => {
n(!1), setTimeout(() => c(""), 300);
}, []);
return /* @__PURE__ */ i.jsxs(J.Provider, { value: { showError: l }, children: [
o,
/* @__PURE__ */ i.jsx(
pe,
{
message: m,
visible: d,
onClose: b
}
)
] });
}
export {
pe as ErrorToast,
xe as ErrorToastProvider,
ge as useErrorToast
};