/* eslint-disable no-shadow */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable react/jsx-props-no-spreading */
import React from "react";
import { StyleSheet } from "react-native";
import {
Modal,
Card,
Text,
Button,
Layout,
Input,
} from "@ui-kitten/components";
import { useModel, setModel } from "flooks";
import Textarea from "react-native-textarea";
import dialogModel from "../models/dialogModel";
setModel("dialogModel", dialogModel);
const styles = StyleSheet.create({
backdrop: {
backgroundColor: "rgba(0, 0, 0, 0.5)",
},
card: {
alignItems: "center",
minWidth: 263,
},
footerContainer: {
flexDirection: "row",
},
footerControl: {
minWidth: 112,
marginHorizontal: 10,
},
textareaContainer: {
backgroundColor: "#F0F0F0",
height: 100,
alignSelf: "stretch",
width: 250,
borderRadius: 4,
},
textarea: {
textAlignVertical: "top", // hack android
fontSize: 13,
color: "#333",
paddingHorizontal: 14,
paddingVertical: 10,
height: 100,
},
});
const Header = (props, title) => (
{title}
);
const Footer = (
props,
cancelLabelText,
confirmLabelText,
cancelable,
confirmCallback,
cancelCallback
) => (
{cancelable && (
)}
);
export default function Dialog(props) {
const { tip, confirm, cancel } = useModel("wordsModel");
const {
hideDialog,
diloadShow,
showInfo,
title,
cancelLabelText,
confirmLabelText,
cancelable,
confirmCallback,
cancelCallback,
bodyText,
status,
isEdit,
textAreaInfo,
} = useModel("dialogModel");
const showAllInfo = React.useMemo(() => {
if (diloadShow) {
return {
title,
cancelLabelText,
confirmLabelText,
cancelable,
confirmCallback,
cancelCallback,
bodyText,
isEdit,
status,
...textAreaInfo,
...showInfo,
};
}
return {};
}, [showInfo, diloadShow]);
const [introduction, changeIntroduction] = React.useState();
return (
{
return Header(props, showAllInfo.title || tip);
}}
footer={props => {
return Footer(
props,
showAllInfo.cancelLabelText || cancel,
showAllInfo.confirmLabelText || confirm,
showAllInfo.cancelable || false,
() => {
hideDialog();
if (showAllInfo.confirmCallback) {
if (showAllInfo.isEdit) {
showAllInfo.confirmCallback(
introduction || showAllInfo.defaultValue
);
} else {
showAllInfo.confirmCallback();
}
}
},
() => {
hideDialog();
if (showAllInfo.cancelCallback) {
showAllInfo.cancelCallback();
}
}
);
}}
>
{showAllInfo.isEdit ? (
showAllInfo.InputType ? (
) : (
)
) : (
{showAllInfo.bodyText || "确认删除吗"}
)}
);
}