@lapp-studio/react-toast-engine 0.0.1 β†’ 0.0.2

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 (2) hide show
  1. package/README.md +72 -37
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,33 +1,40 @@
1
1
  # React Toast Engine 🍞
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@lapp-studio/react-toast-engine.svg?style=flat-square)](https://www.npmjs.com/package/@lapp-studio/react-toast-engine)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT)
5
+
3
6
  **React Toast Engine** is a high-performance, headless toast management library for **React** and **React Native**.
4
7
 
5
- It separates state logic (powered by Zustand) from the UI layer, allowing you to share the same notification logic across Web and Mobile while maintaining 60FPS native animations using **Reanimated**.
8
+ It separates state logic (powered by [Zustand](https://github.com/pmndrs/zustand)) from the UI layer, allowing you to share the exact same notification logic across Web and Mobile. For React Native, it maintains flawless 60FPS animations natively using **Reanimated** and **Gesture Handler**, without locking the JS thread.
6
9
 
7
10
  ## ✨ Key Features
8
11
 
9
- - πŸš€ **Zero-Lag State:** Atomic updates via Zustand to prevent unnecessary re-renders.
10
- - πŸ“± **Native First:** Deep integration with `react-native-reanimated` and `gesture-handler`.
11
- - 🌐 **Truly Hybrid:** Multiple entry points to ensure Web builds don't bundle Native code.
12
- - πŸ—οΈ **Headless & Flexible:** You provide the components; we handle the stack, queue, and lifecycle.
12
+ - πŸš€ **Zero-Lag State:** Atomic updates via Zustand to prevent unnecessary re-renders across your app.
13
+ - πŸ“± **Native First:** Deep, out-of-the-box integration with `react-native-reanimated`, `react-native-gesture-handler`, and `react-native-worklets`.
14
+ - 🌐 **Truly Hybrid (Tree-Shakeable):** Separate entry points for Core (`/`) and Native (`/native`) ensure your Web builds never bundle heavy React Native libraries.
15
+ - πŸ—οΈ **100% Headless & Flexible:** You build the UI components; the engine handles the stacking, queuing, lifecycle, and gesture logic.
16
+ - πŸ›‘οΈ **Smart Provider Stacking:** If multiple providers exist in the DOM/Tree, the engine intelligently routes toasts only to the topmost (active) provider to prevent duplicates.
13
17
 
14
18
  ---
15
19
 
16
20
  ## πŸ“¦ Installation
17
21
 
22
+ Install the core library:
23
+
18
24
  ```bash
19
25
  # npm
20
26
  npm i @lapp-studio/react-toast-engine
27
+
21
28
  # yarn
22
29
  yarn add @lapp-studio/react-toast-engine
23
30
  ```
24
31
 
25
- ### Peer Dependencies
32
+ ### React Native Peer Dependencies
26
33
 
27
- For **React Native** environments, ensure the following are installed:
34
+ If you are using React Native, ensure you have the required animation and gesture libraries installed in your project:
28
35
 
29
36
  ```bash
30
- yarn add react-native-reanimated react-native-gesture-handler react-native-safe-area-context
37
+ yarn add react-native-reanimated react-native-gesture-handler react-native-safe-area-context react-native-worklets
31
38
  ```
32
39
 
33
40
  ---
@@ -36,29 +43,39 @@ yarn add react-native-reanimated react-native-gesture-handler react-native-safe-
36
43
 
37
44
  ### 1. Initialize the Client
38
45
 
39
- Define your UI components and initialize the engine.
46
+ Create a shared file (e.g., `src/lib/toasts.ts`) to configure your UI components and initialize the engine.
40
47
 
41
48
  ```typescript
42
49
  // src/lib/toasts.ts
43
- import { createToastsClient } from "@lapp-studio/react-toast-engine";
44
- import PoolRenderer from "@lapp-studio/react-toast-engine/native"; // For React Native
50
+ import { createToastsClient } from "@lapp-studio/react-toast-engine/core";
51
+
52
+ // Import the native renderer only in your React Native app
53
+ import { PoolRenderer } from "@lapp-studio/react-toast-engine/native";
45
54
 
55
+ import {
56
+ MySuccessComponent,
57
+ MyErrorComponent,
58
+ MyInfoComponent,
59
+ } from "./components";
60
+
61
+ // Map your custom components to the engine's InfoTypes
46
62
  const components = {
47
63
  success: MySuccessComponent,
48
64
  error: MyErrorComponent,
49
65
  info: MyInfoComponent,
50
66
  };
51
67
 
68
+ // Create and export the client tools
52
69
  export const { store, utilities, renderer } = createToastsClient({
53
70
  components,
54
71
  PoolRenderer,
55
- storeSettings: { poolLimit: 5 },
72
+ storeSettings: { poolLimit: 5 }, // Keep a maximum of 5 toasts in the DOM at once
56
73
  });
57
74
  ```
58
75
 
59
76
  ### 2. Setup the Provider
60
77
 
61
- Wrap your application root with the generated `Provider`.
78
+ Wrap your application's root component with the generated `Provider`.
62
79
 
63
80
  ```tsx
64
81
  import { renderer } from "./lib/toasts";
@@ -74,45 +91,63 @@ export function App() {
74
91
 
75
92
  ### 3. Trigger Toasts
76
93
 
77
- Use hooks inside components or helpers for business logic (e.g., API interceptors).
94
+ You can stack toasts from anywhere in your appβ€”either via React hooks inside your components or via helper functions in standard TypeScript files.
95
+
96
+ **Inside a React Component (Using Hooks):**
78
97
 
79
98
  ```tsx
99
+ import { Button } from "react-native";
80
100
  import { utilities } from "./lib/toasts";
81
101
 
82
- // Inside a React Component
83
- const stack = utilities.hooks.useStackToast();
102
+ export const SaveButton = () => {
103
+ const stack = utilities.hooks.useStackToast();
84
104
 
85
- // Outside React (e.g., inside an Axios Interceptor)
86
- utilities.helpers.stack({
87
- title: "Success!",
88
- description: "Changes saved successfully.",
89
- infoType: "success",
90
- durationInMs: 3000,
91
- });
92
- ```
105
+ const handlePress = () => {
106
+ stack({
107
+ title: "Success!",
108
+ description: "Profile updated.",
109
+ infoType: "success",
110
+ durationInMs: 3000,
111
+ });
112
+ };
93
113
 
94
- ---
95
-
96
- ## πŸ› οΈ Architecture
114
+ return <Button title="Save" onPress={handlePress} />;
115
+ };
116
+ ```
97
117
 
98
- The library follows a **Decoupled Provider-Consumer** pattern:
118
+ **Outside React (Using Helpers - Great for API Interceptors):**
99
119
 
100
- 1. **Store (Zustand):** Manages the global toast pool and provider stack.
101
- 2. **Utilities:** Provides a clean API via `hooks` for UI and `helpers` for logic.
102
- 3. **Renderer:** Handles priority. If multiple providers are present, only the topmost (latest) one renders the active toasts to prevent duplicates.
120
+ ```typescript
121
+ import { utilities } from "./lib/toasts";
122
+ import api from "./api";
123
+
124
+ api.interceptors.response.use(
125
+ (response) => response,
126
+ (error) => {
127
+ utilities.helpers.stack({
128
+ title: "Connection Error",
129
+ description: error.message,
130
+ infoType: "error",
131
+ durationInMs: 5000,
132
+ });
133
+ return Promise.reject(error);
134
+ },
135
+ );
136
+ ```
103
137
 
104
138
  ---
105
139
 
106
- ## πŸ“± React Native Specifics
140
+ ## πŸ“± React Native Architecture
107
141
 
108
- The native build uses **Shared Values** and **Worklets** for maximum performance:
142
+ The native implementation uses **Shared Values** and **Worklets** to achieve native-level performance:
109
143
 
110
- - **Swipe to Dismiss:** Fully interactive gestures to clear notifications.
111
- - **Safe Area Aware:** Automatically calculates offsets using `react-native-safe-area-context`.
112
- - **Z-Index Management:** Smart stacking logic that works across different navigation screens.
144
+ - **Swipe to Dismiss:** Fully interactive, physics-based gestures to clear notifications. Swipe velocities are calculated in real-time.
145
+ - **UI Thread Operations:** Dismissing a toast uses `scheduleOnRN` to bypass the JS thread entirely, avoiding stutters during heavy computations.
146
+ - **Safe Area Aware:** Automatically shifts offsets using `react-native-safe-area-context` to prevent overlapping with notches or dynamic islands.
147
+ - **Dynamic Z-Index:** Smart stacking logic that recalculates layer priorities smoothly as new toasts arrive or leave.
113
148
 
114
149
  ---
115
150
 
116
151
  ## πŸ“„ License
117
152
 
118
- MIT Β© LApp
153
+ MIT Β© L'App Studio
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lapp-studio/react-toast-engine",
3
- "version": "0.00.1",
3
+ "version": "0.0.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/core.js",