index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. SelectBox,
  15. Loading,
  16. Header,
  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. import type {
  27. ILoadingProps
  28. } from "ncore-ui-kit";
  29. const SIZES: Array<ILoadingProps["size"]> = [
  30. 16,
  31. 24,
  32. 32
  33. ];
  34. const SIZES_DATA = SIZES.map((item) => ({
  35. __title: String(item),
  36. __key: String(item)
  37. }));
  38. const LoadingPage = () => {
  39. const {
  40. radiuses,
  41. borders,
  42. spaces,
  43. colors
  44. } = NCoreUIKitTheme.useContext();
  45. const {
  46. localize
  47. } = NCoreUIKitLocalize.useContext();
  48. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  49. const [
  50. sizeIndex,
  51. setSizeIndex
  52. ] = useState<number>(1);
  53. useLayoutEffect(() => {
  54. navigation.setOptions({
  55. header: () => <Header
  56. title={localize("loading-title")}
  57. isWrapSafeareaContext={false}
  58. navigation={navigation}
  59. isGoBackEnable={true}
  60. />,
  61. headerShown: true
  62. });
  63. }, []);
  64. return <PageContainer
  65. scrollViewProps={{
  66. contentContainerStyle: stylesheet.scrollContent
  67. }}
  68. isWorkWithHeaderSpace={false}
  69. scrollViewStyle={[
  70. stylesheet.container
  71. ]}
  72. isScrollable={true}
  73. >
  74. <View
  75. style={[
  76. stylesheet.contentContainer
  77. ]}
  78. >
  79. <Text
  80. style={stylesheet.descText}
  81. variant="bodyMediumSize"
  82. color="mid"
  83. >
  84. {localize("loading-desc")}
  85. </Text>
  86. <View
  87. style={[
  88. stylesheet.previewContainer,
  89. {
  90. borderColor: colors.content.border.subtle,
  91. marginBottom: spaces.spacingMd,
  92. borderRadius: radiuses.form,
  93. borderWidth: borders.line,
  94. padding: spaces.spacingMd
  95. }
  96. ]}
  97. >
  98. <Loading
  99. size={SIZES[sizeIndex]}
  100. />
  101. </View>
  102. <View
  103. style={{
  104. marginBottom: spaces.spacingMd
  105. }}
  106. >
  107. <Text
  108. style={{
  109. marginBottom: spaces.spacingSm
  110. }}
  111. variant="headlineSmallSize"
  112. >
  113. {localize("usage")}
  114. </Text>
  115. <CodeViewer
  116. code={"import {\n Loading\n} from \"ncore-ui-kit\";\n\n<Loading size={24} />"}
  117. language="tsx"
  118. />
  119. </View>
  120. <View
  121. style={[
  122. stylesheet.rowContainer,
  123. {
  124. gap: spaces.spacingMd
  125. }
  126. ]}
  127. >
  128. <SelectBox
  129. onChange={(selectedItems) => {
  130. if (selectedItems.length > 0) {
  131. const index = SIZES.indexOf(
  132. Number(
  133. selectedItems[0]!.__key,
  134. ) as ILoadingProps["size"],
  135. );
  136. if (index !== -1) setSizeIndex(index);
  137. }
  138. }}
  139. titleExtractor={(item) => item.__title}
  140. title={localize("loading-changeSize")}
  141. keyExtractor={(item) => item.__key}
  142. initialSelectedItems={
  143. SIZES_DATA[sizeIndex]
  144. ? [
  145. SIZES_DATA[sizeIndex]!
  146. ]
  147. : []
  148. }
  149. spreadBehaviour="free"
  150. data={SIZES_DATA}
  151. />
  152. </View>
  153. </View>
  154. </PageContainer>;
  155. };
  156. export default LoadingPage;