React Native 為全域性字型設定屬性
阿新 • • 發佈:2019-02-04
1、引入標頭檔案
import React, { Component } from 'react'
2、新增以下程式碼
/**
* 只需引入該檔案即可
* 為源型別擴充
* 自定義字型樣式, _.wrap是lodash的一個函式,用來包裹傳入的函式,然後返回一個新的函式
*/
Text.prototype.render = _.wrap(Text.prototype.render, function (func, ...args) {
let originText = func.apply(this, args);
// let newTesxt = _.cloneDeep(originText);
// originText.props.allowFontScaling = false;
// originText.props.children = 'hhh';
// return cloneElement(originText, {
// style: [
// originText.props.style,
// styles.defaultFontFamily
// ]
// });
return React.cloneElement(originText, {allowFontScaling: false });
});
提示:任意建立一個檔案,加入以上程式碼,引入標頭檔案即可