()
| 145 | } |
| 146 | |
| 147 | function onResizeEnd(): void { |
| 148 | let viewportMeta = getMetaValue('viewport'); |
| 149 | |
| 150 | // Overlaying keyboards do not impact geometry, so there is nothing to measure. |
| 151 | // https://caniuse.com/mdn-html_elements_meta_name_viewport_interactive-widget |
| 152 | if (isAndroid() && viewportMeta?.includes('overlays-content')) { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | let time = performance.now(); |
| 157 | let screen = getTouchScreen(); |
| 158 | |
| 159 | let elapsed = time - state.startTimeStamp; |
| 160 | let delta = state.screenHeight - screen.height; |
| 161 | let rotation = state.screenAngle - screen.angle; |
| 162 | |
| 163 | // Update the screen once an open keyboard that rotated along closes. The state swap was |
| 164 | // deferred, so the old width predicts the height it should close towards. |
| 165 | if (Math.abs(rotation) % 180 && state.screenWidth - screen.height < KEYBOARD_HEIGHT) { |
| 166 | state.screenWidth = screen.width; |
| 167 | state.screenHeight = screen.height; |
| 168 | state.screenAngle = screen.angle; |
| 169 | delta = 0; |
| 170 | } |
| 171 | |
| 172 | // Update the screen if a resize happens outside the capture timeframe. We debounce |
| 173 | // because WebKit may fire its single opening resize before the focus event. |
| 174 | if (elapsed > KEYBOARD_TIMEOUT) { |
| 175 | window.clearTimeout(state.screenTimeout); |
| 176 | |
| 177 | state.screenTimeout = window.setTimeout(() => { |
| 178 | let activeElement = document.hasFocus() ? getActiveElement() : null; |
| 179 | let willKeyboardOpen = willOpenKeyboard(activeElement); |
| 180 | let screen = getTouchScreen(); |
| 181 | |
| 182 | if (Math.abs(state.screenAngle - screen.angle) % 180) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | if (state.isOpen && willKeyboardOpen) { |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | state.screenWidth = screen.width; |
| 191 | state.screenHeight = screen.height; |
| 192 | state.screenAngle = screen.angle; |
| 193 | |
| 194 | state.isOpen = false; |
| 195 | }, KEYBOARD_TIMEOUT); |
| 196 | } |
| 197 | |
| 198 | // Otherwise, record an opening if the height changed by more than our threshold. |
| 199 | // This may fail if the layout viewport changes for other reasons during this timeframe. |
| 200 | if (elapsed <= KEYBOARD_TIMEOUT && delta >= KEYBOARD_HEIGHT) { |
| 201 | state.endTimeStamp = time; |
| 202 | } |
| 203 | |
| 204 | // Store the new open state since the viewport is stable when this is reached. |
no test coverage detected