Message List: Fix notch and Scroll Down Button when navigating between chats (#1408)

This commit is contained in:
Alexander Zinchuk 2021-08-20 23:47:19 +03:00
parent 08e084344d
commit a9f990c7c9
4 changed files with 12 additions and 2 deletions

View File

@ -56,6 +56,7 @@ type OwnProps = {
type: MessageListType; type: MessageListType;
canPost: boolean; canPost: boolean;
isReady: boolean; isReady: boolean;
isActive: boolean;
onFabToggle: (shouldShow: boolean) => void; onFabToggle: (shouldShow: boolean) => void;
onNotchToggle: (shouldShow: boolean) => void; onNotchToggle: (shouldShow: boolean) => void;
hasTools?: boolean; hasTools?: boolean;
@ -110,6 +111,7 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
isGroupChat, isGroupChat,
canPost, canPost,
isReady, isReady,
isActive,
isChatWithSelf, isChatWithSelf,
isCreator, isCreator,
isBot, isBot,
@ -492,6 +494,7 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
memoFirstUnreadIdRef={memoFirstUnreadIdRef} memoFirstUnreadIdRef={memoFirstUnreadIdRef}
threadId={threadId} threadId={threadId}
type={type} type={type}
isActive={isActive}
threadTopMessageId={threadTopMessageId} threadTopMessageId={threadTopMessageId}
hasLinkedChat={hasLinkedChat} hasLinkedChat={hasLinkedChat}
isSchedule={messageGroups ? type === 'scheduled' : false} isSchedule={messageGroups ? type === 'scheduled' : false}

View File

@ -30,6 +30,7 @@ interface OwnProps {
memoFirstUnreadIdRef: { current: number | undefined }; memoFirstUnreadIdRef: { current: number | undefined };
threadId: number; threadId: number;
type: MessageListType; type: MessageListType;
isActive: boolean;
threadTopMessageId: number | undefined; threadTopMessageId: number | undefined;
hasLinkedChat: boolean | undefined; hasLinkedChat: boolean | undefined;
isSchedule: boolean; isSchedule: boolean;
@ -54,6 +55,7 @@ const MessageListContent: FC<OwnProps> = ({
memoFirstUnreadIdRef, memoFirstUnreadIdRef,
threadId, threadId,
type, type,
isActive,
threadTopMessageId, threadTopMessageId,
hasLinkedChat, hasLinkedChat,
isSchedule, isSchedule,
@ -80,6 +82,7 @@ const MessageListContent: FC<OwnProps> = ({
isUnread, isUnread,
onFabToggle, onFabToggle,
onNotchToggle, onNotchToggle,
isActive,
); );
const lang = useLang(); const lang = useLang();

View File

@ -309,7 +309,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
activeKey={currentTransitionKey} activeKey={currentTransitionKey}
shouldCleanup shouldCleanup
> >
{() => ( {(isActive) => (
<> <>
<MessageList <MessageList
key={`${renderingChatId}-${renderingThreadId}-${renderingMessageListType}`} key={`${renderingChatId}-${renderingThreadId}-${renderingMessageListType}`}
@ -321,6 +321,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
onFabToggle={setIsFabShown} onFabToggle={setIsFabShown}
onNotchToggle={setIsNotchShown} onNotchToggle={setIsNotchShown}
isReady={isReady} isReady={isReady}
isActive={isActive}
/> />
<div className={footerClassName}> <div className={footerClassName}>
{renderingCanPost && ( {renderingCanPost && (

View File

@ -22,6 +22,7 @@ export default function useScrollHooks(
isUnread: boolean, isUnread: boolean,
onFabToggle: AnyToVoidFunction, onFabToggle: AnyToVoidFunction,
onNotchToggle: AnyToVoidFunction, onNotchToggle: AnyToVoidFunction,
isActive: boolean,
) { ) {
const { loadViewportMessages } = getDispatch(); const { loadViewportMessages } = getDispatch();
@ -42,6 +43,8 @@ export default function useScrollHooks(
const fabTriggerRef = useRef<HTMLDivElement>(null); const fabTriggerRef = useRef<HTMLDivElement>(null);
const toggleScrollTools = useCallback(() => { const toggleScrollTools = useCallback(() => {
if (!isActive) return;
if (!messageIds || !messageIds.length) { if (!messageIds || !messageIds.length) {
onFabToggle(false); onFabToggle(false);
onNotchToggle(false); onNotchToggle(false);
@ -61,7 +64,7 @@ export default function useScrollHooks(
onFabToggle(isUnread ? !isAtBottom : !isNearBottom); onFabToggle(isUnread ? !isAtBottom : !isNearBottom);
onNotchToggle(!isAtBottom); onNotchToggle(!isAtBottom);
}, [messageIds, isViewportNewest, containerRef, onFabToggle, isUnread, onNotchToggle]); }, [isActive, messageIds, isViewportNewest, containerRef, onFabToggle, isUnread, onNotchToggle]);
const { const {
observe: observeIntersection, observe: observeIntersection,