index.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. type FC
  3. } from "react";
  4. import {
  5. View
  6. } from "react-native";
  7. import type IBottomSheetProps from "./type";
  8. import stylesheet from "./stylesheet";
  9. import {
  10. NCoreUIKitTheme
  11. } from "../../core/hooks";
  12. import {
  13. SafeAreaView
  14. } from "react-native-safe-area-context";
  15. import Modal from "../modal";
  16. const BottomSheet: FC<IBottomSheetProps> = ({
  17. isWrapSafeareaContext = true,
  18. safeAreaViewBackgroundColor,
  19. backgroundColor = "default",
  20. safeAreaViewStyle,
  21. children,
  22. style,
  23. ...props
  24. }) => {
  25. const {
  26. colors,
  27. spaces
  28. } = NCoreUIKitTheme.useContext();
  29. const renderView = () => {
  30. return <View
  31. {...props}
  32. style={[
  33. {
  34. backgroundColor: colors.content.container[backgroundColor],
  35. padding: spaces.spacingMd
  36. },
  37. stylesheet.container,
  38. style
  39. ]}
  40. >
  41. {children}
  42. </View>;
  43. };
  44. const renderWithSafeareaView = () => {
  45. return <SafeAreaView
  46. style={[
  47. safeAreaViewStyle,
  48. {
  49. backgroundColor: safeAreaViewBackgroundColor ? colors.content.container[safeAreaViewBackgroundColor] : colors.content.container[backgroundColor]
  50. },
  51. stylesheet.safeAreaViewContainer
  52. ]}
  53. >
  54. {renderView()}
  55. </SafeAreaView>;
  56. };
  57. const renderSafeareaContext = () => {
  58. return isWrapSafeareaContext ? renderWithSafeareaView() : renderView();
  59. };
  60. return <Modal>
  61. {renderSafeareaContext()}
  62. </Modal>;
  63. };
  64. export default BottomSheet;