index.tsx 4.0 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. SelectBox,
  14. Loading,
  15. Header
  16. ,
  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: () => (
  56. <Header
  57. title={localize("loading-title")}
  58. isWrapSafeareaContext={false}
  59. navigation={navigation}
  60. isGoBackEnable={true}
  61. />
  62. ),
  63. headerShown: true
  64. });
  65. }, []);
  66. return (
  67. <PageContainer
  68. scrollViewProps={{
  69. contentContainerStyle: stylesheet.scrollContent
  70. }}
  71. scrollViewStyle={[stylesheet.container]}
  72. isWorkWithHeaderSpace={false}
  73. isScrollable={true}
  74. >
  75. <View style={[stylesheet.contentContainer]}>
  76. <Text
  77. variant="bodyMediumSize"
  78. color="mid"
  79. style={{
  80. marginBottom: 20
  81. }}
  82. >
  83. {localize("loading-desc")}
  84. </Text>
  85. <View
  86. style={{
  87. borderColor: colors.content.border.subtle,
  88. marginBottom: spaces.spacingMd,
  89. borderRadius: radiuses.form,
  90. borderWidth: borders.line,
  91. padding: spaces.spacingMd,
  92. justifyContent: "center",
  93. alignItems: "center",
  94. minHeight: 120
  95. }}
  96. >
  97. <Loading size={SIZES[sizeIndex]} />
  98. </View>
  99. <View
  100. style={{
  101. justifyContent: "space-between",
  102. gap: spaces.spacingMd,
  103. flexDirection: "row",
  104. flexWrap: "wrap",
  105. width: "100%"
  106. }}
  107. >
  108. <SelectBox
  109. onChange={(selectedItems) => {
  110. if (selectedItems.length > 0) {
  111. const index = SIZES.indexOf(
  112. Number(
  113. selectedItems[0]!.__key,
  114. ) as ILoadingProps["size"],
  115. );
  116. if (index !== -1) setSizeIndex(index);
  117. }
  118. }}
  119. initialSelectedItems={
  120. SIZES_DATA[sizeIndex] ? [SIZES_DATA[sizeIndex]] : []
  121. }
  122. title={localize("loading-changeSize")}
  123. titleExtractor={(item) => item.__title}
  124. keyExtractor={(item) => item.__key}
  125. spreadBehaviour="free"
  126. data={SIZES_DATA}
  127. />
  128. </View>
  129. </View>
  130. </PageContainer>
  131. );
  132. };
  133. export default LoadingPage;