如果我点击一个文本输入,我希望能够点击其他地方,以便再次取消键盘(不是返回键)。在我读过的所有教程和博客文章中,我没有发现一丁点关于这方面的信息。

这个基本的例子在模拟器中的react-native 0.4.2中仍然不能为我工作。还不能在我的iPhone上试试。

<View style={styles.container}>
  <Text style={styles.welcome}>
    Welcome to React Native!
  </Text>
  <Text style={styles.instructions}>
    To get started, edit index.ios.js
  </Text>
  <Text style={styles.instructions}>
    Press Cmd+R to reload,{'\n'}
    Cmd+D or shake for dev menu
  </Text>
  <TextInput
    style={{height: 40, borderColor: 'gray', borderWidth: 1}}
    onEndEditing={this.clearFocus}
  />
</View>

当前回答

键盘模块用于控制键盘事件。

import {Keyboard} from 'react-native' 在渲染方法中添加以下代码。 呈现(){ 返回<TextInput onSubmitEditing={键盘。驳回}/ >; }

你可以使用-

Keyboard.dismiss()

解散活动键盘,并根据react本机文档删除焦点。

其他回答

将此用于自定义撤销

var dismissKeyboard = require('dismissKeyboard');

var TestView = React.createClass({
    render: function(){
        return (
            <TouchableWithoutFeedback 
                onPress={dismissKeyboard}>
                <View />
            </TouchableWithoutFeedback>
        )
    }
})

这刚刚被更新和记录!不再有隐藏的诡计。

import { Keyboard } from 'react-native'

// Hide that keyboard!
Keyboard.dismiss()

Github链接

这是最简单的方法

import {Keyboard} from 'react-native'

然后使用函数Keyboard.dismiss()

这是所有。

下面是我代码的截图,这样你可以更快地理解。

现在用TouchableWithoutFeedback和onPress函数来包装整个视图是keyboard。dismiss()

下面是一个例子

这样,如果用户点击屏幕上的任何地方,不包括textInput字段,键盘将被解散。

键盘模块用于控制键盘事件。

import {Keyboard} from 'react-native' 在渲染方法中添加以下代码。 呈现(){ 返回<TextInput onSubmitEditing={键盘。驳回}/ >; }

你可以使用-

Keyboard.dismiss()

解散活动键盘,并根据react本机文档删除焦点。

使用react-native中的KeyBoard API就可以了。

import { Keyboard } from 'react-native'

// Hide the keyboard whenever you want using !
Keyboard.dismiss()