Skip to content

Commit

Permalink
Scroll indicator full implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-lypko committed Oct 6, 2021
1 parent 2007c70 commit 700467a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Widget/Conversation/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { MessageContainer, WistiaVideoContainer, MessageWrapper, MessageScrollTo

/* - - - - - - - - - - - - - - - - - - - - - - */

const DEFAULT_WRAPPER_HEIGHT = 100;

function Message() {
const {
appState: {
Expand All @@ -34,22 +36,34 @@ function Message() {
const { animationId, wistiaMatcher } = currentMessageData;
const animation = animationId && animations[animationId];

const [animationWrapperScrollHeight, setAnimationWrapperScrollHeight] = useState(100);
const [messageWrapperScrollHeight, setMessageWrapperScrollHeight] = useState(DEFAULT_WRAPPER_HEIGHT);

const messageWrapperRef = useRef<HTMLDivElement>(null);

useEffect(() => {
setMessageWrapperScrollHeight(DEFAULT_WRAPPER_HEIGHT);
}, [currentMessageId]);

useEffect(() => {
if (messageWrapperRef.current) {
messageWrapperRef.current.scrollTop = 0;

const currentScrollHeight = messageWrapperRef.current.scrollHeight;

if (currentScrollHeight !== animationWrapperScrollHeight) {
setAnimationWrapperScrollHeight(currentScrollHeight);
if (messageWrapperScrollHeight !== 0 && currentScrollHeight !== messageWrapperScrollHeight) {
setMessageWrapperScrollHeight(currentScrollHeight);
}

messageWrapperRef.current.addEventListener('scroll', handleOnScroll);
}

return () => messageWrapperRef?.current?.removeEventListener('scroll', handleOnScroll);
});

const handleOnScroll = () => {
setMessageWrapperScrollHeight(0);
};

const renderWistiaWidget = () => {
if (wistiaMatcher) {
const widgetWidth = chatbotWidth - 30;
Expand Down Expand Up @@ -109,7 +123,7 @@ function Message() {
const renderScrollIndicator = () => {
const maxHeight = defineMessageWrapperMaxHeight(responsesCurrentBlobInfo.itemsWithin);
const physicalConditionsMatch =
maxHeight < animationWrapperScrollHeight && Math.abs(maxHeight - animationWrapperScrollHeight) > 20;
maxHeight < messageWrapperScrollHeight && Math.abs(maxHeight - messageWrapperScrollHeight) > 20;

if (!emailRequestIsAllowed && physicalConditionsMatch && !isWindows) {
return <MessageScrollToBottomIndicator items={responsesCurrentBlobInfo.itemsWithin} />;
Expand Down
12 changes: 12 additions & 0 deletions src/Widget/Conversation/Message/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ export const scrollDown = keyframes`
}
`;

const fadeIn = keyframes`
0% {
opacity: 0;
}
90% {
opacity: 0;
}
100% {
opacity: 0.6;
}`;

export const MessageScrollToBottomIndicator = styled.div<{ items: number }>`
display: flex;
position: absolute;
Expand All @@ -128,6 +139,7 @@ export const MessageScrollToBottomIndicator = styled.div<{ items: number }>`
border-radius: 10px;
border: 2px solid black;
opacity: 0.6;
animation: ${fadeIn} 3s ease-in-out;
&:before,
&:after {
Expand Down

0 comments on commit 700467a

Please sign in to comment.