index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. LocaleSwitcher,
  12. PageContainer,
  13. Button,
  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. ChevronRightIcon,
  26. ChevronLeftIcon
  27. } from "lucide-react-native";
  28. const LocaleExamples = () => {
  29. const {
  30. colors,
  31. spaces
  32. } = NCoreUIKitTheme.useContext();
  33. const {
  34. activeLocale,
  35. localize
  36. } = NCoreUIKitLocalize.useContext();
  37. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  38. useLayoutEffect(() => {
  39. navigation.setOptions({
  40. header: () => <Header
  41. navigation={navigation as unknown as NCoreUIKit.Navigation}
  42. title={localize("localeExamples-title")}
  43. isWrapSafeareaContext={false}
  44. isGoBackEnable={true}
  45. />,
  46. headerShown: true
  47. });
  48. }, [
  49. navigation,
  50. localize
  51. ]);
  52. return <PageContainer
  53. isWorkWithHeaderSpace={false}
  54. isScrollable={true}
  55. >
  56. <Text
  57. variant="headlineSmallSize"
  58. color="high"
  59. >
  60. {localize("localeExamples-title")}
  61. </Text>
  62. <Text
  63. color="mid"
  64. >
  65. {localize("localeExamples-desc")}
  66. </Text>
  67. <Text
  68. style={{
  69. marginBottom: spaces.spacingLg,
  70. marginTop: spaces.spacingXl
  71. }}
  72. variant="titleMediumSize"
  73. color="high"
  74. >
  75. {localize("localeExamples-languageSwitcher")}
  76. </Text>
  77. <View
  78. style={[
  79. stylesheet.rowContainer,
  80. {
  81. gap: spaces.spacingMd
  82. }
  83. ]}
  84. >
  85. <LocaleSwitcher/>
  86. </View>
  87. <View
  88. style={[
  89. stylesheet.borderedCard,
  90. {
  91. backgroundColor: colors.content.container.subtle,
  92. marginTop: spaces.spacingLg,
  93. padding: spaces.spacingLg
  94. }
  95. ]}
  96. >
  97. <Text
  98. style={{
  99. marginBottom: spaces.spacingMd
  100. }}
  101. variant="titleMediumSize"
  102. color="high"
  103. >
  104. {localize("localeExamples-localizedTexts")}
  105. </Text>
  106. <Text
  107. style={{
  108. marginBottom: spaces.spacingSm
  109. }}
  110. color="mid"
  111. >
  112. {localize("localeExamples-currentLanguage")}<Text
  113. variant="labelLargeSize"
  114. color="high"
  115. >
  116. {activeLocale}
  117. </Text>
  118. </Text>
  119. <View
  120. style={[
  121. stylesheet.borderedCard2,
  122. {
  123. backgroundColor: colors.content.container.default,
  124. padding: spaces.spacingMd,
  125. gap: spaces.spacingMd
  126. }
  127. ]}
  128. >
  129. <View>
  130. <Text
  131. variant="labelMediumSize"
  132. color="mid"
  133. >
  134. "hello-world" key
  135. </Text>
  136. <Text
  137. variant="bodyLargeSize"
  138. color="high"
  139. >
  140. {localize("hello-world")}
  141. </Text>
  142. </View>
  143. <View>
  144. <Text
  145. variant="labelMediumSize"
  146. color="mid"
  147. >
  148. "menu" key
  149. </Text>
  150. <Text
  151. variant="bodyLargeSize"
  152. color="high"
  153. >
  154. {localize("menu")}
  155. </Text>
  156. </View>
  157. <View>
  158. <Text
  159. variant="labelMediumSize"
  160. color="mid"
  161. >
  162. "installation" key
  163. </Text>
  164. <Text
  165. variant="bodyLargeSize"
  166. color="high"
  167. >
  168. {localize("installation")}
  169. </Text>
  170. </View>
  171. </View>
  172. </View>
  173. <View
  174. style={[
  175. stylesheet.rowSpaceBetween,
  176. {
  177. marginTop: spaces.spacingXl
  178. }
  179. ]}
  180. >
  181. <Button
  182. icon={({
  183. color,
  184. size
  185. }) => {
  186. return <ChevronLeftIcon
  187. color={colors.content.icon[color]}
  188. size={size + 3}
  189. />;
  190. }}
  191. onPress={() => {
  192. navigation.navigate("CoreFeatures", {
  193. screen: "ThemeExamples"
  194. });
  195. }}
  196. title={localize("themeExamples-title")}
  197. />
  198. <Button
  199. icon={({
  200. color,
  201. size
  202. }) => {
  203. return <ChevronRightIcon
  204. color={colors.content.icon[color]}
  205. size={size + 3}
  206. />;
  207. }}
  208. onPress={() => {
  209. navigation.navigate("CoreFeatures", {
  210. screen: "TypesOverride"
  211. });
  212. }}
  213. title={localize("typesOverride-title")}
  214. iconDirection="right"
  215. />
  216. </View>
  217. </PageContainer>;
  218. };
  219. export default LocaleExamples;