【发布时间】:2020-07-12 15:52:58
【问题描述】:
我正在尝试构建一个自定义输入组件,它执行以下操作:
- 接受道具 - 完成
- 如果 onFocus 为真,则渲染一个“V”图标 - 完成
- 验证输入:如果文本输入是“填充文本”,则检查验证是否为真,如果为真:将“V”图标颜色和按钮边框颜色更改为绿色,如果为假:将“V”图标颜色和按钮边框颜色更改为红色,保持这种样式,直到 inputField 再次为空
import React from "react";
import { View, TextInput, StyleSheet, Text } from "react-native";
import {
widthPercentageToDP as wp,
heightPercentageToDP as hp,
} from "react-native-responsive-screen";
import { MaterialCommunityIcons, AntDesign } from "@expo/vector-icons";
class RegisterTextBox extends React.Component {
constructor(props) {
super(props);
this.state = {
borderColor: "",
isFocused: false,
};
}
onBlur() {
this.setState({ isFocused: false });
}
onFocus() {
this.setState({ isFocused: true });
}
render() {
const { isFocused } = this.state;
const {
value,
placeholder,
onChangeText,
secureTextEntry,
inputStyle,
viewStyle,
showIcon = this.state.showIcon,
eyeIcon = false,
} = this.props;
return (
<View style={[styles.container, viewStyle]}>
<TextInput
style={[styles.main, { borderBottomColor: this.state.borderColor }]}
value={value}
onChangeText={onChangeText}
onBlur={() => this.onBlur()}
onFocus={() => this.onFocus()}
placeholder={placeholder}
secureTextEntry={secureTextEntry}
onChangeText={(val) => this.updateInputVal(val, "confirmPassword")}
/>
{isFocused ? (
<AntDesign
name="checkcircle"
size={18}
color="black"
style={{ paddingTop: 8 }}
/>
) : (
<View />
)}
{eyeIcon ? (
<MaterialCommunityIcons
name="eye-off"
size={24}
color="black"
style={{ paddingTop: 5, paddingLeft: 5 }}
/>
) : (
<View />
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
height: hp(5.4),
width: wp(65.2),
borderBottomWidth: 1,
flexDirection: "row",
justifyContent: "space-between",
},
main: {
flex: 1,
},
});
export default RegisterTextBox;
【问题讨论】:
标签: react-native