Dialog.js 5.4 KB

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