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;