File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed
packages/react-native-web/src/exports/Dimensions Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -77,13 +77,24 @@ export default class Dimensions {
77
77
}
78
78
79
79
const win = window ;
80
- const docEl = win . document . documentElement ;
80
+ let height ;
81
+ let width ;
82
+
83
+ if ( win . visualViewport ) {
84
+ const visualViewport = win . visualViewport ;
85
+ height = Math . round ( visualViewport . height ) ;
86
+ width = Math . round ( visualViewport . width ) ;
87
+ } else {
88
+ const docEl = win . document . documentElement ;
89
+ height = docEl . clientHeight ;
90
+ width = docEl . clientWidth ;
91
+ }
81
92
82
93
dimensions . window = {
83
94
fontScale : 1 ,
84
- height : docEl . clientHeight ,
95
+ height,
85
96
scale : win . devicePixelRatio || 1 ,
86
- width : docEl . clientWidth
97
+ width
87
98
} ;
88
99
89
100
dimensions . screen = {
@@ -125,5 +136,9 @@ export default class Dimensions {
125
136
}
126
137
127
138
if ( canUseDOM ) {
128
- window . addEventListener ( 'resize' , Dimensions . _update , false ) ;
139
+ if ( window . visualViewport ) {
140
+ window . visualViewport . addEventListener ( 'resize' , Dimensions . _update , false ) ;
141
+ } else {
142
+ window . addEventListener ( 'resize' , Dimensions . _update , false ) ;
143
+ }
129
144
}
You can’t perform that action at this time.
0 commit comments