当在React native中按下屏幕上的按钮时,TextInput的onBlur函数不会调用

时间:2017-11-08 15:07:32

标签: react-native react-native-ios

我正在做一个登录页面。我有组件自定义TextInput和CustomButton。如果用户按下TextBox,它将调用onBlur并发送文本,但是当我在TextBox上填写全文,然后按提交,onBlur函数不会调用。你可以帮我一个方法来解决它们吗?

这是TextBox,TextInput的自定义

export const TextBox = (props) => (
  <TextInput
    style={styles.textInput}
    placeholderTextColor={styles.placeholderTextColor}
    placeholder={props.placeholder}
    autoCapitalize={props.autoCapitalize}
    keyboardType={props.keyboardType}
    onBlur={(e) => {
      onEnter(e.nativeEvent.text)
    }}
  />
)

这是登录页面,包含TextBox。

renderBoxMessgase = (textBox) => {
  const {
    placeholder,
    errorMessage,
    stylesWrraper,
    type,
    keyboardType
  } = textBox

  return (
    <View
      key={placeholder}
      style={styles[stylesWrraper]}
    >
      <TextBox
        onEnter={(text) => {
          this.checkErrorMessage(text, type)
        }}
        placeholder={placeholder}
        errorMessage={errorMessage}
        keyboardType={keyboardType}
      />
    </View>
  )
}

render() {
  const textBoxes = [this.state.name, this.state.email]
  return (
    <Container style={styles.contentWrapper}>
      <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
        <Image
          source={Images.welcomeBg}
          style={styles.container}
        >
          <Logo />
          <KeyboardAvoidingView behavior="padding">
            <View style={styles.textWarpper}>
              <TextView
                content='Hello, please enter your name and email to continue.'
                type='description'
                isUppercase={false}
                textAlign='center'
                size='large'
                numberOfLines={10}
              />
            </View>
            {textBoxes.map(box => this.renderBoxMessgase(box))}
            <CustomButton
              label='Sign in'
              type='small'
              isUpperCase={true}
              onPress={() => this.onPressLogin()}
            />
          </KeyboardAvoidingView>
        </Image>
      </TouchableWithoutFeedback>
    </Container>
  );
}

Submit but onBlur doen't read

0 个答案:

没有答案