@@ -77,13 +77,30 @@ export default class Dimensions {
7777 }
7878
7979 const win = window ;
80- const docEl = win . document . documentElement ;
80+ let height ;
81+ let width ;
82+
83+ /*
84+ * iOS does not update viewport dimensions on keyboard open/close
85+ * So, we are using window.visualViewport(https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport)
86+ * instead of document.documentElement.clientHeight
87+ * document.documentElement.clientWidth is used as a fallback
88+ */
89+ if ( win . visualViewport ) {
90+ const visualViewport = win . visualViewport ;
91+ height = Math . round ( visualViewport . height ) ;
92+ width = Math . round ( visualViewport . width ) ;
93+ } else {
94+ const docEl = win . document . documentElement ;
95+ height = docEl . clientHeight ;
96+ width = docEl . clientWidth ;
97+ }
8198
8299 dimensions . window = {
83100 fontScale : 1 ,
84- height : docEl . clientHeight ,
101+ height,
85102 scale : win . devicePixelRatio || 1 ,
86- width : docEl . clientWidth
103+ width
87104 } ;
88105
89106 dimensions . screen = {
@@ -125,5 +142,13 @@ export default class Dimensions {
125142}
126143
127144if ( canUseDOM ) {
128- window . addEventListener ( 'resize' , Dimensions . _update , false ) ;
145+ /*
146+ * Same as in _update method, we are
147+ * keeping the previous implementation as a fallback
148+ */
149+ if ( window . visualViewport ) {
150+ window . visualViewport . addEventListener ( 'resize' , Dimensions . _update , false ) ;
151+ } else {
152+ window . addEventListener ( 'resize' , Dimensions . _update , false ) ;
153+ }
129154}
0 commit comments