thêm toast, thêm logic cho phần ButtonCreateNewHaulOrTrip
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
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,
|
||||
});
|
||||
};
|
||||
214
config/toast.tsx
Normal file
214
config/toast.tsx
Normal file
@@ -0,0 +1,214 @@
|
||||
import { MaterialIcons } from "@expo/vector-icons";
|
||||
import { View } from "react-native";
|
||||
import {
|
||||
BaseToast,
|
||||
BaseToastProps,
|
||||
SuccessToast,
|
||||
} from "react-native-toast-message";
|
||||
|
||||
export const Colors: any = {
|
||||
light: {
|
||||
text: "#000",
|
||||
back: "#ffffff",
|
||||
},
|
||||
dark: {
|
||||
text: "#ffffff",
|
||||
back: "#2B2D2E",
|
||||
},
|
||||
default: "#3498db",
|
||||
info: "#3498db",
|
||||
success: "#07bc0c",
|
||||
warn: {
|
||||
background: "#ffffff",
|
||||
text: "black",
|
||||
iconColor: "#f1c40f",
|
||||
},
|
||||
error: {
|
||||
background: "#ffffff",
|
||||
text: "black",
|
||||
iconColor: "#e74c3c",
|
||||
},
|
||||
textDefault: "#4c4c4c",
|
||||
textDark: "black",
|
||||
};
|
||||
|
||||
export const toastConfig = {
|
||||
success: (props: BaseToastProps) => (
|
||||
<SuccessToast
|
||||
{...props}
|
||||
style={{
|
||||
borderLeftColor: Colors.success,
|
||||
backgroundColor: Colors.success,
|
||||
borderRadius: 10,
|
||||
}}
|
||||
contentContainerStyle={{
|
||||
paddingHorizontal: 10,
|
||||
}}
|
||||
text1Style={{
|
||||
color: "white",
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
text2Style={{
|
||||
color: "#f0f0f0",
|
||||
}}
|
||||
renderLeadingIcon={() => (
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: 40,
|
||||
height: "100%",
|
||||
}}
|
||||
>
|
||||
<MaterialIcons name="check-circle" size={30} color="white" />
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
),
|
||||
default: (props: BaseToastProps) => (
|
||||
<BaseToast
|
||||
{...props}
|
||||
style={{
|
||||
borderLeftColor: Colors.default,
|
||||
backgroundColor: Colors.default,
|
||||
borderRadius: 10,
|
||||
}}
|
||||
contentContainerStyle={{
|
||||
paddingHorizontal: 10,
|
||||
}}
|
||||
text1Style={{
|
||||
color: "white",
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
text2Style={{
|
||||
color: "#f0f0f0",
|
||||
}}
|
||||
renderLeadingIcon={() => (
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: 50,
|
||||
height: "100%",
|
||||
}}
|
||||
>
|
||||
<MaterialIcons name="info" size={30} color="white" />
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
),
|
||||
info: (props: BaseToastProps) => (
|
||||
<BaseToast
|
||||
{...props}
|
||||
style={{
|
||||
borderLeftColor: Colors.info,
|
||||
backgroundColor: Colors.info,
|
||||
borderRadius: 10,
|
||||
}}
|
||||
contentContainerStyle={{
|
||||
paddingHorizontal: 10,
|
||||
}}
|
||||
text1Style={{
|
||||
color: "white",
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
text2Style={{
|
||||
color: "#f0f0f0",
|
||||
}}
|
||||
renderLeadingIcon={() => (
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: 50,
|
||||
height: "100%",
|
||||
}}
|
||||
>
|
||||
<MaterialIcons name="info-outline" size={30} color="white" />
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
),
|
||||
warn: (props: BaseToastProps) => (
|
||||
<BaseToast
|
||||
{...props}
|
||||
style={{
|
||||
borderLeftColor: Colors.warn.background,
|
||||
backgroundColor: Colors.warn.background,
|
||||
borderRadius: 10,
|
||||
}}
|
||||
contentContainerStyle={{
|
||||
paddingHorizontal: 10,
|
||||
}}
|
||||
text1Style={{
|
||||
color: Colors.warn.text,
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
text2Style={{
|
||||
color: "#333",
|
||||
}}
|
||||
renderLeadingIcon={() => (
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: 50,
|
||||
height: "100%",
|
||||
}}
|
||||
>
|
||||
<MaterialIcons
|
||||
name="warning"
|
||||
size={30}
|
||||
color={Colors.warn.iconColor}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
),
|
||||
error: (props: BaseToastProps) => (
|
||||
<BaseToast
|
||||
{...props}
|
||||
style={{
|
||||
borderLeftColor: Colors.error.background,
|
||||
backgroundColor: Colors.error.background,
|
||||
borderRadius: 10,
|
||||
}}
|
||||
contentContainerStyle={{
|
||||
paddingHorizontal: 10,
|
||||
}}
|
||||
text1Style={{
|
||||
color: Colors.error.text,
|
||||
fontSize: 16,
|
||||
fontWeight: "600",
|
||||
}}
|
||||
text2Style={{
|
||||
color: "#f0f0f0",
|
||||
}}
|
||||
renderLeadingIcon={() => (
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: 50,
|
||||
height: "100%",
|
||||
}}
|
||||
>
|
||||
<MaterialIcons
|
||||
name="error"
|
||||
size={30}
|
||||
color={Colors.error.iconColor}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
),
|
||||
};
|
||||
Reference in New Issue
Block a user