javascript - 通过在其外部点击来模糊 <TextInput/>,在 native react 中不起作用

标签 javascript reactjs react-native

我有 <TextInput/>我想模糊它并在 <TextInput/> 之外点击时切换键盘我试过this解决方案,但没有任何运气。

import React, { Component } from "react";
import { AppRegistry, Dimensions, StyleSheet, Text, TouchableHighlight, View, Image, TextInput, ScrollView, Keyboard, TouchableWithoutFeedback } from "react-native";
import { Button } from "react-native-elements";

class CounterextendsComponent {
  render() {
    return (
      <View style={styles.container} onPress={this.focusOff}>
        <TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
          <View>
            <TextInput
              ref="numberInput"
              id={this.props.id}
              style={styles.title}
              keyboardType="numeric"
              maxLength={2}
              value={this.state.keys.toString()}
              onChange={(event) =>
                this.updateKeysWithInputHandler(event.nativeEvent.text)
              }
            />
          </View>
        </TouchableWithoutFeedback>
      </View>
    );
  }
}

最佳答案

您需要将父容器的 dimensions/flex 传递给 TouchableWithoutFeedback 才能使其正常工作。

假设您的 styles.container 中有 flex: 1,添加

<TouchableWithoutFeedback style={{flex: 1}} onPress={Keyboard.dismiss} accessible={false}>

到您的子组件,以便它继承 flex

关于javascript - 通过在其外部点击来模糊 <TextInput/>,在 native react 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50211451/

相关文章:

javascript - Jasmine 规范超时。重置 WebDriver 控制流 - 当重定向到新页面时

javascript - 使用 VSCode 的更漂亮的 react/jsx-max-props-per-line 格式

android - 网络请求在生产应用程序中开始失败,WIFI 上没有有效的 NAT64 前缀错误,但适用于移动数据,仅限 Android

javascript - 如何将文本放在图像上

javascript - 用于压缩 javascript 和缩小图像的 Windows 程序

javascript - 居中对齐 ul 中 li 的内容

javascript - JS自动滚动

javascript - 无法读取 "undefined"的属性,即使对象已定义! [ react ]

javascript - 您应该在构造函数中定义组件状态的所有属性吗?

css - react native 图像 resizeMode : How to avoid blanks