react-native-bread 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -11
- package/lib/commonjs/constants.js +25 -1
- package/lib/commonjs/icons/CloseIcon.js +22 -1
- package/lib/commonjs/icons/GreenCheck.js +27 -1
- package/lib/commonjs/icons/InfoIcon.js +24 -1
- package/lib/commonjs/icons/RedX.js +27 -1
- package/lib/commonjs/icons/index.js +34 -1
- package/lib/commonjs/index.js +65 -1
- package/lib/commonjs/pool.js +53 -1
- package/lib/commonjs/toast-api.js +127 -1
- package/lib/commonjs/toast-icons.js +80 -1
- package/lib/commonjs/toast-provider.js +109 -1
- package/lib/commonjs/toast-store.js +252 -1
- package/lib/commonjs/toast.js +351 -1
- package/lib/commonjs/types.js +6 -1
- package/lib/commonjs/use-toast-state.js +72 -1
- package/lib/module/constants.js +21 -1
- package/lib/module/icons/CloseIcon.js +16 -1
- package/lib/module/icons/GreenCheck.js +21 -1
- package/lib/module/icons/InfoIcon.js +18 -1
- package/lib/module/icons/RedX.js +21 -1
- package/lib/module/icons/index.js +7 -1
- package/lib/module/index.js +14 -1
- package/lib/module/pool.js +47 -1
- package/lib/module/toast-api.js +123 -1
- package/lib/module/toast-icons.js +74 -1
- package/lib/module/toast-provider.js +104 -1
- package/lib/module/toast-store.js +248 -1
- package/lib/module/toast.js +345 -1
- package/lib/module/types.js +4 -1
- package/lib/module/use-toast-state.js +67 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/toast-provider.d.ts +28 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -6,20 +6,19 @@ An extremely lightweight, opinionated toast component for React Native.
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- **
|
|
9
|
+
- **Lightweight** - only 20KB packed size
|
|
10
|
+
- **New Architecture** - built exclusively for React Native 0.76+ with Fabric
|
|
10
11
|
- Clean, imperative API inspired by [Sonner](https://sonner.emilkowal.ski/)
|
|
11
12
|
- Zero setup - add one component, start toasting. No hooks, no providers
|
|
12
|
-
-
|
|
13
|
+
- Smooth 60fps animations powered by Reanimated
|
|
13
14
|
- Natural swipe gestures that feel native to the platform
|
|
14
15
|
- Multiple toast types: `success`, `error`, `info`, `promise`, and `custom`
|
|
15
16
|
- Promise handling with automatic loading → success/error states
|
|
16
|
-
- Complex animations and gestures but with high performance
|
|
17
17
|
- Toast stacking with configurable limits
|
|
18
|
-
-
|
|
19
|
-
- **RTL
|
|
18
|
+
- **Works above modals** - automatic on iOS, simple setup on Android
|
|
19
|
+
- **RTL support** - perfect for Arabic and other RTL languages
|
|
20
20
|
- Completely customizable - colors, icons, styles, animations
|
|
21
21
|
- Full Expo compatibility
|
|
22
|
-
- Imperative API works anywhere - components, utilities, event handlers
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
|
|
@@ -38,19 +37,20 @@ This package requires the following peer dependencies:
|
|
|
38
37
|
| [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started) | >= 4.1.0 |
|
|
39
38
|
| [react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler/docs/) | >= 2.25.0 |
|
|
40
39
|
| [react-native-safe-area-context](https://docs.expo.dev/versions/latest/sdk/safe-area-context/) | >= 5.0.0 |
|
|
40
|
+
| [react-native-screens](https://docs.swmansion.com/react-native-screens/) | >= 4.0.0 |
|
|
41
41
|
| [react-native-svg](https://github.com/software-mansion/react-native-svg) | >= 15.8.0 |
|
|
42
42
|
| [react-native-worklets](https://github.com/margelo/react-native-worklets-core) | >= 0.5.0 |
|
|
43
43
|
|
|
44
44
|
If you don't have these installed, you can install all peer dependencies at once:
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
|
-
bun add react-native-reanimated react-native-gesture-handler react-native-safe-area-context react-native-svg react-native-worklets
|
|
47
|
+
bun add react-native-reanimated react-native-gesture-handler react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
Or with npm:
|
|
51
51
|
|
|
52
52
|
```sh
|
|
53
|
-
npm install react-native-reanimated react-native-gesture-handler react-native-safe-area-context react-native-svg react-native-worklets
|
|
53
|
+
npm install react-native-reanimated react-native-gesture-handler react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
> **Note**: Make sure your `react-native-reanimated` and `react-native-worklets` versions are compatible. Reanimated 4.1.x works with worklets 0.5.x-0.7.x, while Reanimated 4.2.x requires worklets 0.7.x only.
|
|
@@ -217,9 +217,25 @@ Available options include:
|
|
|
217
217
|
| `toast.dismiss(id)` | Dismiss a specific toast |
|
|
218
218
|
| `toast.dismissAll()` | Dismiss all toasts |
|
|
219
219
|
|
|
220
|
-
##
|
|
220
|
+
## Toasts in Modals
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
Toasts automatically appear above native modals on **iOS**.
|
|
223
223
|
|
|
224
|
-
**
|
|
224
|
+
On **Android**, add `<ToastPortal />` inside your modal layouts:
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
// app/(modal)/_layout.tsx
|
|
228
|
+
import { Stack } from "expo-router";
|
|
229
|
+
import { Platform } from "react-native";
|
|
230
|
+
import { ToastPortal } from "react-native-bread";
|
|
231
|
+
|
|
232
|
+
export default function ModalLayout() {
|
|
233
|
+
return (
|
|
234
|
+
<>
|
|
235
|
+
<Stack screenOptions={{ headerShown: false }} />
|
|
236
|
+
{Platform.OS === "android" && <ToastPortal />}
|
|
237
|
+
</>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
```
|
|
225
241
|
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SWIPE_EXIT_OFFSET = exports.STACK_TRANSITION_DURATION = exports.STACK_SCALE_PER_ITEM = exports.STACK_OFFSET_PER_ITEM = exports.SPRING_BACK_DURATION = exports.POOL_SIZE = exports.MAX_DRAG_RESISTANCE = exports.MAX_DRAG_CLAMP = exports.ICON_SIZE = exports.ICON_ANIMATION_DURATION = exports.EXIT_OFFSET = exports.EXIT_DURATION = exports.ENTRY_OFFSET = exports.ENTRY_DURATION = exports.EASING = exports.DISMISS_VELOCITY_THRESHOLD = exports.DISMISS_THRESHOLD = void 0;
|
|
7
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
8
|
+
const ICON_SIZE = exports.ICON_SIZE = 28;
|
|
9
|
+
const POOL_SIZE = exports.POOL_SIZE = 5;
|
|
10
|
+
const ENTRY_DURATION = exports.ENTRY_DURATION = 400;
|
|
11
|
+
const EXIT_DURATION = exports.EXIT_DURATION = 350;
|
|
12
|
+
const STACK_TRANSITION_DURATION = exports.STACK_TRANSITION_DURATION = 300;
|
|
13
|
+
const SPRING_BACK_DURATION = exports.SPRING_BACK_DURATION = 650;
|
|
14
|
+
const ICON_ANIMATION_DURATION = exports.ICON_ANIMATION_DURATION = 350;
|
|
15
|
+
const ENTRY_OFFSET = exports.ENTRY_OFFSET = 80;
|
|
16
|
+
const EXIT_OFFSET = exports.EXIT_OFFSET = 100;
|
|
17
|
+
const SWIPE_EXIT_OFFSET = exports.SWIPE_EXIT_OFFSET = 200;
|
|
18
|
+
const MAX_DRAG_CLAMP = exports.MAX_DRAG_CLAMP = 180;
|
|
19
|
+
const MAX_DRAG_RESISTANCE = exports.MAX_DRAG_RESISTANCE = 60;
|
|
20
|
+
const DISMISS_THRESHOLD = exports.DISMISS_THRESHOLD = 40;
|
|
21
|
+
const DISMISS_VELOCITY_THRESHOLD = exports.DISMISS_VELOCITY_THRESHOLD = 300;
|
|
22
|
+
const STACK_OFFSET_PER_ITEM = exports.STACK_OFFSET_PER_ITEM = 10;
|
|
23
|
+
const STACK_SCALE_PER_ITEM = exports.STACK_SCALE_PER_ITEM = 0.05;
|
|
24
|
+
const EASING = exports.EASING = _reactNativeReanimated.Easing.bezier(0.25, 0.1, 0.25, 1.0);
|
|
25
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CloseIcon = void 0;
|
|
7
|
+
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
const CloseIcon = props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.default, {
|
|
11
|
+
viewBox: "0 0 24 24",
|
|
12
|
+
width: 24,
|
|
13
|
+
height: 24,
|
|
14
|
+
fill: "none",
|
|
15
|
+
...props,
|
|
16
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
17
|
+
fill: props.fill ?? "#8993A4",
|
|
18
|
+
d: "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"
|
|
19
|
+
})
|
|
20
|
+
});
|
|
21
|
+
exports.CloseIcon = CloseIcon;
|
|
22
|
+
//# sourceMappingURL=CloseIcon.js.map
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GreenCheck = void 0;
|
|
7
|
+
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
const GreenCheck = props => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.default, {
|
|
11
|
+
viewBox: "0 0 30 31",
|
|
12
|
+
width: 30,
|
|
13
|
+
height: 31,
|
|
14
|
+
fill: "none",
|
|
15
|
+
...props,
|
|
16
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
17
|
+
fill: props.fill ?? "#28B770",
|
|
18
|
+
fillRule: "evenodd",
|
|
19
|
+
d: "m19.866 13.152-5.772 5.773a.933.933 0 0 1-1.326 0L9.88 16.039a.938.938 0 0 1 1.325-1.327l2.225 2.224 5.109-5.11a.938.938 0 1 1 1.326 1.326Zm.28-9.652H9.602C5.654 3.5 3 6.276 3 10.409v9.935c0 4.131 2.654 6.906 6.602 6.906h10.543c3.95 0 6.605-2.775 6.605-6.906v-9.935c0-4.133-2.654-6.909-6.604-6.909Z",
|
|
20
|
+
clipRule: "evenodd"
|
|
21
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
22
|
+
fill: "#fff",
|
|
23
|
+
d: "m19.866 13.152-5.772 5.773a.933.933 0 0 1-1.326 0L9.88 16.039a.938.938 0 0 1 1.325-1.327l2.225 2.224 5.109-5.11a.938.938 0 1 1 1.326 1.326Z"
|
|
24
|
+
})]
|
|
25
|
+
});
|
|
26
|
+
exports.GreenCheck = GreenCheck;
|
|
27
|
+
//# sourceMappingURL=GreenCheck.js.map
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InfoIcon = void 0;
|
|
7
|
+
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
const InfoIcon = props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.default, {
|
|
11
|
+
viewBox: "0 0 24 24",
|
|
12
|
+
width: 24,
|
|
13
|
+
height: 24,
|
|
14
|
+
fill: "none",
|
|
15
|
+
...props,
|
|
16
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
17
|
+
fill: props.fill ?? "#EDBE43",
|
|
18
|
+
fillRule: "evenodd",
|
|
19
|
+
d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2Zm1 15h-2v-6h2v6Zm0-8h-2V7h2v2Z",
|
|
20
|
+
clipRule: "evenodd"
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
exports.InfoIcon = InfoIcon;
|
|
24
|
+
//# sourceMappingURL=InfoIcon.js.map
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RedX = void 0;
|
|
7
|
+
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
const RedX = props => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeSvg.default, {
|
|
11
|
+
viewBox: "0 0 24 24",
|
|
12
|
+
width: 24,
|
|
13
|
+
height: 24,
|
|
14
|
+
fill: "none",
|
|
15
|
+
...props,
|
|
16
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
17
|
+
fill: props.fill ?? "#F05964",
|
|
18
|
+
fillRule: "evenodd",
|
|
19
|
+
d: "M15.58 15.572a.935.935 0 0 1-1.326 0l-2.258-2.258-2.251 2.252a.938.938 0 0 1-1.326-1.325l2.251-2.252-2.252-2.254A.936.936 0 1 1 9.742 8.41l2.253 2.252 2.252-2.25a.939.939 0 0 1 1.325 1.325l-2.25 2.252 2.257 2.257a.938.938 0 0 1 0 1.326ZM17.271.126H6.727C2.777.125.125 2.9.125 7.032v9.936c0 4.13 2.652 6.907 6.603 6.907H17.27c3.95 0 6.605-2.776 6.605-6.907V7.032c0-4.132-2.654-6.907-6.604-6.907Z",
|
|
20
|
+
clipRule: "evenodd"
|
|
21
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
22
|
+
fill: "#fff",
|
|
23
|
+
d: "M15.58 15.572a.935.935 0 0 1-1.326 0l-2.258-2.258-2.251 2.252a.938.938 0 0 1-1.326-1.325l2.251-2.252-2.252-2.254A.936.936 0 1 1 9.742 8.41l2.253 2.252 2.252-2.25a.939.939 0 0 1 1.325 1.325l-2.25 2.252 2.257 2.257a.938.938 0 0 1 0 1.326Z"
|
|
24
|
+
})]
|
|
25
|
+
});
|
|
26
|
+
exports.RedX = RedX;
|
|
27
|
+
//# sourceMappingURL=RedX.js.map
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CloseIcon", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _CloseIcon.CloseIcon;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "GreenCheck", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _GreenCheck.GreenCheck;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "InfoIcon", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _InfoIcon.InfoIcon;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "RedX", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _RedX.RedX;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _CloseIcon = require("./CloseIcon.js");
|
|
31
|
+
var _GreenCheck = require("./GreenCheck.js");
|
|
32
|
+
var _InfoIcon = require("./InfoIcon.js");
|
|
33
|
+
var _RedX = require("./RedX.js");
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
package/lib/commonjs/index.js
CHANGED
|
@@ -1 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BreadLoaf", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _toastProvider.BreadLoaf;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CloseIcon", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _index.CloseIcon;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "GreenCheck", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _index.GreenCheck;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "InfoIcon", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _index.InfoIcon;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "RedX", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _index.RedX;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "ToastContainer", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _toast.ToastContainer;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "ToastPortal", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _toastProvider.ToastPortal;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "toast", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _toastApi.toast;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "toastStore", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _toastStore.toastStore;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var _index = require("./icons/index.js");
|
|
61
|
+
var _toast = require("./toast.js");
|
|
62
|
+
var _toastApi = require("./toast-api.js");
|
|
63
|
+
var _toastProvider = require("./toast-provider.js");
|
|
64
|
+
var _toastStore = require("./toast-store.js");
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
package/lib/commonjs/pool.js
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.slotTrackers = exports.releaseSlot = exports.getSlotIndex = exports.animationPool = void 0;
|
|
7
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
8
|
+
var _constants = require("./constants.js");
|
|
9
|
+
const animationPool = exports.animationPool = Array.from({
|
|
10
|
+
length: _constants.POOL_SIZE
|
|
11
|
+
}, () => ({
|
|
12
|
+
progress: (0, _reactNativeReanimated.makeMutable)(0),
|
|
13
|
+
translationY: (0, _reactNativeReanimated.makeMutable)(0),
|
|
14
|
+
stackIndex: (0, _reactNativeReanimated.makeMutable)(0)
|
|
15
|
+
}));
|
|
16
|
+
const slotTrackers = exports.slotTrackers = Array.from({
|
|
17
|
+
length: _constants.POOL_SIZE
|
|
18
|
+
}, () => ({
|
|
19
|
+
wasExiting: false,
|
|
20
|
+
prevIndex: 0,
|
|
21
|
+
initialized: false
|
|
22
|
+
}));
|
|
23
|
+
const slotAssignments = new Map();
|
|
24
|
+
const usedSlots = new Set();
|
|
25
|
+
const getSlotIndex = toastId => {
|
|
26
|
+
if (slotAssignments.has(toastId)) {
|
|
27
|
+
return slotAssignments.get(toastId) ?? 0;
|
|
28
|
+
}
|
|
29
|
+
for (let i = 0; i < _constants.POOL_SIZE; i++) {
|
|
30
|
+
if (!usedSlots.has(i)) {
|
|
31
|
+
slotAssignments.set(toastId, i);
|
|
32
|
+
usedSlots.add(i);
|
|
33
|
+
slotTrackers[i].initialized = false;
|
|
34
|
+
slotTrackers[i].wasExiting = false;
|
|
35
|
+
slotTrackers[i].prevIndex = 0;
|
|
36
|
+
return i;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
};
|
|
41
|
+
exports.getSlotIndex = getSlotIndex;
|
|
42
|
+
const releaseSlot = toastId => {
|
|
43
|
+
const idx = slotAssignments.get(toastId);
|
|
44
|
+
if (idx !== undefined) {
|
|
45
|
+
usedSlots.delete(idx);
|
|
46
|
+
slotAssignments.delete(toastId);
|
|
47
|
+
slotTrackers[idx].initialized = false;
|
|
48
|
+
slotTrackers[idx].wasExiting = false;
|
|
49
|
+
slotTrackers[idx].prevIndex = 0;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.releaseSlot = releaseSlot;
|
|
53
|
+
//# sourceMappingURL=pool.js.map
|
|
@@ -1 +1,127 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toast = void 0;
|
|
7
|
+
var _toastStore = require("./toast-store.js");
|
|
8
|
+
const _toast = (title, description, type, duration) => {
|
|
9
|
+
_toastStore.toastStore.show(title, description, type, duration);
|
|
10
|
+
};
|
|
11
|
+
const parseDescriptionOrOptions = arg => {
|
|
12
|
+
if (!arg) return {};
|
|
13
|
+
if (typeof arg === "string") return {
|
|
14
|
+
description: arg
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
description: arg.description,
|
|
18
|
+
duration: arg.duration,
|
|
19
|
+
options: arg
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const parseMessage = input => typeof input === "string" ? {
|
|
23
|
+
title: input
|
|
24
|
+
} : input;
|
|
25
|
+
const parseErrorMessage = (input, error) => {
|
|
26
|
+
if (typeof input === "function") {
|
|
27
|
+
return parseMessage(input(error));
|
|
28
|
+
}
|
|
29
|
+
return parseMessage(input);
|
|
30
|
+
};
|
|
31
|
+
const promiseToast = async (promise, messages) => {
|
|
32
|
+
const loadingCfg = parseMessage(messages.loading);
|
|
33
|
+
const toastId = _toastStore.toastStore.show(loadingCfg.title, loadingCfg.description, "loading", loadingCfg.duration ?? 60 * 60 * 1000);
|
|
34
|
+
try {
|
|
35
|
+
const result = await promise;
|
|
36
|
+
const successCfg = parseMessage(messages.success);
|
|
37
|
+
_toastStore.toastStore.updateToast(toastId, {
|
|
38
|
+
title: successCfg.title,
|
|
39
|
+
description: successCfg.description,
|
|
40
|
+
type: "success",
|
|
41
|
+
duration: successCfg.duration ?? 4000
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
data: result,
|
|
45
|
+
success: true
|
|
46
|
+
};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
49
|
+
const errorCfg = parseErrorMessage(messages.error, error);
|
|
50
|
+
_toastStore.toastStore.updateToast(toastId, {
|
|
51
|
+
title: errorCfg.title,
|
|
52
|
+
description: errorCfg.description,
|
|
53
|
+
type: "error",
|
|
54
|
+
duration: errorCfg.duration ?? 4000
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
error,
|
|
58
|
+
success: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const toastFn = _toast;
|
|
63
|
+
toastFn.custom = (content, options) => {
|
|
64
|
+
const type = options?.type ?? "info";
|
|
65
|
+
return _toastStore.toastStore.show("", undefined, type, options?.duration, {
|
|
66
|
+
...options,
|
|
67
|
+
customContent: content
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
toastFn.success = (title, descriptionOrOptions, duration) => {
|
|
71
|
+
const {
|
|
72
|
+
description,
|
|
73
|
+
duration: optDuration,
|
|
74
|
+
options
|
|
75
|
+
} = parseDescriptionOrOptions(descriptionOrOptions);
|
|
76
|
+
_toastStore.toastStore.show(title, description, "success", duration ?? optDuration, options);
|
|
77
|
+
};
|
|
78
|
+
toastFn.error = (title, descriptionOrOptions, duration) => {
|
|
79
|
+
const {
|
|
80
|
+
description,
|
|
81
|
+
duration: optDuration,
|
|
82
|
+
options
|
|
83
|
+
} = parseDescriptionOrOptions(descriptionOrOptions);
|
|
84
|
+
_toastStore.toastStore.show(title, description, "error", duration ?? optDuration, options);
|
|
85
|
+
};
|
|
86
|
+
toastFn.info = (title, descriptionOrOptions, duration) => {
|
|
87
|
+
const {
|
|
88
|
+
description,
|
|
89
|
+
duration: optDuration,
|
|
90
|
+
options
|
|
91
|
+
} = parseDescriptionOrOptions(descriptionOrOptions);
|
|
92
|
+
_toastStore.toastStore.show(title, description, "info", duration ?? optDuration, options);
|
|
93
|
+
};
|
|
94
|
+
toastFn.promise = promiseToast;
|
|
95
|
+
toastFn.dismiss = id => {
|
|
96
|
+
_toastStore.toastStore.hide(id);
|
|
97
|
+
};
|
|
98
|
+
toastFn.dismissAll = () => {
|
|
99
|
+
_toastStore.toastStore.hideAll();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Toast API for showing notifications.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { toast } from 'react-native-bread';
|
|
108
|
+
*
|
|
109
|
+
* // Basic toasts
|
|
110
|
+
* toast.success("Saved!", "Your changes have been saved");
|
|
111
|
+
* toast.error("Error", "Something went wrong");
|
|
112
|
+
* toast.info("Tip", "Swipe up to dismiss");
|
|
113
|
+
*
|
|
114
|
+
* // Promise toast (loading → success/error)
|
|
115
|
+
* toast.promise(apiCall(), {
|
|
116
|
+
* loading: { title: "Loading..." },
|
|
117
|
+
* success: { title: "Done!" },
|
|
118
|
+
* error: (err) => ({ title: "Failed", description: err.message }),
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* // Dismiss toasts
|
|
122
|
+
* toast.dismiss(id);
|
|
123
|
+
* toast.dismissAll();
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
const toast = exports.toast = toastFn;
|
|
127
|
+
//# sourceMappingURL=toast-api.js.map
|
|
@@ -1 +1,80 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveIcon = exports.AnimatedIcon = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
|
+
var _constants = require("./constants.js");
|
|
11
|
+
var _index = require("./icons/index.js");
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
const resolveIcon = (type, color, custom, config) => {
|
|
15
|
+
if (custom) return typeof custom === "function" ? custom({
|
|
16
|
+
color,
|
|
17
|
+
size: _constants.ICON_SIZE
|
|
18
|
+
}) : custom;
|
|
19
|
+
if (config) return config({
|
|
20
|
+
color,
|
|
21
|
+
size: _constants.ICON_SIZE
|
|
22
|
+
});
|
|
23
|
+
switch (type) {
|
|
24
|
+
case "success":
|
|
25
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GreenCheck, {
|
|
26
|
+
width: 36,
|
|
27
|
+
height: 36,
|
|
28
|
+
fill: color
|
|
29
|
+
});
|
|
30
|
+
case "error":
|
|
31
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.RedX, {
|
|
32
|
+
width: _constants.ICON_SIZE,
|
|
33
|
+
height: _constants.ICON_SIZE,
|
|
34
|
+
fill: color
|
|
35
|
+
});
|
|
36
|
+
case "loading":
|
|
37
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
|
|
38
|
+
size: _constants.ICON_SIZE,
|
|
39
|
+
color: color
|
|
40
|
+
});
|
|
41
|
+
case "info":
|
|
42
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.InfoIcon, {
|
|
43
|
+
width: _constants.ICON_SIZE,
|
|
44
|
+
height: _constants.ICON_SIZE,
|
|
45
|
+
fill: color
|
|
46
|
+
});
|
|
47
|
+
default:
|
|
48
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GreenCheck, {
|
|
49
|
+
width: 36,
|
|
50
|
+
height: 36,
|
|
51
|
+
fill: color
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.resolveIcon = resolveIcon;
|
|
56
|
+
const AnimatedIcon = exports.AnimatedIcon = /*#__PURE__*/(0, _react.memo)(({
|
|
57
|
+
type,
|
|
58
|
+
color,
|
|
59
|
+
custom,
|
|
60
|
+
config
|
|
61
|
+
}) => {
|
|
62
|
+
const progress = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
63
|
+
(0, _react.useEffect)(() => {
|
|
64
|
+
progress.value = (0, _reactNativeReanimated.withTiming)(1, {
|
|
65
|
+
duration: _constants.ICON_ANIMATION_DURATION,
|
|
66
|
+
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.back(1.5))
|
|
67
|
+
});
|
|
68
|
+
}, [progress]);
|
|
69
|
+
const style = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
70
|
+
opacity: progress.value,
|
|
71
|
+
transform: [{
|
|
72
|
+
scale: 0.7 + progress.value * 0.3
|
|
73
|
+
}]
|
|
74
|
+
}));
|
|
75
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
76
|
+
style: style,
|
|
77
|
+
children: resolveIcon(type, color, custom, config)
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=toast-icons.js.map
|