gpt4 book ai didi

react-native - 以编程方式输入文本时,TextInput 无法按预期工作

转载 作者:行者123 更新时间:2023-12-02 04:35:55 25 4
gpt4 key购买 nike

以下代码在 iOS (iPhone 6) 中无法正常运行。当我按下“Push Me”时,单词没有完全显示,光标也没有显示。在进一步调查中,我发现没有触发 onChangeText 和 onContentSize 更改。按下“Push Me”按钮后按键盘上的任意键会显示完整的单词。我希望在单击按钮时显示完整的单词。如果我使用 value prop 更新 TextInput,它就可以工作。但是我需要像这个链接中的“TokenizedTextExample”一样显示格式化文本:https://facebook.github.io/react-native/docs/textinput.html

import React, { Component } from 'react';
import {
AppRegistry,
TouchableOpacity,
TextInput,
Text,
View
} from 'react-native';

export default class keypost extends Component {
constructor(props) {
super(props);
this.state = {
part: '',
update: true
};
}


myfunc() {
this.setState({ part: <Text><Text style={{ color: 'blue' }}>"thivishnu_ks_is_good_boyo lllllll COurs uad is sfd_sdf llllsdf sfsddfadfadsfadsff dsafdfas"</Text> <Text>"fasdfa sjsjsjs jsjsjsj sjsjshshshsshshss"</Text></Text> })
}
render() {
var parts = this.state.part
return (
<View style={{ paddingTop: 50 }}>
<TextInput
multiline={true}
style={{ height: 300 }}
>
<Text>{parts}</Text>
</TextInput>
<TouchableOpacity style={{ height: 100, width: 100 }} onPress={this.myfunc.bind(this)} >
<Text style={{}}>
Push Me
</Text>
</TouchableOpacity>
</View>
);
}
}

最佳答案

移除给 TextInput 的固定高度将修复最初隐藏的问题。

   <TextInput
multiline={true}
>
<Text>{parts}</Text>
</TextInput>

关于react-native - 以编程方式输入文本时,TextInput 无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42976735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com