以编程方式输入文本时 TextInput 未按预期工作

2024-04-28

以下代码在 iOS (iPhone 6) 中无法正常工作。当我按“Push Me”时,单词没有完全显示,光标也没有显示。经过进一步调查,我发现 onChangeText 和 onContentSize 更改没有被触发。按“Push Me”按钮后按键盘上的任意键将显示完整单词。我希望单击按钮时显示完整的单词。如果我使用 value 属性来更新 TextInput,它会起作用。但我需要显示格式化文本,如此链接中的“TokenizedTextExample”:https://facebook.github.io/react-native/docs/textinput.html 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

以编程方式输入文本时 TextInput 未按预期工作 的相关文章

随机推荐