Skip to content

Commit

Permalink
refactor: Adjust virtualkeyboard api delay
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Feb 11, 2024
1 parent a9a932a commit 04ac06c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/ChatBotContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 04ac06c

Please sign in to comment.