index.tsx 3.8 KB

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