Skip to content

Commit 59af091

Browse files
natewnecolas
authored andcommitted
[fix] Prevent style recalculation on pageload
Close necolas#2325
1 parent 379da30 commit 59af091

File tree

1 file changed

+6
-1
lines changed
  • packages/react-native-web/src/exports/Dimensions

1 file changed

+6
-1
lines changed

packages/react-native-web/src/exports/Dimensions/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ const dimensions = {
4545
};
4646
const listeners = {};
4747

48+
let shouldInit = canUseDOM;
49+
4850
export default class Dimensions {
4951
static get(dimension: DimensionKey): DisplayMetrics {
52+
if (shouldInit) {
53+
shouldInit = false;
54+
Dimensions._update();
55+
}
5056
invariant(dimensions[dimension], `No dimension set for key ${dimension}`);
5157
return dimensions[dimension];
5258
}
@@ -118,6 +124,5 @@ export default class Dimensions {
118124
}
119125

120126
if (canUseDOM) {
121-
Dimensions._update();
122127
window.addEventListener('resize', Dimensions._update, false);
123128
}

0 commit comments

Comments
 (0)