react-native中TextInput在ios平台下不能输入中文

目录

react-native 0.55.4版本,发现TextInput 在iOS平台上无法输入中文的问题。

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;

另: native-base中Input,Textarea等组件在ios平台下不能输入中文