Dialog.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import React from "react";
  2. import { StyleSheet } from "react-native";
  3. import {
  4. Modal,
  5. Card,
  6. Text,
  7. Button,
  8. Layout,
  9. Input,
  10. } from "@ui-kitten/components";
  11. import { useModel, setModel } from "flooks";
  12. import dialogModel from "../models/dialogModel";
  13. import Textarea from "react-native-textarea";
  14. setModel("dialogModel", dialogModel);
  15. const Header = (props, title) => (
  16. <Text {...props} category='s1'>
  17. {title}
  18. </Text>
  19. );
  20. const Footer = (
  21. props,
  22. cancelLabelText,
  23. confirmLabelText,
  24. cancelable,
  25. confirmCallback,
  26. cancelCallback
  27. ) => (
  28. <Layout {...props} style={[props.style, styles.footerContainer]}>
  29. {cancelable && (
  30. <Button
  31. style={styles.footerControl}
  32. status='basic'
  33. size='small'
  34. appearance='outline'
  35. onPress={cancelCallback}
  36. >
  37. {cancelLabelText}
  38. </Button>
  39. )}
  40. <Button
  41. style={styles.footerControl}
  42. size='small'
  43. onPress={confirmCallback}
  44. >
  45. {confirmLabelText}
  46. </Button>
  47. </Layout>
  48. );
  49. export default function Dialog(props) {
  50. const { tip, confirm, cancel } = useModel("wordsModel");
  51. const {
  52. hideDialog,
  53. diloadShow,
  54. showInfo,
  55. title,
  56. cancelLabelText,
  57. confirmLabelText,
  58. cancelable,
  59. confirmCallback,
  60. cancelCallback,
  61. bodyText,
  62. status,
  63. isEdit,
  64. textAreaInfo,
  65. } = useModel("dialogModel");
  66. const showAllInfo = React.useMemo(() => {
  67. if (diloadShow) {
  68. console.log({
  69. title,
  70. cancelLabelText,
  71. confirmLabelText,
  72. cancelable,
  73. confirmCallback,
  74. cancelCallback,
  75. bodyText,
  76. isEdit,
  77. status,
  78. ...textAreaInfo,
  79. ...showInfo,
  80. });
  81. return {
  82. title,
  83. cancelLabelText,
  84. confirmLabelText,
  85. cancelable,
  86. confirmCallback,
  87. cancelCallback,
  88. bodyText,
  89. isEdit,
  90. status,
  91. ...textAreaInfo,
  92. ...showInfo,
  93. };
  94. } else {
  95. return {};
  96. }
  97. }, [showInfo, diloadShow]);
  98. const [introduction, changeIntroduction] = React.useState();
  99. return (
  100. <Modal visible={diloadShow} backdropStyle={styles.backdrop}>
  101. <Card
  102. style={styles.card}
  103. appearance='diaogOutline'
  104. header={props => {
  105. return Header(props, showAllInfo.title || tip);
  106. }}
  107. footer={props => {
  108. return Footer(
  109. props,
  110. showAllInfo.cancelLabelText || cancel,
  111. showAllInfo.confirmLabelText || confirm,
  112. showAllInfo.cancelable || false,
  113. () => {
  114. hideDialog();
  115. if (showAllInfo.confirmCallback) {
  116. if (showAllInfo.isEdit) {
  117. showAllInfo.confirmCallback(introduction);
  118. } else {
  119. showAllInfo.confirmCallback();
  120. }
  121. }
  122. },
  123. () => {
  124. hideDialog();
  125. if (showAllInfo.cancelCallback) {
  126. showAllInfo.cancelCallback();
  127. }
  128. }
  129. );
  130. }}
  131. >
  132. {showAllInfo.isEdit ? (
  133. showAllInfo.InputType ? (
  134. <Input
  135. dataDetectorTypes={
  136. showAllInfo.InputType == "phone"
  137. ? "phoneNumber"
  138. : "default"
  139. }
  140. keyboardType={
  141. showAllInfo.InputType == "phone"
  142. ? "phone-pad"
  143. : "default"
  144. }
  145. onChangeText={changeIntroduction}
  146. defaultValue={showAllInfo.defaultValue}
  147. maxLength={showAllInfo.maxLength}
  148. placeholder={showAllInfo.pla}
  149. />
  150. ) : (
  151. <Textarea
  152. containerStyle={styles.textareaContainer}
  153. style={styles.textarea}
  154. onChangeText={changeIntroduction}
  155. defaultValue={showAllInfo.defaultValue}
  156. maxLength={showAllInfo.maxLength}
  157. placeholder={showAllInfo.pla}
  158. placeholderTextColor={"#B4B4B4"}
  159. underlineColorAndroid={"transparent"}
  160. />
  161. )
  162. ) : (
  163. <Text
  164. {...props}
  165. category='p1'
  166. status={showAllInfo.status || ""}
  167. >
  168. {showAllInfo.bodyText || "确认删除吗"}
  169. </Text>
  170. )}
  171. </Card>
  172. </Modal>
  173. );
  174. }
  175. const styles = StyleSheet.create({
  176. backdrop: {
  177. backgroundColor: "rgba(0, 0, 0, 0.5)",
  178. },
  179. card: {
  180. alignItems: "center",
  181. minWidth: 263,
  182. },
  183. footerContainer: {
  184. flexDirection: "row",
  185. },
  186. footerControl: {
  187. minWidth: 112,
  188. marginHorizontal: 10,
  189. },
  190. textareaContainer: {
  191. backgroundColor: "#F0F0F0",
  192. height: 100,
  193. alignSelf: "stretch",
  194. width: 250,
  195. borderRadius: 4,
  196. },
  197. textarea: {
  198. textAlignVertical: "top", // hack android
  199. fontSize: 13,
  200. color: "#333",
  201. paddingHorizontal: 14,
  202. paddingVertical: 10,
  203. height: 100,
  204. },
  205. });