| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- import * as WebBrowser from "expo-web-browser";
- import * as React from "react";
- import { View, StyleSheet, TouchableWithoutFeedback } from "react-native";
- import {
- Layout,
- Input,
- Button,
- useTheme,
- Icon,
- Text,
- SelectItem,
- } from "@ui-kitten/components";
- import { Cascader, BottomModal } from "beeshell";
- import variables from "../constants/customTheme";
- import { useModel } from "flooks";
- import OpenTime from "./OpenTime";
- import UpLoadImage from "./UpLoadImage";
- import moment from "moment";
- import Actionsheet from "./Actionsheet";
- const AlertIcon = (props) => <Icon {...props} name='alert-circle-outline' />;
- function* flattenSelect(array, key) {
- for (const item of array) {
- let _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 [secureTextEntry, setSecureTextEntry] = React.useState(true);
- const { cancel, confirm } = useModel("wordsModel");
- const toggleSecureEntry = () => {
- setSecureTextEntry(!secureTextEntry);
- };
- const renderIcon = (props) => (
- <TouchableWithoutFeedback onPress={toggleSecureEntry}>
- <Icon {...props} name={secureTextEntry ? "eye-off" : "eye"} />
- </TouchableWithoutFeedback>
- );
- function getInputProps(props) {
- let _props = {
- value: props.value || "",
- placeholder: props.placeholder,
- };
- if (props.type === "phone") {
- _props = {
- ..._props,
- dataDetectorTypes: "phoneNumber",
- maxLength: 11,
- keyboardType: "phone-pad",
- };
- } else if (props.type === "password") {
- _props = {
- ..._props,
- accessoryRight: (ImageProps) => renderIcon(ImageProps),
- secureTextEntry: secureTextEntry,
- };
- } else if (props.type == "code") {
- _props = {
- ..._props,
- maxLength: 6,
- keyboardType: "numeric",
- };
- } else if (props.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 = (props) => {
- return (
- <View
- style={[
- styles.label,
- props.type === "img" ? { alignSelf: "flex-start" } : {},
- props.labelStyle || {},
- ]}
- >
- <Text category='c1' style={{ textAlign: "right" }}>
- {props.label}
- </Text>
- </View>
- );
- };
- const ForwardIcon = (props) => <Icon {...props} name='arrow-ios-forward' />;
- const selectList = props.selectList ? props.selectList : [];
- const [bottomModalX, changeBottomModalx] = React.useState("");
- const [selectVal, setSelectVal] = React.useState("");
- const selectInfo = React.useMemo(() => {
- if (props.type === "select" && props.value && selectList.length > 0) {
- const childrens = [...flattenSelect(selectList, "children")];
- return (
- childrens.find((item) => {
- return item.id == props.value;
- }) || { name: " " }
- );
- } else {
- return { name: " " };
- }
- }, [props.value, props.type, selectList]);
- const [open, ChangeOpen] = React.useState(false);
- function submitEvent(val) {
- console.log(val);
- }
- const theme = useTheme();
- function getMain(type, props) {
- if (type == "select") {
- return (
- <>
- <SelectItem
- appearance='form'
- style={{ flex: 1 }}
- accessoryRight={ForwardIcon}
- title={selectInfo.name}
- onPress={() => {
- bottomModalX.open();
- }}
- />
- <BottomModal
- ref={(c) => {
- changeBottomModalx(c);
- }}
- title={props.selectTitle}
- titleStyle={styles.titleStyle}
- cancelable={true}
- leftLabelText={cancel}
- leftLabelTextStyle={styles.leftLabelTextStyle}
- rightLabelText={confirm}
- rightLabelTextStyle={styles.rightLabelTextStyle}
- rightCallback={() => {
- props.onChange(selectVal);
- }}
- >
- <Cascader
- style={{ height: 200, marginBottom: 50 }}
- data={selectList}
- fieldKeys={{
- labelKey: "name",
- idKey: "id",
- activeKey: "choose",
- }}
- onChange={(value, info) => {
- setSelectVal(value[0]);
- }}
- />
- </BottomModal>
- </>
- );
- } else if (type == "openTime") {
- return (
- <OpenTime
- open={open}
- submit={(start, end, week) => {
- ChangeOpen(false);
- props.onChange(
- week.join(","),
- moment(start, "HH:mm").format("HH:mm:ss"),
- moment(end, "HH:mm").format("HH:mm:ss")
- );
- console.log(
- moment(start, "HH:mm").format("HH:mm:ss"),
- moment(end, "HH:mm").format("HH:mm:ss"),
- week
- );
- }}
- cancelEvent={() => {
- ChangeOpen(false);
- }}
- openModal={() => {
- ChangeOpen(true);
- }}
- defaultValue={props.defaultValue}
- />
- );
- } else if (type == "url") {
- return (
- <SelectItem
- appearance='form'
- style={{ flex: 1 }}
- accessoryRight={ForwardIcon}
- title={props.value || " "}
- onPress={props.changePath}
- />
- );
- } else if (type == "actionSheet") {
- return (
- <>
- <Actionsheet
- list={props.list}
- value={props.value}
- onChange={props.onChange}
- />
- </>
- );
- } else if (type == "img") {
- return (
- <UpLoadImage
- style={styles.upload}
- value={props.value}
- changeIcon={props.onChange}
- />
- );
- } else {
- return <Input {...inputProps} size='small' style={styles.input} />;
- }
- }
- return (
- <Layout
- level='1'
- style={[
- styles.inputContainer,
- { ...props.style },
- props.type === "img" ? { flexDirection: "column" } : {},
- ]}
- >
- <Label {...props} />
- {(!props.value || props.value == " ") && (
- <Text category='c1' style={styles.sub}>
- {props.sub}
- </Text>
- )}
- {getMain(props.type, props)}
- {props.type == "code" && (
- <Button
- appearance='ghost'
- size='tiny'
- style={{ paddingVertical: 8, marginLeft: 5 }}
- >
- {props.btnText}
- </Button>
- )}
- </Layout>
- );
- });
- function ChnageTime(sendNum, isSend, changeSend_Num) {
- let num = sendNum - 1;
- console.log(num);
- changeSend_Num(true, num);
- setTimeout(() => {
- ChnageTime(num, isSend, changeSend_Num);
- }, 1000);
- }
- const styles = StyleSheet.create({
- inputContainer: {
- flexDirection: "row",
- alignItems: "center",
- paddingVertical: 10,
- paddingHorizontal: 4,
- },
- input: {
- flex: 1,
- },
- label: {
- width: 80,
- marginRight: 19,
- 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,
- },
- });
- export default FormInput;
|