Skip to content

Commit

Permalink
Fix chat cut off on iOS with on-screen keyboard open (#362)
Browse files Browse the repository at this point in the history
* Prep setup

* Attempt with fixed header

* Revert "Attempt with fixed header"

This reverts commit 1b249a2.

* PoC with fixed height

* PoC fix

* Fix the issue

* Revert "Prep setup"

This reverts commit 761b785.
  • Loading branch information
IgorKrupenja authored Jan 2, 2025
1 parent cb1394c commit 1b18483
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/chat/chat.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@media screen and (max-width: 480px) {
.chat {
position: fixed;
top: 0;
bottom: 0;
right: 0;
height: 100dvh;
width: 100%;
Expand Down
22 changes: 21 additions & 1 deletion src/components/chat/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { motion } from "framer-motion";
import { memo, useEffect, useLayoutEffect, useState } from "react";
import { memo, useEffect, useLayoutEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Resizable, ResizeCallback } from "re-resizable";
import useChatSelector from "../../hooks/use-chat-selector";
Expand Down Expand Up @@ -85,6 +85,25 @@ const Chat = (): JSX.Element => {

const { burokrattOnlineStatus, showConfirmationModal } = useAppSelector((state) => state.widget);

const chatRef = useRef<HTMLDivElement>(null);

// Prevent chat from being cut off on iOS devices when on-screen keyboard is open
useEffect(() => {
const vv = window.visualViewport;
const currentRef = chatRef.current;

function setChatHeight() {
if (currentRef && vv && /iPhone|iPad|iPod/.test(window.navigator.userAgent)) {
currentRef.style.height = `${vv.height}px`;
}
}

vv?.addEventListener('resize', setChatHeight);
setChatHeight();

return () => vv?.removeEventListener('resize', setChatHeight);
}, []);

useEffect(() => {
if (feedback.isFeedbackRatingGiven && feedback.isFeedbackMessageGiven && !feedback.isFeedbackConfirmationShown) {
setShowFeedbackResult(true);
Expand Down Expand Up @@ -211,6 +230,7 @@ const Chat = (): JSX.Element => {
className={`${styles.chat} ${isAuthenticated ? styles.authenticated : ""}`}
animate={{ y: 0 }}
style={{ y: 400 }}
ref={chatRef}
>
<ChatHeader
isDetailSelected={showWidgetDetails}
Expand Down

0 comments on commit 1b18483

Please sign in to comment.