index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import {
  2. useLayoutEffect
  3. } from "react";
  4. import {
  5. View
  6. } from "react-native";
  7. import stylesheet from "./stylesheet";
  8. import {
  9. NCoreUIKitLocalize,
  10. NCoreUIKitTheme,
  11. SystemToolbar,
  12. PageContainer,
  13. CodeViewer,
  14. Header,
  15. Text
  16. } from "ncore-ui-kit";
  17. import {
  18. useNavigation
  19. } from "@react-navigation/native";
  20. import type RootStackParamList from "../../../navigation/type";
  21. import type {
  22. NativeStackNavigationProp
  23. } from "@react-navigation/native-stack";
  24. import {
  25. SettingsIcon,
  26. LogOutIcon,
  27. UserIcon,
  28. MenuIcon,
  29. HomeIcon
  30. } from "lucide-react-native";
  31. const SystemToolbarPage = () => {
  32. const {
  33. radiuses,
  34. borders,
  35. spaces,
  36. colors
  37. } = NCoreUIKitTheme.useContext();
  38. const {
  39. localize
  40. } = NCoreUIKitLocalize.useContext();
  41. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  42. useLayoutEffect(() => {
  43. navigation.setOptions({
  44. header: () => <Header
  45. title={localize("systemToolbar-title")}
  46. isWrapSafeareaContext={false}
  47. navigation={navigation}
  48. isGoBackEnable={true}
  49. />,
  50. headerShown: true
  51. });
  52. }, [
  53. navigation,
  54. localize
  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("systemToolbar-desc")}
  77. </Text>
  78. <View
  79. style={[
  80. stylesheet.previewContainer,
  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. <SystemToolbar
  91. actions={[
  92. {
  93. onPress: () => console.log("Settings pressed"),
  94. icon: ({
  95. color,
  96. size
  97. }) => <SettingsIcon
  98. color={colors.content.icon[color]}
  99. size={size}
  100. />,
  101. titleKey: "menu-settings"
  102. },
  103. {
  104. content: [
  105. {
  106. icon: ({
  107. color,
  108. size
  109. }) => <HomeIcon
  110. color={colors.content.icon[color]}
  111. size={size}
  112. />,
  113. onPress: () => console.log("Home"),
  114. titleKey: "menu-home"
  115. },
  116. {
  117. icon: ({
  118. color,
  119. size
  120. }) => <LogOutIcon
  121. color={colors.content.icon[color]}
  122. size={size}
  123. />,
  124. onPress: () => console.log("Logout"),
  125. titleKey: "close"
  126. }
  127. ],
  128. icon: ({
  129. color,
  130. size
  131. }) => <UserIcon
  132. color={colors.content.icon[color]}
  133. size={size}
  134. />,
  135. titleKey: "avatar-title"
  136. }
  137. ]}
  138. icon={({
  139. color,
  140. size
  141. }) => <MenuIcon
  142. color={colors.content.icon[color]}
  143. size={size}
  144. />}
  145. titleKey="menu-title"
  146. />
  147. </View>
  148. <View
  149. style={{
  150. marginBottom: spaces.spacingMd
  151. }}
  152. >
  153. <Text
  154. style={{
  155. marginBottom: spaces.spacingSm
  156. }}
  157. variant="headlineSmallSize"
  158. >
  159. {localize("usage")}
  160. </Text>
  161. <CodeViewer
  162. code={"import {\n SystemToolbar\n} from \"ncore-ui-kit\";\nimport {\n Settings,\n User,\n LogOut,\n Menu,\n Home\n} from \"lucide-react-native\";\n\n<SystemToolbar\n titleKey=\"menu\"\n icon={({ color, size }) => <Menu color={colors.content.icon[color]} size={size} />}\n actions={[\n {\n titleKey: \"menu-settings\",\n icon: ({ color, size }) => <Settings color={colors.content.icon[color]} size={size} />,\n onPress: () => console.log(\"Settings pressed\")\n }\n ]}\n/>"}
  163. language="tsx"
  164. />
  165. </View>
  166. </View>
  167. </PageContainer>;
  168. };
  169. export default SystemToolbarPage;