index.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { FC, ReactNode } from 'react';
  2. import {
  3. Dimensions,
  4. DimensionValue,
  5. Platform,
  6. StatusBar,
  7. View
  8. } from 'react-native';
  9. import ReactModal from 'react-native-modal';
  10. import { ModalHeader } from './ModalHeader/modal-header';
  11. import { styles } from './style';
  12. type Props = {
  13. children: ReactNode;
  14. visible: boolean;
  15. onRequestClose?: () => void;
  16. visibleInPercent?: DimensionValue;
  17. headerTitle: string;
  18. };
  19. export const Modal: FC<Props> = ({
  20. children,
  21. onRequestClose,
  22. visible,
  23. visibleInPercent,
  24. headerTitle
  25. }) => {
  26. const screenHeight = Dimensions.get('screen').height;
  27. const NOTCH_HEIGHT = 44;
  28. const statusBarHeight =
  29. Platform.OS === 'ios' ? StatusBar.currentHeight || NOTCH_HEIGHT : StatusBar.currentHeight || 0;
  30. const adjustedHeight = screenHeight - statusBarHeight;
  31. return (
  32. <ReactModal
  33. isVisible={visible}
  34. onBackdropPress={onRequestClose}
  35. onBackButtonPress={onRequestClose}
  36. style={styles.modal}
  37. statusBarTranslucent={true}
  38. presentationStyle="overFullScreen"
  39. >
  40. <View style={[styles.wrapper, { height: visibleInPercent ?? adjustedHeight }]}>
  41. <ModalHeader onRequestClose={onRequestClose} textHeader={headerTitle} />
  42. <Drawer />
  43. {children}
  44. </View>
  45. </ReactModal>
  46. );
  47. };
  48. const Drawer = () => {
  49. return <View style={styles.drawer} />;
  50. };