index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import {
  2. useLayoutEffect,
  3. useState
  4. } from "react";
  5. import {
  6. View
  7. } from "react-native";
  8. import stylesheet from "./stylesheet";
  9. import {
  10. NCoreUIKitLocalize,
  11. NCoreUIKitTheme,
  12. PageContainer,
  13. CodeViewer,
  14. Header,
  15. Button,
  16. Modal,
  17. Text
  18. } from "ncore-ui-kit";
  19. import {
  20. useNavigation
  21. } from "@react-navigation/native";
  22. import type RootStackParamList from "../../../navigation/type";
  23. import type {
  24. NativeStackNavigationProp
  25. } from "@react-navigation/native-stack";
  26. const ModalPage = () => {
  27. const {
  28. localize
  29. } = NCoreUIKitLocalize.useContext();
  30. const {
  31. spaces
  32. } = NCoreUIKitTheme.useContext();
  33. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  34. const [
  35. isActive,
  36. setIsActive
  37. ] = useState<boolean>(false);
  38. useLayoutEffect(() => {
  39. navigation.setOptions({
  40. header: () => <Header
  41. title={localize("components-modal")}
  42. isWrapSafeareaContext={false}
  43. navigation={navigation}
  44. isGoBackEnable={true}
  45. />,
  46. headerShown: true
  47. });
  48. }, []);
  49. return <PageContainer
  50. scrollViewProps={{
  51. contentContainerStyle: stylesheet.scrollContent
  52. }}
  53. isWorkWithHeaderSpace={false}
  54. scrollViewStyle={[
  55. stylesheet.container
  56. ]}
  57. isScrollable={true}
  58. >
  59. <View
  60. style={[
  61. stylesheet.contentContainer
  62. ]}
  63. >
  64. <Text
  65. style={stylesheet.descText}
  66. variant="bodyMediumSize"
  67. color="mid"
  68. >
  69. {localize("modal-desc")}
  70. </Text>
  71. <Text
  72. variant="titleMediumSize"
  73. style={stylesheet.title}
  74. >
  75. {localize("components-modal")}
  76. </Text>
  77. <Button
  78. onPress={() => setIsActive(true)}
  79. spreadBehaviour="stretch"
  80. title="Open Modal"
  81. />
  82. <View
  83. style={{
  84. marginVertical: spaces.spacingMd
  85. }}
  86. >
  87. <Text
  88. style={{
  89. marginBottom: spaces.spacingSm
  90. }}
  91. variant="headlineSmallSize"
  92. >
  93. {localize("usage")}
  94. </Text>
  95. <CodeViewer
  96. code={"import {\n Modal\n} from \"ncore-ui-kit\";\n\n<Modal\n isActive={isActive}\n onOverlayPress={() => setIsActive(false)}\n>\n <View>\n <Text>Modal Content</Text>\n </View>\n</Modal>"}
  97. language="tsx"
  98. />
  99. </View>
  100. <Modal
  101. onOverlayPress={() => setIsActive(false)}
  102. isActive={isActive}
  103. id="example-modal"
  104. >
  105. <View
  106. style={stylesheet.modalContent}
  107. >
  108. <Text>
  109. This is an example modal content.
  110. </Text>
  111. <Button
  112. onPress={() => setIsActive(false)}
  113. spreadBehaviour="stretch"
  114. title="Close Modal"
  115. type="primary"
  116. />
  117. </View>
  118. </Modal>
  119. </View>
  120. </PageContainer>;
  121. };
  122. export default ModalPage;