我有 <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/