@@ -77,13 +77,30 @@ 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
+ /*
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
+ }
81
98
82
99
dimensions . window = {
83
100
fontScale : 1 ,
84
- height : docEl . clientHeight ,
101
+ height,
85
102
scale : win . devicePixelRatio || 1 ,
86
- width : docEl . clientWidth
103
+ width
87
104
} ;
88
105
89
106
dimensions . screen = {
@@ -125,5 +142,13 @@ export default class Dimensions {
125
142
}
126
143
127
144
if ( 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
+ }
129
154
}
0 commit comments