TextInput not working as expected when programmatically entering text

三世轮回 提交于 2019-12-10 18:27:44

问题


The below code does not work properly in iOS (iPhone 6). When I press ‘Push Me’, the word is not displayed completely and the cursor is also not shown. On further investigation, I found out that onChangeText and onContentSize change are not triggered. Pressing any key on the key board after pressing the ‘Push Me’ button displays the full word. I want the full word to be displayed when the button is clicked. It works, if I use value prop to update the TextInput. But I need to display formatted text like in the ‘TokenizedTextExample’ in this link: 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>
    );
  }
}

回答1:


Removing the fixed height given to TextInput will fix the initial hidden issue.

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


来源:https://stackoverflow.com/questions/42976735/textinput-not-working-as-expected-when-programmatically-entering-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!