2020-11-17 09:43:38 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-05-18 04:17:00 +02:00
|
|
|
import { StyleSheet, Platform, useWindowDimensions, View } from 'react-native';
|
2020-11-17 09:43:38 +01:00
|
|
|
import Modal from 'react-native-modal';
|
2021-11-16 17:40:01 +01:00
|
|
|
import { BlueButton, BlueSpacing10 } from '../BlueComponents';
|
2021-05-18 04:17:00 +02:00
|
|
|
import loc from '../loc';
|
2023-10-24 03:28:44 +02:00
|
|
|
import { useTheme } from './themes';
|
2020-11-17 09:43:38 +01:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
margin: 0,
|
|
|
|
},
|
2021-05-18 04:17:00 +02:00
|
|
|
hasDoneButton: {
|
|
|
|
padding: 16,
|
|
|
|
paddingBottom: 24,
|
|
|
|
},
|
2020-11-17 09:43:38 +01:00
|
|
|
});
|
|
|
|
|
2021-09-09 13:00:11 +02:00
|
|
|
const BottomModal = ({
|
|
|
|
onBackButtonPress = undefined,
|
|
|
|
onBackdropPress = undefined,
|
2021-09-30 13:33:50 +02:00
|
|
|
onClose,
|
2021-09-09 13:00:11 +02:00
|
|
|
windowHeight = undefined,
|
|
|
|
windowWidth = undefined,
|
|
|
|
doneButton = undefined,
|
|
|
|
avoidKeyboard = false,
|
|
|
|
allowBackdropPress = true,
|
|
|
|
...props
|
|
|
|
}) => {
|
2020-11-17 09:43:38 +01:00
|
|
|
const valueWindowHeight = useWindowDimensions().height;
|
|
|
|
const valueWindowWidth = useWindowDimensions().width;
|
|
|
|
const handleBackButtonPress = onBackButtonPress ?? onClose;
|
2021-09-09 13:00:11 +02:00
|
|
|
const handleBackdropPress = allowBackdropPress ? onBackdropPress ?? onClose : undefined;
|
2021-05-18 04:17:00 +02:00
|
|
|
const { colors } = useTheme();
|
|
|
|
const stylesHook = StyleSheet.create({
|
|
|
|
hasDoneButton: {
|
|
|
|
backgroundColor: colors.elevated,
|
|
|
|
},
|
|
|
|
});
|
2020-11-17 09:43:38 +01:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
style={styles.root}
|
|
|
|
deviceHeight={windowHeight ?? valueWindowHeight}
|
|
|
|
deviceWidth={windowWidth ?? valueWindowWidth}
|
|
|
|
onBackButtonPress={handleBackButtonPress}
|
|
|
|
onBackdropPress={handleBackdropPress}
|
|
|
|
{...props}
|
2021-03-16 03:07:52 +01:00
|
|
|
accessibilityViewIsModal
|
2021-09-09 13:00:11 +02:00
|
|
|
avoidKeyboard={avoidKeyboard}
|
2021-05-18 04:17:00 +02:00
|
|
|
useNativeDriverForBackdrop={Platform.OS === 'android'}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
{doneButton && (
|
|
|
|
<View style={[styles.hasDoneButton, stylesHook.hasDoneButton]}>
|
|
|
|
<BlueButton title={loc.send.input_done} onPress={onClose} />
|
2021-11-16 17:40:01 +01:00
|
|
|
<BlueSpacing10 />
|
2021-05-18 04:17:00 +02:00
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</Modal>
|
2020-11-17 09:43:38 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
BottomModal.propTypes = {
|
|
|
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element), PropTypes.element]),
|
|
|
|
onBackButtonPress: PropTypes.func,
|
|
|
|
onBackdropPress: PropTypes.func,
|
|
|
|
onClose: PropTypes.func,
|
2021-05-18 04:18:39 +02:00
|
|
|
doneButton: PropTypes.bool,
|
2020-11-17 09:43:38 +01:00
|
|
|
windowHeight: PropTypes.number,
|
|
|
|
windowWidth: PropTypes.number,
|
2021-09-09 13:00:11 +02:00
|
|
|
avoidKeyboard: PropTypes.bool,
|
|
|
|
allowBackdropPress: PropTypes.bool,
|
2020-11-17 09:43:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default BottomModal;
|