index.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {
  2. type FC
  3. } from "react";
  4. import {
  5. ScrollView,
  6. View
  7. } from "react-native";
  8. import type IPageContainerProps from "./type";
  9. import stylesheet from "./stylesheet";
  10. import {
  11. NCoreUIKitTheme
  12. } from "../../core/hooks";
  13. const PageContainer: FC<IPageContainerProps> = ({
  14. backgroundColor = "default" as keyof NCoreUIKit.ContainerContentColors,
  15. isScrollable = false,
  16. scrollViewStyle,
  17. scrollViewProps,
  18. children,
  19. style,
  20. ...props
  21. }) => {
  22. const {
  23. spaces
  24. } = NCoreUIKitTheme.useContext();
  25. const renderScrollview = () => {
  26. if(style) {
  27. console.log("Hey!. You make wrong things. If you must be use isScrollable={true}, you must be use scrollViewStyle. Do not use style prop for this case.");
  28. }
  29. if(props) {
  30. console.log("Hey!. You make wrong things. If you must be use isScrollable={true}, you must be use scrollViewProps. Do not use default view props for this case.");
  31. }
  32. return <ScrollView
  33. {...scrollViewProps}
  34. contentContainerStyle={[
  35. {
  36. padding: spaces.spacingMd
  37. },
  38. scrollViewProps?.contentContainerStyle
  39. ]}
  40. style={[
  41. {
  42. backgroundColor: backgroundColor
  43. },
  44. stylesheet.container,
  45. scrollViewStyle
  46. ]}
  47. >
  48. {children}
  49. </ScrollView>;
  50. };
  51. const renderView = () => {
  52. if(scrollViewStyle) {
  53. console.log("Hey!. You make wrong things. If you must be use isScrollable={false}, you must be use style. Do not use scrollViewStyle prop for this case.");
  54. }
  55. if(scrollViewProps) {
  56. console.log("Hey!. You make wrong things. If you must be use isScrollable={false}, you musn't use scrollViewProps.");
  57. }
  58. return <View
  59. {...props}
  60. style={[
  61. {
  62. backgroundColor: backgroundColor,
  63. padding: spaces.spacingMd
  64. },
  65. stylesheet.container,
  66. style
  67. ]}
  68. >
  69. {children}
  70. </View>;
  71. };
  72. return isScrollable ? renderScrollview() : renderView();
  73. };
  74. export default PageContainer;