mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-23 06:48:35 +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 = () => {
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user