Dialog.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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(introduction);
  138. } else {
  139. showAllInfo.confirmCallback();
  140. }
  141. }
  142. },
  143. () => {
  144. hideDialog();
  145. if (showAllInfo.cancelCallback) {
  146. showAllInfo.cancelCallback();
  147. }
  148. }
  149. );
  150. }}
  151. >
  152. {showAllInfo.isEdit ? (
  153. showAllInfo.InputType ? (
  154. <Input
  155. dataDetectorTypes={
  156. showAllInfo.InputType === "phone"
  157. ? "phoneNumber"
  158. : "default"
  159. }
  160. keyboardType={
  161. showAllInfo.InputType === "phone"
  162. ? "phone-pad"
  163. : "default"
  164. }
  165. onChangeText={changeIntroduction}
  166. defaultValue={showAllInfo.defaultValue}
  167. maxLength={showAllInfo.maxLength}
  168. placeholder={showAllInfo.pla}
  169. />
  170. ) : (
  171. <Textarea
  172. containerStyle={styles.textareaContainer}
  173. style={styles.textarea}
  174. onChangeText={changeIntroduction}
  175. defaultValue={showAllInfo.defaultValue}
  176. maxLength={showAllInfo.maxLength}
  177. placeholder={showAllInfo.pla}
  178. placeholderTextColor="#B4B4B4"
  179. underlineColorAndroid="transparent"
  180. />
  181. )
  182. ) : (
  183. <Text
  184. {...props}
  185. category='p1'
  186. status={showAllInfo.status || ""}
  187. >
  188. {showAllInfo.bodyText || "确认删除吗"}
  189. </Text>
  190. )}
  191. </Card>
  192. </Modal>
  193. );
  194. }