index.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. BottomSheet,
  14. CodeViewer,
  15. Button,
  16. Header,
  17. Switch,
  18. Text
  19. } from "ncore-ui-kit";
  20. import {
  21. useNavigation
  22. } from "@react-navigation/native";
  23. import type RootStackParamList from "../../../navigation/type";
  24. import type {
  25. NativeStackNavigationProp
  26. } from "@react-navigation/native-stack";
  27. const BottomSheetPage = () => {
  28. const {
  29. radiuses,
  30. borders,
  31. spaces,
  32. colors
  33. } = NCoreUIKitTheme.useContext();
  34. const {
  35. localize
  36. } = NCoreUIKitLocalize.useContext();
  37. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  38. const [
  39. isWorkWithPortal,
  40. setIsWorkWithPortal
  41. ] = useState<boolean>(true);
  42. const [
  43. isSwipeClose,
  44. setIsSwipeClose
  45. ] = useState<boolean>(true);
  46. const [
  47. isShowHandle,
  48. setIsShowHandle
  49. ] = useState<boolean>(true);
  50. const [
  51. isActive,
  52. setIsActive
  53. ] = useState<boolean>(false);
  54. useLayoutEffect(() => {
  55. navigation.setOptions({
  56. header: () => <Header
  57. title={localize("bottomSheet-title")}
  58. isWrapSafeareaContext={false}
  59. navigation={navigation}
  60. isGoBackEnable={true}
  61. />,
  62. headerShown: true
  63. });
  64. }, []);
  65. return <PageContainer
  66. scrollViewProps={{
  67. contentContainerStyle: stylesheet.scrollContent
  68. }}
  69. isWorkWithHeaderSpace={false}
  70. scrollViewStyle={[
  71. stylesheet.container
  72. ]}
  73. isScrollable={true}
  74. >
  75. <View
  76. style={[
  77. stylesheet.contentContainer
  78. ]}
  79. >
  80. <Text
  81. style={stylesheet.marginContainer}
  82. variant="bodyMediumSize"
  83. color="mid"
  84. >
  85. {localize("bottomSheet-desc")}
  86. </Text>
  87. <View
  88. style={[
  89. stylesheet.paddedMarginContainer,
  90. {
  91. borderColor: colors.content.border.subtle,
  92. marginBottom: spaces.spacingMd,
  93. borderRadius: radiuses.form,
  94. borderWidth: borders.line,
  95. padding: spaces.spacingMd
  96. }
  97. ]}
  98. >
  99. <Button
  100. title={localize("bottomSheet-openSheet")}
  101. onPress={() => setIsActive(true)}
  102. />
  103. </View>
  104. <View
  105. style={{
  106. marginBottom: spaces.spacingMd
  107. }}
  108. >
  109. <Text
  110. style={{
  111. marginBottom: spaces.spacingSm
  112. }}
  113. variant="headlineSmallSize"
  114. >
  115. {localize("usage")}
  116. </Text>
  117. <CodeViewer
  118. code={"import {\n BottomSheet\n} from \"ncore-ui-kit\";\n\n<BottomSheet\n isActive={isActive}\n onClose={() => setIsActive(false)}\n>\n <Text>BottomSheet Content</Text>\n</BottomSheet>"}
  119. language="tsx"
  120. />
  121. </View>
  122. <View
  123. style={[
  124. stylesheet.rowSpaceBetween,
  125. {
  126. gap: spaces.spacingMd
  127. }
  128. ]}
  129. >
  130. <View
  131. style={stylesheet.rowSpaceBetween2}
  132. >
  133. <Switch
  134. title={localize(
  135. "bottomSheet-toggleSwipeClose",
  136. )}
  137. onPress={() => {
  138. setIsSwipeClose(!isSwipeClose);
  139. }}
  140. isActive={isSwipeClose}
  141. spreadBehaviour="free"
  142. />
  143. <Switch
  144. title={localize(
  145. "bottomSheet-toggleShowHandle",
  146. )}
  147. onPress={() => {
  148. setIsShowHandle(!isShowHandle);
  149. }}
  150. isActive={isShowHandle}
  151. spreadBehaviour="free"
  152. />
  153. <Switch
  154. title={localize("bottomSheet-togglePortal")}
  155. onPress={() => {
  156. setIsWorkWithPortal(!isWorkWithPortal);
  157. }}
  158. isActive={isWorkWithPortal}
  159. spreadBehaviour="free"
  160. />
  161. </View>
  162. </View>
  163. </View>
  164. <BottomSheet
  165. isWorkWithPortal={isWorkWithPortal}
  166. onClose={() => setIsActive(false)}
  167. isSwipeClose={isSwipeClose}
  168. isShowHandle={isShowHandle}
  169. isActive={isActive}
  170. >
  171. <View
  172. style={{
  173. padding: spaces.spacingMd
  174. }}
  175. >
  176. <Text
  177. style={[
  178. stylesheet.centeredText,
  179. {
  180. marginBottom: spaces.spacingMd
  181. }
  182. ]}
  183. >
  184. {localize("bottomSheet-content")}
  185. </Text>
  186. <Button
  187. title={localize("bottomSheet-close")}
  188. onPress={() => setIsActive(false)}
  189. spreadBehaviour="stretch"
  190. type="danger"
  191. />
  192. </View>
  193. </BottomSheet>
  194. </PageContainer>;
  195. };
  196. export default BottomSheetPage;