@mehul214/react-native-flash-toast 0.0.0-stage → 1.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/LICENSE +22 -0
- package/README.md +251 -2
- package/dist/index.d.mts +229 -0
- package/dist/index.d.ts +231 -0
- package/dist/index.js +613 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +594 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +87 -4
- package/src/FlashMessage.tsx +398 -0
- package/src/FlashMessageManager.ts +71 -0
- package/src/FlashMessageProvider.tsx +48 -0
- package/src/hooks/useFlashMessage.ts +2 -0
- package/src/icons.tsx +74 -0
- package/src/index.ts +31 -0
- package/src/styles.ts +135 -0
- package/src/types.ts +101 -0
- package/src/utils/safeArea.ts +45 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
type FlashMessageType = 'default' | 'success' | 'danger' | 'warning' | 'info';
|
|
5
|
+
type FlashMessagePosition = 'top' | 'bottom' | 'center';
|
|
6
|
+
type FlashMessageTransition = 'slide' | 'fade' | 'bounce';
|
|
7
|
+
type FlashMessageIcon = FlashMessageType | 'none' | ReactNode | ((props: {
|
|
8
|
+
size: number;
|
|
9
|
+
color: string;
|
|
10
|
+
}) => ReactNode);
|
|
11
|
+
interface FlashMessageAction {
|
|
12
|
+
label: string;
|
|
13
|
+
onPress: () => void;
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
textStyle?: StyleProp<TextStyle>;
|
|
16
|
+
}
|
|
17
|
+
interface FlashMessageOptions {
|
|
18
|
+
/** Unique ID for the message. Auto-generated if not provided */
|
|
19
|
+
id?: string;
|
|
20
|
+
/** Primary title or content */
|
|
21
|
+
message: string | ReactNode;
|
|
22
|
+
/** Secondary subtitle or body content */
|
|
23
|
+
description?: string | ReactNode;
|
|
24
|
+
/** Preset semantic style */
|
|
25
|
+
type?: FlashMessageType;
|
|
26
|
+
/** Screen position: 'top', 'bottom', or 'center'. Default: 'top' */
|
|
27
|
+
position?: FlashMessagePosition;
|
|
28
|
+
/** Display duration in milliseconds before auto-hiding. Default: 3000ms. Set to 0 to disable */
|
|
29
|
+
duration?: number;
|
|
30
|
+
/** Whether the message auto-dismisses after duration. Default: true */
|
|
31
|
+
autoHide?: boolean;
|
|
32
|
+
/** Floating pill with rounded corners vs edge-to-edge bar. Default: true */
|
|
33
|
+
floating?: boolean;
|
|
34
|
+
/** Preset or custom icon */
|
|
35
|
+
icon?: FlashMessageIcon;
|
|
36
|
+
/** Interactive action button (e.g. Undo, Retry) */
|
|
37
|
+
action?: FlashMessageAction;
|
|
38
|
+
/** Callback fired when the flash message card is tapped */
|
|
39
|
+
onPress?: () => void;
|
|
40
|
+
/** Callback fired when the flash message is long-pressed */
|
|
41
|
+
onLongPress?: () => void;
|
|
42
|
+
/** Callback fired after the message appears */
|
|
43
|
+
onShow?: () => void;
|
|
44
|
+
/** Callback fired after the message has fully hidden */
|
|
45
|
+
onHide?: () => void;
|
|
46
|
+
/** Custom container style */
|
|
47
|
+
style?: StyleProp<ViewStyle>;
|
|
48
|
+
/** Custom title text style */
|
|
49
|
+
titleStyle?: StyleProp<TextStyle>;
|
|
50
|
+
/** Custom description text style */
|
|
51
|
+
textStyle?: StyleProp<TextStyle>;
|
|
52
|
+
/** Override background color */
|
|
53
|
+
backgroundColor?: string;
|
|
54
|
+
/** Override text and icon color */
|
|
55
|
+
color?: string;
|
|
56
|
+
/** Dismiss when tapped. Default: true */
|
|
57
|
+
hideOnPress?: boolean;
|
|
58
|
+
/** Enable swipe up/down gesture to dismiss. Default: true */
|
|
59
|
+
swipeToDismiss?: boolean;
|
|
60
|
+
/** Temporarily pause the autoHide timer while finger touches the banner. Default: true */
|
|
61
|
+
pauseOnPress?: boolean;
|
|
62
|
+
/** Show an animated countdown progress bar at the bottom of the card. Default: false */
|
|
63
|
+
showProgressBar?: boolean;
|
|
64
|
+
/** Transition animation style: 'slide' | 'fade' | 'bounce'. Default: 'slide' */
|
|
65
|
+
transition?: FlashMessageTransition;
|
|
66
|
+
/** Override manual top inset / status bar height if needed */
|
|
67
|
+
statusBarHeight?: number;
|
|
68
|
+
/** Custom render function to completely override inner layout */
|
|
69
|
+
customComponent?: (options: FlashMessageOptions, hide: () => void) => ReactNode;
|
|
70
|
+
}
|
|
71
|
+
interface FlashMessageRef {
|
|
72
|
+
showMessage: (options: FlashMessageOptions) => void;
|
|
73
|
+
hideMessage: () => void;
|
|
74
|
+
}
|
|
75
|
+
interface FlashMessageContainerProps {
|
|
76
|
+
/** Default position for all messages if not specified in options */
|
|
77
|
+
position?: FlashMessagePosition;
|
|
78
|
+
/** Default duration in ms. Default: 3000 */
|
|
79
|
+
duration?: number;
|
|
80
|
+
/** Default floating style. Default: true */
|
|
81
|
+
floating?: boolean;
|
|
82
|
+
/** Default transition. Default: 'slide' */
|
|
83
|
+
transition?: FlashMessageTransition;
|
|
84
|
+
/** Optional top status bar offset */
|
|
85
|
+
statusBarOffset?: number;
|
|
86
|
+
/** Optional bottom navigation bar offset */
|
|
87
|
+
bottomOffset?: number;
|
|
88
|
+
/** Extra container style */
|
|
89
|
+
style?: StyleProp<ViewStyle>;
|
|
90
|
+
/** Can message replace current one immediately or queue. Default: 'replace' */
|
|
91
|
+
mode?: 'replace' | 'queue';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
declare const FlashMessage: React.ForwardRefExoticComponent<FlashMessageContainerProps & React.RefAttributes<FlashMessageRef>>;
|
|
95
|
+
|
|
96
|
+
declare class FlashMessageManager {
|
|
97
|
+
private defaultInstance;
|
|
98
|
+
private instances;
|
|
99
|
+
private pendingQueue;
|
|
100
|
+
register(ref: FlashMessageRef, id?: string): void;
|
|
101
|
+
unregister(id?: string): void;
|
|
102
|
+
showMessage(options: FlashMessageOptions, targetId?: string): void;
|
|
103
|
+
hideMessage(targetId?: string): void;
|
|
104
|
+
}
|
|
105
|
+
declare const flashManager: FlashMessageManager;
|
|
106
|
+
/**
|
|
107
|
+
* Imperative helper to trigger a flash message from anywhere in the app
|
|
108
|
+
* (services, Zustand, Redux, API handlers, navigation screens).
|
|
109
|
+
*/
|
|
110
|
+
declare function showMessage(options: FlashMessageOptions): void;
|
|
111
|
+
/**
|
|
112
|
+
* Imperative helper to dismiss the currently displayed flash message.
|
|
113
|
+
*/
|
|
114
|
+
declare function hideMessage(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Modern alias for showMessage
|
|
117
|
+
*/
|
|
118
|
+
declare const flash: typeof showMessage;
|
|
119
|
+
declare const dismissFlash: typeof hideMessage;
|
|
120
|
+
|
|
121
|
+
interface FlashMessageContextValue {
|
|
122
|
+
show: (options: FlashMessageOptions) => void;
|
|
123
|
+
hide: () => void;
|
|
124
|
+
}
|
|
125
|
+
interface FlashMessageProviderProps extends FlashMessageContainerProps {
|
|
126
|
+
children: React.ReactNode;
|
|
127
|
+
}
|
|
128
|
+
declare const FlashMessageProvider: React.FC<FlashMessageProviderProps>;
|
|
129
|
+
declare function useFlashMessage(): FlashMessageContextValue;
|
|
130
|
+
|
|
131
|
+
interface BuiltInIconProps {
|
|
132
|
+
type: FlashMessageType;
|
|
133
|
+
size?: number;
|
|
134
|
+
color?: string;
|
|
135
|
+
}
|
|
136
|
+
declare const BuiltInIcon: React.FC<BuiltInIconProps>;
|
|
137
|
+
|
|
138
|
+
declare const COLORS: Record<FlashMessageType, {
|
|
139
|
+
background: string;
|
|
140
|
+
text: string;
|
|
141
|
+
icon: string;
|
|
142
|
+
}>;
|
|
143
|
+
declare const styles: {
|
|
144
|
+
rootOverlay: {
|
|
145
|
+
position: "absolute";
|
|
146
|
+
left: number;
|
|
147
|
+
right: number;
|
|
148
|
+
zIndex: number;
|
|
149
|
+
elevation: number;
|
|
150
|
+
};
|
|
151
|
+
rootTop: {
|
|
152
|
+
top: number;
|
|
153
|
+
};
|
|
154
|
+
rootBottom: {
|
|
155
|
+
bottom: number;
|
|
156
|
+
};
|
|
157
|
+
rootCenter: {
|
|
158
|
+
top: number;
|
|
159
|
+
bottom: number;
|
|
160
|
+
justifyContent: "center";
|
|
161
|
+
alignItems: "center";
|
|
162
|
+
};
|
|
163
|
+
toastContainer: any;
|
|
164
|
+
floatingContainer: {
|
|
165
|
+
marginHorizontal: number;
|
|
166
|
+
borderRadius: number;
|
|
167
|
+
borderWidth: number;
|
|
168
|
+
borderColor: string;
|
|
169
|
+
};
|
|
170
|
+
edgeToEdgeContainer: {
|
|
171
|
+
marginHorizontal: number;
|
|
172
|
+
borderRadius: number;
|
|
173
|
+
};
|
|
174
|
+
contentWrapper: {
|
|
175
|
+
flex: number;
|
|
176
|
+
flexDirection: "row";
|
|
177
|
+
alignItems: "center";
|
|
178
|
+
paddingVertical: number;
|
|
179
|
+
paddingHorizontal: number;
|
|
180
|
+
};
|
|
181
|
+
iconContainer: {
|
|
182
|
+
marginRight: number;
|
|
183
|
+
justifyContent: "center";
|
|
184
|
+
alignItems: "center";
|
|
185
|
+
};
|
|
186
|
+
textContainer: {
|
|
187
|
+
flex: number;
|
|
188
|
+
justifyContent: "center";
|
|
189
|
+
};
|
|
190
|
+
titleText: {
|
|
191
|
+
fontSize: number;
|
|
192
|
+
fontWeight: "600";
|
|
193
|
+
letterSpacing: number;
|
|
194
|
+
color: string;
|
|
195
|
+
};
|
|
196
|
+
descriptionText: {
|
|
197
|
+
fontSize: number;
|
|
198
|
+
fontWeight: "400";
|
|
199
|
+
color: string;
|
|
200
|
+
marginTop: number;
|
|
201
|
+
lineHeight: number;
|
|
202
|
+
};
|
|
203
|
+
actionButton: {
|
|
204
|
+
marginLeft: number;
|
|
205
|
+
paddingHorizontal: number;
|
|
206
|
+
paddingVertical: number;
|
|
207
|
+
borderRadius: number;
|
|
208
|
+
backgroundColor: string;
|
|
209
|
+
};
|
|
210
|
+
actionButtonText: {
|
|
211
|
+
fontSize: number;
|
|
212
|
+
fontWeight: "700";
|
|
213
|
+
color: string;
|
|
214
|
+
};
|
|
215
|
+
progressBarContainer: {
|
|
216
|
+
position: "absolute";
|
|
217
|
+
bottom: number;
|
|
218
|
+
left: number;
|
|
219
|
+
right: number;
|
|
220
|
+
height: number;
|
|
221
|
+
backgroundColor: string;
|
|
222
|
+
};
|
|
223
|
+
progressBarFill: {
|
|
224
|
+
height: "100%";
|
|
225
|
+
backgroundColor: string;
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
export = FlashMessage;
|
|
231
|
+
export { BuiltInIcon, COLORS, FlashMessage, type FlashMessageAction, type FlashMessageContainerProps, type FlashMessageIcon, type FlashMessageOptions, type FlashMessagePosition, FlashMessageProvider, type FlashMessageRef, type FlashMessageTransition, type FlashMessageType, dismissFlash, flash, flashManager, hideMessage, showMessage, styles, useFlashMessage };
|