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.
141 lines
3.7 KiB
141 lines
3.7 KiB
import React, { useState } from "react" |
|
import AwesomeAlert from 'react-native-awesome-alerts'; |
|
const ReactNative = require('react-native'); |
|
|
|
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 : 'bold' }} |
|
message={alert.message} |
|
messageStyle={{textAlign : 'right', fontFamily : 'regular'}} |
|
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)} |
|
contentStyle={{ |
|
width: ReactNative.Dimensions.get('window').width / 1.5, |
|
}} |
|
cancelButtonStyle={{ |
|
fontFamily : 'regular', |
|
}} |
|
confirmButtonStyle={ |
|
{ |
|
width: ReactNative.Dimensions.get('window').width / 4, |
|
alignItems: 'center', |
|
justifyContent: 'center', |
|
fontFamily : 'regular' |
|
} |
|
} |
|
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: ReactNative.Dimensions.get('window').width / 1.5 |
|
}} |
|
confirmButtonStyle={ |
|
{ |
|
width: ReactNative.Dimensions.get('window').width / 4, |
|
alignItems: 'center', |
|
justifyContent: 'center' |
|
} |
|
} |
|
useNativeDriver={true} |
|
/> |
|
</> |
|
|
|
} |
|
|
|
export default AlertModal;
|
|
|