BlueWallet/components/BottomModal.tsx

83 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-11-17 09:43:38 +01:00
import React from 'react';
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';
2023-11-15 09:40:22 +01:00
import { 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';
2023-11-15 09:40:22 +01:00
import Button from './Button';
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
});
2024-02-10 05:35:24 +01:00
interface BottomModalProps {
children?: React.ReactNode;
onBackButtonPress?: () => void;
onBackdropPress?: () => void;
onClose: () => void;
windowHeight?: number;
windowWidth?: number;
doneButton?: boolean;
avoidKeyboard?: boolean;
allowBackdropPress?: boolean;
isVisible: boolean;
coverScreen?: boolean;
2024-02-10 05:35:24 +01:00
}
const BottomModal: React.FC<BottomModalProps> = ({
onBackButtonPress,
onBackdropPress,
2021-09-30 13:33:50 +02:00
onClose,
2024-02-10 05:35:24 +01:00
windowHeight,
windowWidth,
doneButton,
isVisible,
2021-09-09 13:00:11 +02:00
avoidKeyboard = false,
allowBackdropPress = true,
coverScreen = true,
2021-09-09 13:00:11 +02:00
...props
}) => {
2024-02-10 05:35:24 +01:00
const { height: valueWindowHeight, width: valueWindowWidth } = useWindowDimensions();
2020-11-17 09:43:38 +01:00
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,
},
});
2024-02-10 05:35:24 +01:00
2020-11-17 09:43:38 +01:00
return (
<Modal
style={styles.root}
deviceHeight={windowHeight ?? valueWindowHeight}
deviceWidth={windowWidth ?? valueWindowWidth}
onBackButtonPress={handleBackButtonPress}
onBackdropPress={handleBackdropPress}
2024-02-10 05:35:24 +01:00
isVisible={isVisible}
coverScreen={coverScreen}
2020-11-17 09:43:38 +01:00
{...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]}>
<Button title={loc.send.input_done} onPress={onClose} testID="ModalDoneButton" />
<BlueSpacing10 />
2021-05-18 04:17:00 +02:00
</View>
)}
</Modal>
2020-11-17 09:43:38 +01:00
);
};
export default BottomModal;