Dialog.js 6.1 KB

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