|
|
@ -1,8 +1,15 @@ |
|
|
|
import React, { useState } from "react" |
|
|
|
import React, { useState } from "react"; |
|
|
|
import AwesomeAlert from 'react-native-awesome-alerts'; |
|
|
|
import { Dimensions } from "react-native"; |
|
|
|
const ReactNative = require('react-native'); |
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
|
|
|
import AwesomeAlert from "react-native-awesome-alerts"; |
|
|
|
|
|
|
|
|
|
|
|
const AlertModal = props => { |
|
|
|
//style
|
|
|
|
|
|
|
|
import Colors from "../constants/Colors"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//variables
|
|
|
|
|
|
|
|
const { width } = Dimensions.get("window"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const AlertModal = (props) => { |
|
|
|
const [alert, setAlert] = useState({ |
|
|
|
const [alert, setAlert] = useState({ |
|
|
|
show: false, |
|
|
|
show: false, |
|
|
|
showProgress: false, |
|
|
|
showProgress: false, |
|
|
@ -15,12 +22,9 @@ const AlertModal = props => { |
|
|
|
cancelText: "بیخیال", |
|
|
|
cancelText: "بیخیال", |
|
|
|
confirmText: "باشه", |
|
|
|
confirmText: "باشه", |
|
|
|
confirmButtonColor: "#2980b9", |
|
|
|
confirmButtonColor: "#2980b9", |
|
|
|
onCancel: () => { |
|
|
|
onCancel: () => {}, |
|
|
|
}, |
|
|
|
onConfirm: () => {}, |
|
|
|
onConfirm: () => { |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
const [apiAlert, setApiAlert] = useState({ |
|
|
|
const [apiAlert, setApiAlert] = useState({ |
|
|
|
show: false, |
|
|
|
show: false, |
|
|
|
showProgress: false, |
|
|
|
showProgress: false, |
|
|
@ -33,55 +37,66 @@ const AlertModal = props => { |
|
|
|
cancelText: "بیخیال", |
|
|
|
cancelText: "بیخیال", |
|
|
|
confirmText: "باشه", |
|
|
|
confirmText: "باشه", |
|
|
|
confirmButtonColor: "#2980b9", |
|
|
|
confirmButtonColor: "#2980b9", |
|
|
|
onCancel: () => { |
|
|
|
onCancel: () => {}, |
|
|
|
}, |
|
|
|
onConfirm: () => {}, |
|
|
|
onConfirm: () => { |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global.globalAlert = (params) => { |
|
|
|
global.globalAlert = (params) => { |
|
|
|
setAlert({ |
|
|
|
setAlert({ |
|
|
|
...alert, |
|
|
|
...alert, |
|
|
|
...params |
|
|
|
...params, |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
global.globalApiAlert = (params) => { |
|
|
|
global.globalApiAlert = (params) => { |
|
|
|
|
|
|
|
|
|
|
|
setApiAlert({ |
|
|
|
setApiAlert({ |
|
|
|
...apiAlert, |
|
|
|
...apiAlert, |
|
|
|
...params |
|
|
|
...params, |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function hideAlert() { |
|
|
|
function hideAlert() { |
|
|
|
setAlert({ ...alert, show: false }) |
|
|
|
setAlert({ ...alert, show: false }); |
|
|
|
} |
|
|
|
} |
|
|
|
function onApiCancelPressed(){ |
|
|
|
function onApiCancelPressed() { |
|
|
|
globalApiAlert({ show: false }) |
|
|
|
globalApiAlert({ show: false }); |
|
|
|
|
|
|
|
|
|
|
|
apiAlert.onCancel() |
|
|
|
apiAlert.onCancel(); |
|
|
|
} |
|
|
|
} |
|
|
|
function onApiConfirmPressed(){ |
|
|
|
function onApiConfirmPressed() { |
|
|
|
globalApiAlert({ show: false }) |
|
|
|
globalApiAlert({ show: false }); |
|
|
|
apiAlert.onConfirm() |
|
|
|
apiAlert.onConfirm(); |
|
|
|
} |
|
|
|
} |
|
|
|
function onCancelPressed(){ |
|
|
|
function onCancelPressed() { |
|
|
|
hideAlert() |
|
|
|
hideAlert(); |
|
|
|
alert.onCancel() |
|
|
|
alert.onCancel(); |
|
|
|
} |
|
|
|
} |
|
|
|
function onConfirmPressed(){ |
|
|
|
function onConfirmPressed() { |
|
|
|
hideAlert() |
|
|
|
hideAlert(); |
|
|
|
alert.onConfirm() |
|
|
|
alert.onConfirm(); |
|
|
|
} |
|
|
|
} |
|
|
|
return <> |
|
|
|
return ( |
|
|
|
|
|
|
|
<> |
|
|
|
<AwesomeAlert |
|
|
|
<AwesomeAlert |
|
|
|
show={alert.show} |
|
|
|
show={alert.show} |
|
|
|
progressColor="red" |
|
|
|
progressColor="red" |
|
|
|
showProgress={alert.showProgress} |
|
|
|
showProgress={alert.showProgress} |
|
|
|
title={alert.title} |
|
|
|
title={alert.title} |
|
|
|
titleStyle={{ fontFamily : 'bold' }} |
|
|
|
titleStyle={{ |
|
|
|
|
|
|
|
fontFamily: "bold", |
|
|
|
|
|
|
|
color: |
|
|
|
|
|
|
|
props.theme === "light" |
|
|
|
|
|
|
|
? Colors.theme1.gray20 |
|
|
|
|
|
|
|
: Colors.theme1.white, |
|
|
|
|
|
|
|
}} |
|
|
|
message={alert.message} |
|
|
|
message={alert.message} |
|
|
|
messageStyle={{textAlign : 'right', fontFamily : 'regular'}} |
|
|
|
messageStyle={{ |
|
|
|
|
|
|
|
textAlign: "right", |
|
|
|
|
|
|
|
fontFamily: "regular", |
|
|
|
|
|
|
|
color: |
|
|
|
|
|
|
|
props.theme === "light" |
|
|
|
|
|
|
|
? Colors.theme1.gray20 |
|
|
|
|
|
|
|
: Colors.theme1.white, |
|
|
|
|
|
|
|
}} |
|
|
|
closeOnTouchOutside={alert.closeOnTouchOutside} |
|
|
|
closeOnTouchOutside={alert.closeOnTouchOutside} |
|
|
|
closeOnHardwareBackPress={alert.closeOnHardwareBackPress} |
|
|
|
closeOnHardwareBackPress={alert.closeOnHardwareBackPress} |
|
|
|
showCancelButton={alert.showCancelButton} |
|
|
|
showCancelButton={alert.showCancelButton} |
|
|
@ -90,33 +105,35 @@ const AlertModal = props => { |
|
|
|
confirmText={alert.confirmText} |
|
|
|
confirmText={alert.confirmText} |
|
|
|
confirmButtonColor={alert.confirmButtonColor} |
|
|
|
confirmButtonColor={alert.confirmButtonColor} |
|
|
|
onCancelPressed={onCancelPressed} |
|
|
|
onCancelPressed={onCancelPressed} |
|
|
|
onConfirmPressed={(onConfirmPressed)} |
|
|
|
onConfirmPressed={onConfirmPressed} |
|
|
|
cancelButtonTextStyle={{ |
|
|
|
cancelButtonTextStyle={{ |
|
|
|
color : '#777', |
|
|
|
color: props.theme === "light" ? "#777" : Colors.theme1.grayE3, |
|
|
|
fontFamily : 'regular', |
|
|
|
fontFamily: "regular", |
|
|
|
}} |
|
|
|
}} |
|
|
|
confirmButtonTextStyle={{ |
|
|
|
confirmButtonTextStyle={{ |
|
|
|
fontFamily : 'regular', |
|
|
|
fontFamily: "regular", |
|
|
|
|
|
|
|
|
|
|
|
}} |
|
|
|
}} |
|
|
|
contentStyle={{ |
|
|
|
contentStyle={{ |
|
|
|
width: ReactNative.Dimensions.get('window').width / 1.5, |
|
|
|
width: width / 1.5, |
|
|
|
}} |
|
|
|
}} |
|
|
|
cancelButtonStyle={{ |
|
|
|
cancelButtonStyle={{ |
|
|
|
fontFamily : 'regular', |
|
|
|
fontFamily: "regular", |
|
|
|
borderColor : "#777", |
|
|
|
borderColor: props.theme === "light" ? "#777" : Colors.theme1.grayE3, |
|
|
|
borderWidth : 1, |
|
|
|
borderWidth: 1, |
|
|
|
backgroundColor : 'white', |
|
|
|
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, |
|
|
|
}} |
|
|
|
}} |
|
|
|
confirmButtonStyle={ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
|
|
justifyContent: 'center', |
|
|
|
|
|
|
|
fontFamily : 'regular', |
|
|
|
|
|
|
|
borderColor : "#2980b9", |
|
|
|
|
|
|
|
borderWidth : 1, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
useNativeDriver={true} |
|
|
|
useNativeDriver={true} |
|
|
|
/> |
|
|
|
/> |
|
|
|
<AwesomeAlert |
|
|
|
<AwesomeAlert |
|
|
@ -133,21 +150,23 @@ const AlertModal = props => { |
|
|
|
confirmText={apiAlert.confirmText} |
|
|
|
confirmText={apiAlert.confirmText} |
|
|
|
confirmButtonColor={apiAlert.confirmButtonColor} |
|
|
|
confirmButtonColor={apiAlert.confirmButtonColor} |
|
|
|
onCancelPressed={onApiCancelPressed} |
|
|
|
onCancelPressed={onApiCancelPressed} |
|
|
|
onConfirmPressed={(onApiConfirmPressed)} |
|
|
|
onConfirmPressed={onApiConfirmPressed} |
|
|
|
contentStyle={{ |
|
|
|
contentStyle={{ |
|
|
|
width: ReactNative.Dimensions.get('window').width / 1.5 |
|
|
|
width: width / 1.5, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
confirmButtonStyle={{ |
|
|
|
|
|
|
|
width: width / 4, |
|
|
|
|
|
|
|
alignItems: "center", |
|
|
|
|
|
|
|
justifyContent: "center", |
|
|
|
}} |
|
|
|
}} |
|
|
|
confirmButtonStyle={ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
width: ReactNative.Dimensions.get('window').width / 4, |
|
|
|
|
|
|
|
alignItems: 'center', |
|
|
|
|
|
|
|
justifyContent: 'center' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
useNativeDriver={true} |
|
|
|
useNativeDriver={true} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</> |
|
|
|
</> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
|
|
|
|
theme: state.publicApi.theme, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export default AlertModal; |
|
|
|
export default connect(mapStateToProps)(AlertModal); |
|
|
|