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;

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM