如何修复键盘错误隐藏反应本机
How to fix keyboard error hiding react native
我在 Animated.View 中有一个 TextInput,只有在给定的 TouchableOpacity 上单击时才会显示。
当我输入此 TextInput 时会出现问题,当您单击每个键时键盘会隐藏和出现。
我注意到当我将属性值 = {text} onChangeText = {setText} 应用于 TextInput 时会发生这种情况。
我该如何解决?
我认为你不应该赋值。随它去。只需在 onChangeText 上设置状态。
也许你只是按照文档设置输入文本doc
它可能工作正常。
import React, { Component, useState } from 'react';
import { Text, TextInput, View } from 'react-native';
export default function PizzaTranslator() {
const [text, setText] = useState('');
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type here to translate!"
onChangeText={text => setText(text)}
defaultValue={text}
/>
<Text style={{padding: 10, fontSize: 42}}>
{text.split(' ').map((word) => word && '').join(' ')}
</Text>
</View>
);
}
我在 FlatList Footer 中的 TextInput 遇到了同样的问题,
这个讨论也可以帮助人们
我在 Animated.View 中有一个 TextInput,只有在给定的 TouchableOpacity 上单击时才会显示。 当我输入此 TextInput 时会出现问题,当您单击每个键时键盘会隐藏和出现。 我注意到当我将属性值 = {text} onChangeText = {setText} 应用于 TextInput 时会发生这种情况。 我该如何解决?
我认为你不应该赋值。随它去。只需在 onChangeText 上设置状态。
也许你只是按照文档设置输入文本doc
它可能工作正常。
import React, { Component, useState } from 'react';
import { Text, TextInput, View } from 'react-native';
export default function PizzaTranslator() {
const [text, setText] = useState('');
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type here to translate!"
onChangeText={text => setText(text)}
defaultValue={text}
/>
<Text style={{padding: 10, fontSize: 42}}>
{text.split(' ').map((word) => word && '').join(' ')}
</Text>
</View>
);
}
我在 FlatList Footer 中的 TextInput 遇到了同样的问题, 这个讨论也可以帮助人们