File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed
packages/react-native-web/src/exports/Dimensions Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,29 @@ function update() {
5252 }
5353
5454 const win = window ;
55- const docEl = win . document . documentElement ;
55+ let height ;
56+ let width ;
57+
58+ /**
59+ * iOS does not update viewport dimensions on keyboard open/close.
60+ * window.visualViewport(https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport)
61+ * is used instead of document.documentElement.clientHeight (which remains as a fallback)
62+ */
63+ if ( win . visualViewport ) {
64+ const visualViewport = win . visualViewport ;
65+ height = Math . round ( visualViewport . height ) ;
66+ width = Math . round ( visualViewport . width ) ;
67+ } else {
68+ const docEl = win . document . documentElement ;
69+ height = docEl . clientHeight ;
70+ width = docEl . clientWidth ;
71+ }
5672
5773 dimensions . window = {
5874 fontScale : 1 ,
59- height : docEl . clientHeight ,
75+ height,
6076 scale : win . devicePixelRatio || 1 ,
61- width : docEl . clientWidth
77+ width
6278 } ;
6379
6480 dimensions . screen = {
@@ -128,5 +144,9 @@ export default class Dimensions {
128144}
129145
130146if ( canUseDOM ) {
131- window . addEventListener ( 'resize' , handleResize , false ) ;
147+ if ( window . visualViewport ) {
148+ window . visualViewport . addEventListener ( 'resize' , handleResize , false ) ;
149+ } else {
150+ window . addEventListener ( 'resize' , handleResize , false ) ;
151+ }
132152}
You can’t perform that action at this time.
0 commit comments