80 lines
1.5 KiB
TypeScript
80 lines
1.5 KiB
TypeScript
import Toast from "react-native-toast-message";
|
|
|
|
export enum ToastType {
|
|
SUCCESS = "success",
|
|
ERROR = "error",
|
|
WARNING = "error", // react-native-toast-message không có 'warning', dùng 'error'
|
|
INFO = "info",
|
|
}
|
|
|
|
/**
|
|
* Success toast
|
|
*/
|
|
export const showToastSuccess = (message: string, title?: string): void => {
|
|
Toast.show({
|
|
type: "success",
|
|
text1: title || "Success",
|
|
text2: message,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Error toast
|
|
*/
|
|
export const showToastError = (message: string, title?: string): void => {
|
|
Toast.show({
|
|
type: ToastType.ERROR,
|
|
text1: title || ToastType.ERROR,
|
|
text2: message,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Info toast
|
|
*/
|
|
export const showToastInfo = (message: string, title?: string): void => {
|
|
Toast.show({
|
|
type: ToastType.INFO,
|
|
text1: title || ToastType.INFO,
|
|
text2: message,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Warning toast
|
|
*/
|
|
export const showToastWarning = (message: string, title?: string): void => {
|
|
Toast.show({
|
|
type: ToastType.WARNING,
|
|
text1: title || ToastType.WARNING,
|
|
text2: message,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Default toast
|
|
*/
|
|
export const showToastDefault = (message: string, title?: string): void => {
|
|
Toast.show({
|
|
type: ToastType.INFO,
|
|
text1: title || ToastType.INFO,
|
|
text2: message,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Custom toast với type tùy chọn
|
|
*/
|
|
export const show = (
|
|
message: string,
|
|
type: ToastType,
|
|
title?: string
|
|
): void => {
|
|
const titleText = title || type.charAt(0).toUpperCase() + type.slice(1);
|
|
Toast.show({
|
|
type,
|
|
text1: titleText,
|
|
text2: message,
|
|
});
|
|
};
|