[fix] StyleSheet.hairlineWidth guard against missing document.body

This commit is contained in:
Nicolas Gallagher
2018-01-04 13:41:49 -08:00
parent 87fdd6c73b
commit 6d9154196e
@@ -8,13 +8,16 @@ import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
const getHairlineWidth = () => {
let hairlineWidth = 1;
if (canUseDOM && window.devicePixelRatio && window.devicePixelRatio >= 2) {
const node = document.createElement('div');
node.style.border = '.5px solid transparent';
document.body.appendChild(node);
if (node.offsetHeight === 1) {
hairlineWidth = 0.5;
const body = document.body;
if (body) {
const node = document.createElement('div');
node.style.border = '.5px solid transparent';
body.appendChild(node);
if (node.offsetHeight === 1) {
hairlineWidth = 0.5;
}
body.removeChild(node);
}
document.body.removeChild(node);
}
return hairlineWidth;
};