EditBannerScreen.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import { Image, StyleSheet } from "react-native";
  4. import { Layout, Text, useTheme, Button } from "@ui-kitten/components";
  5. import { useFocusEffect } from "@react-navigation/native";
  6. import { useModel } from "flooks";
  7. import ScrollPage from "../components/ScrollPage";
  8. import NavHeaderBar from "../components/NavHeaderBar";
  9. import UpLoadImage from "../components/UpLoadImage";
  10. const styles = StyleSheet.create({
  11. container: {
  12. flex: 1,
  13. paddingBottom: 33,
  14. },
  15. icon: {
  16. width: 90,
  17. height: 80,
  18. marginBottom: 26,
  19. },
  20. text: {
  21. fontWeight: "500",
  22. marginBottom: 7,
  23. },
  24. top: {
  25. paddingVertical: 7,
  26. height: 114,
  27. backgroundColor: "#eee",
  28. alignSelf: "stretch",
  29. alignItems: "center",
  30. justifyContent: "center",
  31. },
  32. banner: {
  33. flex: 1,
  34. alignSelf: "stretch",
  35. },
  36. logo: {
  37. width: 50,
  38. height: 50,
  39. borderRadius: 3,
  40. },
  41. remove: {
  42. position: "absolute",
  43. bottom: 10,
  44. right: 10,
  45. },
  46. upload: {
  47. marginTop: 21,
  48. width: 133,
  49. height: 133,
  50. alignSelf: "center",
  51. },
  52. main: {
  53. paddingHorizontal: 24,
  54. paddingVertical: 14,
  55. },
  56. button: {
  57. alignSelf: "center",
  58. marginTop: 19,
  59. },
  60. });
  61. export default function EditBannerScreen({ route }) {
  62. const theme = useTheme();
  63. const { changeBackground } = useModel("barModel");
  64. const {
  65. banner,
  66. logo,
  67. qualification,
  68. uploadStoreImg,
  69. registerInfo,
  70. } = useModel("userModel");
  71. const [img, changeImg] = React.useState("");
  72. const [type, setType] = React.useState("banner");
  73. const { showDialog } = useModel("dialogModel");
  74. const {
  75. bannerTitle,
  76. logoTitle,
  77. qualificationTitle,
  78. remove,
  79. editText,
  80. uplaodText,
  81. uplaodImg,
  82. removeTips,
  83. } = useModel("wordsModel");
  84. useFocusEffect(
  85. React.useCallback(() => {
  86. changeBackground(theme["color-primary-500"]);
  87. if (route.params.type) {
  88. setType(route.params.type);
  89. }
  90. }, [])
  91. );
  92. return (
  93. <>
  94. <NavHeaderBar
  95. title={
  96. editText +
  97. (type === "banner"
  98. ? bannerTitle
  99. : type === "qualification"
  100. ? qualificationTitle
  101. : logoTitle)
  102. }
  103. />
  104. <ScrollPage>
  105. <Layout style={styles.container}>
  106. <Layout style={styles.top}>
  107. <Image
  108. source={{
  109. uri:
  110. type === "banner"
  111. ? banner
  112. : type === "qualification"
  113. ? qualification || registerInfo.qualification
  114. : logo,
  115. }}
  116. style={[type === "logo" ? styles.logo : styles.banner]}
  117. />
  118. <Button
  119. style={styles.remove}
  120. size="tiny"
  121. status="danger"
  122. onPress={() => {
  123. showDialog({
  124. bodyText: removeTips,
  125. status: "danger",
  126. cancelable: true,
  127. confirmCallback: () => {
  128. uploadStoreImg("", type);
  129. },
  130. });
  131. }}
  132. >
  133. {remove}
  134. </Button>
  135. </Layout>
  136. <Layout style={styles.main}>
  137. <Text category="c1">
  138. {uplaodText +
  139. (type === "banner"
  140. ? bannerTitle
  141. : type === "qualification"
  142. ? qualificationTitle
  143. : logoTitle)}
  144. </Text>
  145. <UpLoadImage
  146. style={styles.upload}
  147. value={img}
  148. changeIcon={changeImg}
  149. size={133}
  150. />
  151. <Button
  152. disabled={!img}
  153. style={styles.button}
  154. onPress={() => {
  155. uploadStoreImg(img, type).then(() => {
  156. changeImg("");
  157. });
  158. }}
  159. >
  160. {uplaodImg}
  161. </Button>
  162. </Layout>
  163. </Layout>
  164. </ScrollPage>
  165. </>
  166. );
  167. }