我有一个TextInput,我已经启用multiline为真.问题是按下回车键后键盘不会隐藏.这是一条新的路由.所以我希望用react-native-dismiss-keyboard.要利用这一点,我需要识别返回键操作.怎么做?

<TextInput
    style={styles.additionalTextInput}
    multiline={true}
    autoCapitalize="sentences"
    autoCorrect={true}
    onChangeText={(text) => this.setState({text})}
    keyboardType="default"
    returnKeyType="done"
    onKeyPress={(keyPress) => console.log(keyPress)}
    placeholder="Enter text here..."
/>

推荐答案

我用了onSubmitEditing个props .例如

<TextInput style={[styles.textInput]}
  placeholder='搜索'
  placeholderTextColor='#bbb'
  onChange={(event) => {
    this.searchChange(event.nativeEvent.text)
  }}
  returnKeyType='search'
  autoFocus={true}
  value={ this.props.searchName }
  selectionColor={colors.orangeColor}
  onSubmitEditing={this.searchSubmit}
  clearButtonMode="while-editing"
/>

React-native相关问答推荐

Redux toolkit通过按钮操作进行查询

如何在Recact Native中单击Back按钮后调用函数

在AWS-Amplify js v6中检索原始的accesToken和idToken

React Native - 何时调用componentWillUnmount?

错误:HostFunction 中的异常: Malformed calls from JS: field sizes are different. In an Animated View

Eslint 错误,configuration for rule "import/no-cycle" is invalid

加载作为props传递的图像

react-native 中 android 和 iOS 的图像大小

使用带有 react-native 的 WebView 设置用户代理

如何在 react-native 中在图像周围添加阴影

React-Native Packager 失败:重复的模块名称

以编程方式在 React Native 中添加组件

React-Native Android 中隐藏(hide)的元素溢出

React Native 中的全屏图像

在本react-native中具有异步和等待的箭头函数

React Native:如何获取文件大小、mime 类型和扩展名?

React-native Xcode 构建失败 -> 'RCTAssert.h file not found'

> 任务 :app:checkDebugAarMetadata 在运行 react-native run-android 时失败

expo 已过期卸载并再次运行以升级

类型 androidx.appcompat.resources.R$dimen 被定义了多次