/* eslint-disable react/jsx-props-no-spreading */ /* eslint-disable no-shadow */ /* eslint-disable no-underscore-dangle */ /* eslint-disable no-restricted-syntax */ import * as WebBrowser from "expo-web-browser"; import * as React from "react"; import { View, StyleSheet, TouchableWithoutFeedback } from "react-native"; import { Layout, Input, Button, Icon, Text, SelectItem, } from "@ui-kitten/components"; import { Cascader, BottomModal } from "beeshell"; import { useModel } from "flooks"; import moment from "moment"; import OpenTime from "./OpenTime"; import Datepicker from "./Datepicker"; import UpLoadImage from "./UpLoadImage"; import Actionsheet from "./Actionsheet"; const styles = StyleSheet.create({ inputContainer: { flexDirection: "row", alignItems: "center", paddingVertical: 10, paddingHorizontal: 4, }, input: { flex: 1, }, label: { width: 80, marginRight: 19, flexShrink: 0, }, labelleft: { width: 73, flexShrink: 0, }, right: { flexDirection: "row", }, code: { paddingHorizontal: 5, marginLeft: 5, }, selectContent: { backgroundColor: "#F0F0F0", }, titleStyle: { fontSize: 15, }, leftLabelTextStyle: { fontSize: 13, }, rightLabelTextStyle: { fontSize: 13, }, sub: { color: "#787878", position: "absolute", left: 90, zIndex: 2, }, upload: { marginTop: 20, width: 67, height: 67, }, }); function* flattenSelect(array, key) { for (const item of array) { const _array = key ? item[key] : item; if (Array.isArray(_array) && _array.length > 0) { yield* flattenSelect(_array, key); } else { yield item; } } } const FormInput = React.memo(props => { const { appearance,type } = props; const [secureTextEntry, setSecureTextEntry] = React.useState(true); const { cancel, confirm } = useModel("wordsModel"); const toggleSecureEntry = () => { setSecureTextEntry(!secureTextEntry); }; // eslint-disable-next-line no-shadow const renderIcon = props => ( ); function getInputProps(props) { let _props = { value: props.value || "", placeholder: props.placeholder, }; if (type === "phone") { _props = { ..._props, dataDetectorTypes: "phoneNumber", maxLength: 11, keyboardType: "phone-pad", }; } else if (type === "password") { _props = { ..._props, accessoryRight: ImageProps => renderIcon(ImageProps), secureTextEntry, }; } else if (type === "code") { _props = { ..._props, maxLength: 6, keyboardType: "numeric", }; } else if (type === "amount" || props.type === "money") { _props = { ..._props, keyboardType: "numeric", }; } if (props.onChange) { _props = { ..._props, onChangeText: nextValue => props.onChange(nextValue), }; } return _props; } const inputProps = getInputProps(props); // const myInput = () => { // if (inputProps != null) { // return; // } // }; const Label = ({type,labelStyle,label}) => { return ( {label} ); }; const ForwardIcon = props => ; const selectList = props.selectList ? props.selectList : []; const [bottomModalX, changeBottomModalx] = React.useState(""); const [selectVal, setSelectVal] = React.useState(""); const selectInfo = React.useMemo(() => { if (type === "select" && props.value && selectList.length > 0) { const childrens = [...flattenSelect(selectList, "children")]; return ( childrens.find(item => { return item.id === props.value; }) || { name: " " } ); } return { name: " " }; }, [props.value, props.type, selectList]); const [open, ChangeOpen] = React.useState(false); const Btn = ({ btnText }) => ( ); function getMain(type, props) { if (type === "select") { return ( <> { bottomModalX.open(); }} /> { changeBottomModalx(c); }} title={props.selectTitle} titleStyle={styles.titleStyle} cancelable leftLabelText={cancel} leftLabelTextStyle={styles.leftLabelTextStyle} rightLabelText={confirm} rightLabelTextStyle={styles.rightLabelTextStyle} rightCallback={() => { props.onChange(selectVal); }} > { setSelectVal(value[0]); }} /> ); } if (type === "openTime") { return ( { ChangeOpen(false); props.onChange( week.join(","), moment(start, "HH:mm").format("HH:mm:ss"), moment(end, "HH:mm").format("HH:mm:ss") ); }} cancelEvent={() => { ChangeOpen(false); }} openModal={() => { ChangeOpen(true); }} defaultValue={props.defaultValue} /> ); } if (type === "date") { return ( ); } if (type === "url") { return ( ); } if (type === "actionSheet") { return ( <> ); } if (type === "img") { return ( ); } if (appearance === "inner" && type === "code") { return ( (