mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-02 02:25:22 +00:00
[fix] StyleSheet.hairlineWidth guard against missing document.body
This commit is contained in:
@@ -8,13 +8,16 @@ import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
|||||||
const getHairlineWidth = () => {
|
const getHairlineWidth = () => {
|
||||||
let hairlineWidth = 1;
|
let hairlineWidth = 1;
|
||||||
if (canUseDOM && window.devicePixelRatio && window.devicePixelRatio >= 2) {
|
if (canUseDOM && window.devicePixelRatio && window.devicePixelRatio >= 2) {
|
||||||
const node = document.createElement('div');
|
const body = document.body;
|
||||||
node.style.border = '.5px solid transparent';
|
if (body) {
|
||||||
document.body.appendChild(node);
|
const node = document.createElement('div');
|
||||||
if (node.offsetHeight === 1) {
|
node.style.border = '.5px solid transparent';
|
||||||
hairlineWidth = 0.5;
|
body.appendChild(node);
|
||||||
|
if (node.offsetHeight === 1) {
|
||||||
|
hairlineWidth = 0.5;
|
||||||
|
}
|
||||||
|
body.removeChild(node);
|
||||||
}
|
}
|
||||||
document.body.removeChild(node);
|
|
||||||
}
|
}
|
||||||
return hairlineWidth;
|
return hairlineWidth;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user