mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-29 12:54:53 +08:00
[fix] Remove requestAnimationFrame from StyleManager
Using requestAnimationFrame while registering styles/classes slows down iOS/Mobile Webkit. By removing it, it's possible that we add a little bit of overhead, slowing down current cycles, but should be mostly unnoticed. Fix #517
This commit is contained in:
committed by
Nicolas Gallagher
parent
deb0a85440
commit
65d5a89040
@@ -1,7 +1,6 @@
|
|||||||
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
||||||
import generateCss from './generateCss';
|
import generateCss from './generateCss';
|
||||||
import hash from './hash';
|
import hash from './hash';
|
||||||
import requestAnimationFrame from 'fbjs/lib/requestAnimationFrame';
|
|
||||||
import staticCss from './staticCss';
|
import staticCss from './staticCss';
|
||||||
|
|
||||||
const emptyObject = {};
|
const emptyObject = {};
|
||||||
@@ -126,14 +125,12 @@ export default class StyleManager {
|
|||||||
className = createClassName(prop, value);
|
className = createClassName(prop, value);
|
||||||
this._addToCache(className, prop, value);
|
this._addToCache(className, prop, value);
|
||||||
if (canUseDOM) {
|
if (canUseDOM) {
|
||||||
requestAnimationFrame(() => {
|
const sheet = this.mainSheet.sheet;
|
||||||
const sheet = this.mainSheet.sheet;
|
// avoid injecting if the rule already exists (e.g., server rendered, hot reload)
|
||||||
// avoid injecting if the rule already exists (e.g., server rendered, hot reload)
|
if (this.mainSheet.textContent.indexOf(className) === -1) {
|
||||||
if (this.mainSheet.textContent.indexOf(className) === -1) {
|
const rule = createCssRule(className, prop, value);
|
||||||
const rule = createCssRule(className, prop, value);
|
sheet.insertRule(rule, sheet.cssRules.length);
|
||||||
sheet.insertRule(rule, sheet.cssRules.length);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return className;
|
return className;
|
||||||
|
|||||||
Reference in New Issue
Block a user