相关疑难解决方法(0)

在本地反应中隐藏键盘

如果我点击文本输入,我希望能够点击其他地方以便再次解除键盘(尽管不是返回键).我在所阅读的所有教程和博客文章中都没有找到关于这方面的最细微信息.

这个基本示例对我来说仍然不适用于模拟器中的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>
Run Code Online (Sandbox Code Playgroud)

reactjs react-native

375
推荐指数
26
解决办法
14万
查看次数

在 React Native 中单击 TextInput 字段之外时会失去焦点并关闭键盘吗?

我已经研究过它并找到了这篇文章:

react-native:隐藏键盘

但这对我不起作用。当我触摸文本输入字段之外的屏幕部分时,我预计输入字段将失去焦点并且键盘将被关闭。但是,什么也没有发生。光标在输入端一直闪烁。

下面是我试过的代码。请注意,我使用的是 redux-form v6:

import dismissKeyboard from 'dismissKeyboard';

<TouchableWithoutFeedback onPress={()=> dismissKeyboard()}>
        <View style={styles.inputWrap}>
          <Field name="editLocation" component={TextField} />
          <Button onPress={handleSubmit(this.onSubmit)}>Sign In</Button>
        </View>
</TouchableWithoutFeedback>
Run Code Online (Sandbox Code Playgroud)

TextField 组件包含 TextInput。不确定我是否做错了什么。

我已经使用三星 S6 图像和三星 note 4 在 Genymotion 模拟器上测试了代码。

javascript android react-native react-native-android

6
推荐指数
1
解决办法
7530
查看次数

React-Native:触摸 TextInput 一侧时,“onBlur”不会被触发

   <TextInput
        ref={ ref => this.mobileNumberRef = ref}
        keyboardType='phone-pad'
        returnKeyType='done'
        onBlur={() => Keyboard.dismiss()}
   />
Run Code Online (Sandbox Code Playgroud)

当触摸到该区域之外时,我想关闭键盘TextInput。但并onBlur()没有被解雇。

有人可以让我知道如何实现这一目标吗?谢谢你!

onblur react-native

5
推荐指数
1
解决办法
7622
查看次数