1

我有一个简短的表单,它有两个 FormInput 字段(来自 react-native-elements)。当触摸文本输入之外的屏幕上的任何位置时,我尝试使用几种方法来移除焦点(并隐藏键盘)。

  <View style={{flex:1}}>
  <ScrollView keyboardShouldPersistTaps="handled">
    <FormInput
        placeholder='Phone Number'
        errorStyle={{ color: 'red' }}
        inputStyle={{ color: 'white', fontSize: 20, fontFamily: 'Roboto-Thin', borderBottomColor: 'transparent'}}
        placeholderTextColor='white'
        onChangeText = {this.onPhoneChange.bind(this)}
        containerStyle = {{ borderBottomWidth: 1, borderBottomColor: '#4DB1AD', width: '90%'}}
        keyboardType='numeric'
        maxLength={10}
    />
    </ScrollView>
    </View>

我也试过

  <TouchableWithoutFeedback style={{flex: 1}} onPress={Keyboard.dismiss} accessible={false}>
  <View>
    <FormInput
        placeholder='Phone Number'
        errorStyle={{ color: 'red' }}
        inputStyle={{ color: 'white', fontSize: 20, fontFamily: 'Roboto-Thin', borderBottomColor: 'transparent'}}
        placeholderTextColor='white'
        onChangeText = {this.onPhoneChange.bind(this)}
        containerStyle = {{ borderBottomWidth: 1, borderBottomColor: '#4DB1AD', width: '90%'}}
        keyboardType='numeric'
        maxLength={10}
        onSubmitEditing={Keyboard.dismiss}
        onBlur={Keyboard.dismiss}
        blurOnSubmit={true}
    />
    </View>
    </TouchableWithoutFeedback>

和这个方法

  <TouchableOpacity activeOpacity={1} onPress={() => Keyboard.dismiss()}>
    <FormInput
        placeholder='Phone Number'
        errorStyle={{ color: 'red' }}
        inputStyle={{ color: 'white', fontSize: 20, fontFamily: 'Roboto-Thin', borderBottomColor: 'transparent'}}
        placeholderTextColor='white'
        onChangeText = {this.onPhoneChange.bind(this)}
        containerStyle = {{ borderBottomWidth: 1, borderBottomColor: '#4DB1AD', width: '90%'}}
        keyboardType='numeric'
        maxLength={10}
    />
    </TouchableOpacity>

不幸的是,这些解决方案都不适合我。

4

0 回答 0