You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

175 lines
4.8 KiB

import React, { useState } from "react";
import { Dimensions } from "react-native";
import { connect } from "react-redux";
import AwesomeAlert from "react-native-awesome-alerts";
//style
import Colors from "../constants/Colors";
//variables
const { width } = Dimensions.get("window");
const AlertModal = (props) => {
const [alert, setAlert] = useState({
show: false,
showProgress: false,
title: "خطا",
message: "خطای ناشناخته",
closeOnTouchOutside: false,
closeOnHardwareBackPress: false,
showCancelButton: true,
showConfirmButton: true,
cancelText: "بیخیال",
confirmText: "باشه",
confirmButtonColor: "#2980b9",
onCancel: () => {},
onConfirm: () => {},
});
const [apiAlert, setApiAlert] = useState({
show: false,
showProgress: false,
title: "خطا",
message: "خطای ناشناخته",
closeOnTouchOutside: false,
closeOnHardwareBackPress: false,
showCancelButton: true,
showConfirmButton: true,
cancelText: "بیخیال",
confirmText: "باشه",
confirmButtonColor: "#2980b9",
onCancel: () => {},
onConfirm: () => {},
});
global.globalAlert = (params) => {
setAlert({
...alert,
...params,
});
};
global.globalApiAlert = (params) => {
setApiAlert({
...apiAlert,
...params,
});
};
function hideAlert() {
setAlert({ ...alert, show: false });
}
function onApiCancelPressed() {
globalApiAlert({ show: false });
apiAlert.onCancel();
}
function onApiConfirmPressed() {
globalApiAlert({ show: false });
apiAlert.onConfirm();
}
function onCancelPressed() {
hideAlert();
alert.onCancel();
}
function onConfirmPressed() {
hideAlert();
alert.onConfirm();
}
return (
<>
<AwesomeAlert
show={alert.show}
progressColor="red"
showProgress={alert.showProgress}
title={alert.title}
titleStyle={{
fontFamily: "Medium",
color:
props.theme === "light"
? Colors.theme1.gray20
: Colors.theme1.white,
}}
message={alert.message}
messageStyle={{
textAlign: "right",
fontFamily: "Regular",
color:
props.theme === "light"
? Colors.theme1.gray20
: Colors.theme1.white,
}}
overlayStyle={{
width : width,
}}
closeOnTouchOutside={alert.closeOnTouchOutside}
closeOnHardwareBackPress={alert.closeOnHardwareBackPress}
showCancelButton={alert.showCancelButton}
showConfirmButton={alert.showConfirmButton}
cancelText={alert.cancelText}
confirmText={alert.confirmText}
confirmButtonColor={alert.confirmButtonColor}
onCancelPressed={onCancelPressed}
onConfirmPressed={onConfirmPressed}
cancelButtonTextStyle={{
color: props.theme === "light" ? "#777" : Colors.theme1.grayE3,
fontFamily: "Regular",
}}
confirmButtonTextStyle={{
fontFamily: "Regular",
}}
contentStyle={{
width: width / 1.5,
}}
cancelButtonStyle={{
fontFamily: "Regular",
borderColor: props.theme === "light" ? "#777" : Colors.theme1.grayE3,
borderWidth: 1,
backgroundColor:
props.theme === "light" ? Colors.theme1.white : Colors.theme1.black,
}}
confirmButtonStyle={{
alignItems: "center",
justifyContent: "center",
fontFamily: "Regular",
borderColor: "#2980b9",
borderWidth: 1,
}}
contentContainerStyle={{
backgroundColor:
props.theme === "light" ? "white" : Colors.theme1.black,
}}
useNativeDriver={true}
/>
<AwesomeAlert
show={apiAlert.show}
progressColor="red"
showProgress={apiAlert.showProgress}
title={apiAlert.title}
message={apiAlert.message}
closeOnTouchOutside={apiAlert.closeOnTouchOutside}
closeOnHardwareBackPress={apiAlert.closeOnHardwareBackPress}
showCancelButton={apiAlert.showCancelButton}
showConfirmButton={apiAlert.showConfirmButton}
cancelText={apiAlert.cancelText}
confirmText={apiAlert.confirmText}
confirmButtonColor={apiAlert.confirmButtonColor}
onCancelPressed={onApiCancelPressed}
onConfirmPressed={onApiConfirmPressed}
contentStyle={{
width: width / 1.5,
}}
confirmButtonStyle={{
width: width / 4,
alignItems: "center",
justifyContent: "center",
}}
useNativeDriver={true}
/>
</>
);
};
const mapStateToProps = (state) => ({
theme: state.publicApi.theme,
});
export default connect(mapStateToProps)(AlertModal);