initial: add login
This commit is contained in:
79
config/toast.ts
Normal file
79
config/toast.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
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,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user