From 04ac06cc36636a5fb41da06c46139e0d8d9fe0f2 Mon Sep 17 00:00:00 2001 From: tjtanjin Date: Sun, 11 Feb 2024 21:21:56 +0800 Subject: [PATCH] refactor: Adjust virtualkeyboard api delay --- src/components/ChatBotContainer.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/ChatBotContainer.tsx b/src/components/ChatBotContainer.tsx index d619bd9e..3852c77c 100644 --- a/src/components/ChatBotContainer.tsx +++ b/src/components/ChatBotContainer.tsx @@ -137,13 +137,22 @@ const ChatBotContainer = ({ flow }: { flow: Flow }) => { const { x, y, width, height } = event.target.boundingRect; // width does not need adjustments so only height is adjusted if (x == 0 && y == 0 && width == 0 && height == 0) { + // delay added as it takes time for keyboard to appear and resize the viewport height setTimeout(() => { setViewportHeight(window.visualViewport?.height as number); - }, 501); + }, 101); + + // a second check added in case device lags and needs a later resizing + setTimeout(() => { + if (viewportHeight != window.visualViewport?.height as number) { + setViewportHeight(window.visualViewport?.height as number); + } + }, 1001); } else { + // delay added as it takes time for keyboard to disappear and resize the viewport height setTimeout(() => { setViewportHeight(window.visualViewport?.height as number - height); - }, 501); + }, 101); } }); }