react-native - ScrollView 在 React Native 中删除 TextInput 键盘
问题描述
我正在使用TextInput
自定义清除图标来清除文本。由于我需要TextInput
在屏幕中保留多个 s,因此我使用了ScrollView
:
import React, {Component} from 'react';
import {
View,
Text,
ScrollView,
StyleSheet,
Image,
TouchableOpacity,
TextInput,
} from 'react-native';
export default class SuccessScreen extends Component {
constructor(props) {
super(props);
this.state = {};
}
handleRightClick() {
console.log('handleRightClick');
}
render() {
return (
<ScrollView>
<View style={styles.SectionStyle}>
<TextInput style={styles.input} />
<TouchableOpacity
style={styles.ImageStyle}
onPress={this.handleRightClick}>
<Image source={require('../../images/cross_icon.png')} />
</TouchableOpacity>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
input: {
flex: 1,
borderColor: '#000000',
borderBottomWidth: 1,
height: 40,
fontSize: 15,
color: '#000000',
},
SectionStyle: {
flexDirection: 'row',
minWidth: '100%',
height: 40,
},
ImageStyle: {
height: 25,
width: 25,
marginLeft: -25,
alignContent: 'center',
resizeMode: 'stretch',
alignItems: 'center',
},
});
没有ScrollView
,handleRightClick
被调用,但是当我使用 时ScrollView
,它只是关闭键盘而不调用handleRightClick
.
解决方案
有ScrollView
一个道具keyboardShouldPersistTaps
。您应该将其设置为'handled'
以便您TouchableOpacity
将处理新闻而不是ScrollView
.
<ScrollView keyboardShouldPersistTaps='handled'>
// ...
</ScrollView>
推荐阅读
- oracle - 西班牙语的 UTL_FILE 和字符集
- pine-script - pine-script,log(pi * (atr(factor)) 的含义是什么
- r - R中的ggplot - 具有两个y轴的直方图和线图
- php - 我无法使用其他计算机(相同的 wifi)在 xampp 中访问我的网站
- c# - 如果之前抛出,如何验证方法已达到
- swift - 使用 AVAudioplayer 展开可选值错误时意外发现 nil
- javascript - 联系表格 7 - 重定向到另一个页面
- java - json-b 是否有像 @JsonValue 一样工作的注释
- netsuite - 具有 GL 影响的库存调整脚本
- html - 为什么边框底部样式在 Outlook html 电子邮件中不起作用?