FormInput.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import { View, StyleSheet } from "react-native";
  4. import { Form, Input, Button } from "beeshell";
  5. import Text from "./Text";
  6. import variables from "../constants/customTheme";
  7. const FormInput = React.memo((props) => {
  8. function getInputProps(props) {
  9. let _props = {
  10. value: props.value || "",
  11. placeholder: props.placeholder,
  12. placeholderTextColor: "#B4B4B4",
  13. };
  14. if (props.type == "phone") {
  15. _props = {
  16. ...props,
  17. dataDetectorTypes: "phoneNumber",
  18. maxLength: 11,
  19. keyboardType: "phone-pad",
  20. };
  21. } else {
  22. _props = {
  23. ..._props,
  24. secureTextEntry: true,
  25. };
  26. }
  27. if (props.onChange) {
  28. _props = {
  29. ..._props,
  30. onChange: (value) => props.onChange(value),
  31. };
  32. }
  33. if (props.type == "code") {
  34. _props = {
  35. ..._props,
  36. dataDetectorTypes: "phoneNumber",
  37. maxLength: 6,
  38. keyboardType: "phone-pad",
  39. };
  40. }
  41. return _props;
  42. }
  43. const inputProps = getInputProps(props);
  44. const myInput = () => {
  45. if (inputProps != null) {
  46. return;
  47. }
  48. };
  49. const label = (props) => {
  50. return (
  51. <View style={styles.label}>
  52. <Text {...props}></Text>
  53. </View>
  54. );
  55. };
  56. return (
  57. <Form.Item label={label(props)}>
  58. <View style={styles.right}>
  59. {props.type !== "children" && (
  60. <Input {...inputProps} style={styles.input} />
  61. )}
  62. {props.children}
  63. {props.type === "code" && (
  64. <Button
  65. style={styles.code}
  66. type='primary'
  67. onPress={() => {
  68. props.changeSend_Num(true, 60);
  69. ChnageTime(60, true, props.changeSend_Num);
  70. }}
  71. >
  72. {props.isSend
  73. ? "(" + props.sendNum + ")S"
  74. : "发送验证码"}
  75. </Button>
  76. )}
  77. </View>
  78. </Form.Item>
  79. );
  80. });
  81. function ChnageTime(sendNum, isSend, changeSend_Num) {
  82. let num = sendNum - 1;
  83. console.log(num);
  84. changeSend_Num(true, num);
  85. setTimeout(() => {
  86. ChnageTime(num, isSend, changeSend_Num);
  87. }, 1000);
  88. }
  89. const styles = StyleSheet.create({
  90. input: {
  91. backgroundColor: "#F0F0F0",
  92. paddingHorizontal: 15,
  93. borderRadius: 3,
  94. marginRight: 4,
  95. flexShrink: 1,
  96. flex: 1,
  97. },
  98. label: {
  99. width: 90,
  100. marginRight: 19,
  101. },
  102. right: {
  103. flexDirection: "row",
  104. },
  105. code: {
  106. paddingHorizontal: 5,
  107. marginLeft: 5,
  108. },
  109. });
  110. export default FormInput;