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 {
7777 }
7878
7979 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+ }
8192
8293 dimensions . window = {
8394 fontScale : 1 ,
84- height : docEl . clientHeight ,
95+ height,
8596 scale : win . devicePixelRatio || 1 ,
86- width : docEl . clientWidth
97+ width
8798 } ;
8899
89100 dimensions . screen = {
@@ -125,5 +136,9 @@ export default class Dimensions {
125136}
126137
127138if ( 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+ }
129144}
You can’t perform that action at this time.
0 commit comments