Middle Column: Fixing the keyboard hiding issue on iOs (#3488)

This commit is contained in:
Alexander Zinchuk 2023-07-05 13:16:28 +02:00
parent 9e5e3ab196
commit 332ae408a4
2 changed files with 17 additions and 3 deletions

View File

@ -1,7 +1,7 @@
import React, {
useEffect, useState, memo, useMemo,
} from '../../lib/teact/teact';
import { requestMutation } from '../../lib/fasterdom/fasterdom';
import { requestMeasure, requestMutation } from '../../lib/fasterdom/fasterdom';
import { getActions, withGlobal } from '../../global';
import type { ApiChat, ApiChatBannedRights } from '../../api/types';
@ -304,6 +304,14 @@ function MiddleColumn({
requestMutation(() => {
document.body.classList.toggle('keyboard-visible', isFixNeeded);
requestMeasure(() => {
if (!isFixNeeded && visualViewport.offsetTop) {
requestMutation(() => {
window.scrollTo({ top: 0 });
});
}
});
});
};

View File

@ -7,16 +7,22 @@ type IDimensions = {
height: number;
};
const WINDOW_ORIENTATION_CHANGE_THROTTLE_MS = 100;
const WINDOW_RESIZE_THROTTLE_MS = 250;
const initialHeight = window.innerHeight;
let initialHeight = window.innerHeight;
let currentWindowSize = updateSizes();
const handleResize = throttle(() => {
currentWindowSize = updateSizes();
}, WINDOW_RESIZE_THROTTLE_MS, true);
window.addEventListener('orientationchange', handleResize);
const handleOrientationChange = throttle(() => {
initialHeight = window.innerHeight;
handleResize();
}, WINDOW_ORIENTATION_CHANGE_THROTTLE_MS, false);
window.addEventListener('orientationchange', handleOrientationChange);
if (IS_IOS) {
window.visualViewport!.addEventListener('resize', handleResize);
} else {