2019-12-04 19:38:19 +05:00
|
|
|
import React, {useEffect, useState, createRef} from 'react';
|
2019-12-09 13:17:40 +05:00
|
|
|
import {View, Text, TouchableOpacity, Modal} from 'react-native';
|
2019-12-04 19:38:19 +05:00
|
|
|
import NavigationService from '../../services/NavigationService';
|
2019-12-09 13:17:40 +05:00
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
import {
|
|
|
|
|
COLOR_SCHEME,
|
|
|
|
|
SIZE,
|
|
|
|
|
br,
|
|
|
|
|
ph,
|
|
|
|
|
pv,
|
|
|
|
|
opacity,
|
|
|
|
|
FONT,
|
|
|
|
|
WEIGHT,
|
|
|
|
|
} from '../../common/common';
|
|
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
2019-12-11 15:20:18 +05:00
|
|
|
import {getElevation} from '../../utils/utils';
|
2019-12-14 19:26:44 +05:00
|
|
|
import {useAppContext} from '../../provider/useAppContext';
|
2020-01-17 00:23:16 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2019-12-04 19:38:19 +05:00
|
|
|
|
|
|
|
|
export const Dialog = ({
|
|
|
|
|
title,
|
|
|
|
|
paragraph = null,
|
|
|
|
|
positiveText = 'Ok',
|
|
|
|
|
negativeText = 'Cancel',
|
|
|
|
|
icon = null,
|
|
|
|
|
visible,
|
|
|
|
|
close = () => {},
|
|
|
|
|
positivePress = () => {},
|
|
|
|
|
}) => {
|
2020-01-17 00:23:16 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const {colors} = state;
|
2019-12-04 19:38:19 +05:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
visible={visible}
|
|
|
|
|
transparent={true}
|
2019-12-09 13:17:40 +05:00
|
|
|
animated
|
|
|
|
|
animationType="fade"
|
2019-12-04 19:38:19 +05:00
|
|
|
onRequestClose={() => (refs = [])}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2020-01-08 22:47:49 +05:00
|
|
|
backgroundColor: 'rgba(0,0,0,0.3)',
|
2019-12-04 19:38:19 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-01-08 22:47:49 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={() => close()}
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2019-12-04 19:38:19 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2019-12-11 15:20:18 +05:00
|
|
|
...getElevation(5),
|
2019-12-04 19:38:19 +05:00
|
|
|
width: '80%',
|
|
|
|
|
maxHeight: 350,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
{icon ? (
|
|
|
|
|
<Icon name={icon} color={colors.accent} size={SIZE.lg} />
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
2019-12-14 16:00:16 +05:00
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
marginLeft: 5,
|
2020-01-07 11:12:55 +05:00
|
|
|
fontSize: SIZE.md,
|
2019-12-04 19:38:19 +05:00
|
|
|
}}>
|
|
|
|
|
{title}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
{paragraph ? (
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
2019-12-14 16:00:16 +05:00
|
|
|
fontSize: SIZE.sm - 2,
|
2019-12-04 19:38:19 +05:00
|
|
|
textAlign: 'center',
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
}}>
|
|
|
|
|
{paragraph}
|
|
|
|
|
</Text>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
}}>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={() => positivePress()}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '48%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
{positiveText}
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={() => close()}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '48%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2019-12-07 12:05:15 +05:00
|
|
|
backgroundColor: colors.nav,
|
2019-12-04 19:38:19 +05:00
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
{negativeText}
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|