index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. TextInput,
  15. Header,
  16. Switch,
  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 HeaderPage = () => {
  27. const {
  28. radiuses,
  29. borders,
  30. spaces,
  31. colors
  32. } = NCoreUIKitTheme.useContext();
  33. const {
  34. localize
  35. } = NCoreUIKitLocalize.useContext();
  36. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  37. const [
  38. title,
  39. setTitle
  40. ] = useState<string>("Header Example");
  41. const [
  42. isGoBackEnable,
  43. setIsGoBackEnable
  44. ] = useState<boolean>(true);
  45. useLayoutEffect(() => {
  46. navigation.setOptions({
  47. header: () => <Header
  48. title={localize("header-title")}
  49. isWrapSafeareaContext={false}
  50. navigation={navigation}
  51. isGoBackEnable={true}
  52. />,
  53. headerShown: true
  54. });
  55. }, []);
  56. return <PageContainer
  57. scrollViewProps={{
  58. contentContainerStyle: stylesheet.scrollContent
  59. }}
  60. isWorkWithHeaderSpace={false}
  61. scrollViewStyle={[
  62. stylesheet.container
  63. ]}
  64. isScrollable={true}
  65. >
  66. <View
  67. style={[
  68. stylesheet.contentContainer
  69. ]}
  70. >
  71. <Text
  72. style={stylesheet.marginContainer}
  73. variant="bodyMediumSize"
  74. color="mid"
  75. >
  76. {localize("header-desc")}
  77. </Text>
  78. <View
  79. style={[
  80. stylesheet.paddedMarginContainer,
  81. {
  82. borderColor: colors.content.border.subtle,
  83. marginBottom: spaces.spacingMd,
  84. borderRadius: radiuses.form,
  85. borderWidth: borders.line,
  86. padding: spaces.spacingMd
  87. }
  88. ]}
  89. >
  90. <Header
  91. isGoBackEnable={isGoBackEnable}
  92. isWrapSafeareaContext={false}
  93. navigation={navigation}
  94. title={title}
  95. />
  96. </View>
  97. <View
  98. style={{
  99. marginBottom: spaces.spacingMd
  100. }}
  101. >
  102. <Text
  103. style={{
  104. marginBottom: spaces.spacingSm
  105. }}
  106. variant="headlineSmallSize"
  107. >
  108. {localize("usage")}
  109. </Text>
  110. <CodeViewer
  111. code={"import {\n Header\n} from \"ncore-ui-kit\";\n\n<Header\n title=\"Header Example\"\n isGoBackEnable={true}\n/>"}
  112. language="tsx"
  113. />
  114. </View>
  115. <TextInput
  116. placeholder={localize("header-enterTitle")}
  117. title={localize("header-titleLabel")}
  118. style={{
  119. marginBottom: spaces.spacingMd
  120. }}
  121. spreadBehaviour="stretch"
  122. onChangeText={setTitle}
  123. value={title}
  124. />
  125. <View
  126. style={stylesheet.rowSpaceBetween}
  127. >
  128. <Switch
  129. onPress={() => setIsGoBackEnable(!isGoBackEnable)}
  130. title={localize("header-toggleGoBack")}
  131. isActive={isGoBackEnable}
  132. spreadBehaviour="free"
  133. />
  134. </View>
  135. </View>
  136. </PageContainer>;
  137. };
  138. export default HeaderPage;