File tree 1 file changed +24
-4
lines changed
packages/react-native-web/src/exports/Dimensions
1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,29 @@ function update() {
52
52
}
53
53
54
54
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
+ }
56
72
57
73
dimensions . window = {
58
74
fontScale : 1 ,
59
- height : docEl . clientHeight ,
75
+ height,
60
76
scale : win . devicePixelRatio || 1 ,
61
- width : docEl . clientWidth
77
+ width
62
78
} ;
63
79
64
80
dimensions . screen = {
@@ -128,5 +144,9 @@ export default class Dimensions {
128
144
}
129
145
130
146
if ( 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
+ }
132
152
}
You can’t perform that action at this time.
0 commit comments