react-native中TextInput在ios平台下不能输入中文
react-native 0.55.4版本,发现TextInput 在iOS平台上无法输入中文的问题。
1. github上相关资料
import React, {Component} from 'react';
import {Platform, TextInput} from 'react-native';
class MyTextInput extends Component {
  shouldComponentUpdate(nextProps){
    return Platform.OS !== 'ios' || this.props.value === nextProps.value;
  }
  render() {
    return <TextInput {...this.props} />;
  }
};
export default MyTextInput;
代码加入到项目中后,试运行了下发现果然是可以的,以为至此不能输入中文的bug,应该是破掉了。
2.需要满足defultValue和value属性
项目中由于很多都地方使用了defultValue和value属性,所以在详细的测试中发现,以上封装只能满足于value属性的情况下没问题的,那么还需要满足defultValue属性了。
以下为封装后的代码:
import React, {Component} from 'react';
import {Platform, TextInput} from 'react-native';
class MyTextInput extends Component {
  shouldComponentUpdate(nextProps) {
    const { value, defaultValue } = this.props;
    return Platform.OS !== 'ios'
    || (value === nextProps.value && !nextProps.defaultValue)
    || (defaultValue === nextProps.defaultValue && !nextProps.value);
  }
  render() {
    return <TextInput {...this.props} />;
  }
};
export default MyTextInput;
    本博客所记录的文章,主要是从网络收集的,有一些因为经过多次转载,所以出处已经不知,若是侵权,请通知我,我及时修改。本博客主要是用来记录我对所写文章的理解,若有错误,请大家指点,相互学习!

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号