index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. scrollViewStyle={[stylesheet.container]}
  61. isWorkWithHeaderSpace={false}
  62. isScrollable={true}
  63. >
  64. <View
  65. style={[stylesheet.contentContainer]}
  66. >
  67. <Text
  68. variant="bodyMediumSize"
  69. color="mid"
  70. style={stylesheet.marginContainer}
  71. >
  72. {localize("header-desc")}
  73. </Text>
  74. <View
  75. style={[
  76. stylesheet.paddedMarginContainer,
  77. {
  78. borderColor: colors.content.border.subtle,
  79. marginBottom: spaces.spacingMd,
  80. borderRadius: radiuses.form,
  81. borderWidth: borders.line,
  82. padding: spaces.spacingMd
  83. }
  84. ]}
  85. >
  86. <Header
  87. isWrapSafeareaContext={false}
  88. isGoBackEnable={isGoBackEnable}
  89. navigation={navigation}
  90. title={title}
  91. />
  92. </View>
  93. <View
  94. style={{
  95. marginBottom: spaces.spacingMd
  96. }}
  97. >
  98. <Text
  99. variant="headlineSmallSize"
  100. style={{
  101. marginBottom: spaces.spacingSm
  102. }}
  103. >
  104. {localize("usage")}
  105. </Text>
  106. <CodeViewer
  107. code={"import {\n Header\n} from \"ncore-ui-kit\";\n\n<Header\n title=\"Header Example\"\n isGoBackEnable={true}\n/>"}
  108. language="tsx"
  109. />
  110. </View>
  111. <TextInput
  112. placeholder={localize("header-enterTitle")}
  113. title={localize("header-titleLabel")}
  114. style={{
  115. marginBottom: spaces.spacingMd
  116. }}
  117. spreadBehaviour="stretch"
  118. onChangeText={setTitle}
  119. value={title}
  120. />
  121. <View
  122. style={stylesheet.rowSpaceBetween}
  123. >
  124. <Switch
  125. onPress={() => setIsGoBackEnable(!isGoBackEnable)}
  126. title={localize("header-toggleGoBack")}
  127. isActive={isGoBackEnable}
  128. spreadBehaviour="free"
  129. />
  130. </View>
  131. </View>
  132. </PageContainer>;
  133. };
  134. export default HeaderPage;