Performance 在react native中使用样式化组件是否会影响性能?
通过挖掘图书馆,我可以看到它像这样做了很多繁重的工作Performance 在react native中使用样式化组件是否会影响性能?,performance,react-native,styled-components,Performance,React Native,Styled Components,通过挖掘图书馆,我可以看到它像这样做了很多繁重的工作 散列计算 运行如此多的循环并展平对象 函数css(样式){ 对于(var\u len=arguments.length,插值=新数组(\u len>1?\u len-1:0),\u key=1;\u key
函数css(样式){
对于(var\u len=arguments.length,插值=新数组(\u len>1?\u len-1:0),\u key=1;\u key<\u len;\u key++){
插值[_-key-1]=参数[_-key];
}
if(isFunction(样式)| | isPlainObject(样式)){
//$FlowFixMe
返回平坦(交错(空数组[styles].concat(插值));
}
if(interpolations.length==0&&styles.length==1&&typeof styles[0]==string”){
//$FlowFixMe
返回样式;
}//$FlowFixMe
返回展平(交错(样式、插值));
}
那么,在没有样式化组件和css的大型react本机项目中使用样式化组件会对性能产生影响吗
function generateStyleObject(executionContext) {
var flatCSS = flatten(this.rules, executionContext).join('');
var hash = generateComponentId(flatCSS);
if (!generated[hash]) {
var root = safeParse(flatCSS);
var declPairs = [];
root.each(function (node) {
if (node.type === 'decl') {
declPairs.push([node.prop, node.value]);
} else if (process.env.NODE_ENV !== 'production' && node.type !== 'comment') {
/* eslint-disable no-console */
console.warn("Node of type " + node.type + " not supported as an inline style");
}
}); // RN currently does not support differing values for the corner radii of Image
// components (but does for View). It is almost impossible to tell whether we'll have
// support, so we'll just disable multiple values here.
// https://github.com/styled-components/css-to-react-native/issues/11
var styleObject = transformDeclPairs(declPairs, ['borderRadius', 'borderWidth', 'borderColor', 'borderStyle']);
var styles = styleSheet.create({
generated: styleObject
});
generated[hash] = styles.generated;
}
return generated[hash];
};
function css(styles) {
for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
interpolations[_key - 1] = arguments[_key];
}
if (isFunction(styles) || isPlainObject(styles)) {
// $FlowFixMe
return flatten(interleave(EMPTY_ARRAY, [styles].concat(interpolations)));
}
if (interpolations.length === 0 && styles.length === 1 && typeof styles[0] === "string") {
// $FlowFixMe
return styles;
} // $FlowFixMe
return flatten(interleave(styles, interpolations));
}