Files
notesnook/apps/mobile/src/components/Dialog/index.js

147 lines
3.8 KiB
JavaScript
Raw Normal View History

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-04 19:38:19 +05:00
export const Dialog = ({
title,
paragraph = null,
positiveText = 'Ok',
negativeText = 'Cancel',
icon = null,
visible,
close = () => {},
positivePress = () => {},
}) => {
const [colors, setColors] = useState(COLOR_SCHEME);
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%',
backgroundColor: 'rgba(255,255,255,0.3)',
justifyContent: 'center',
alignItems: 'center',
}}>
<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,
fontSize: SIZE.md + 2,
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>
);
};