From 14679f9f34f1cbebe5483d7b67ad1a16a389ff2a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 26 Jan 2022 14:44:21 +0000 Subject: [PATCH 1/2] Fix indicator scrollbar not updating on window resize --- src/components/structures/IndicatorScrollbar.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/structures/IndicatorScrollbar.tsx b/src/components/structures/IndicatorScrollbar.tsx index 26c6879b046..307541cb0b9 100644 --- a/src/components/structures/IndicatorScrollbar.tsx +++ b/src/components/structures/IndicatorScrollbar.tsx @@ -18,6 +18,7 @@ import React, { ComponentProps, createRef } from "react"; import AutoHideScrollbar from "./AutoHideScrollbar"; import { replaceableComponent } from "../../utils/replaceableComponent"; +import UIStore, { UI_EVENTS } from "../../stores/UIStore"; interface IProps extends Omit, "onWheel"> { // If true, the scrollbar will append mx_IndicatorScrollbar_leftOverflowIndicator @@ -35,8 +36,8 @@ interface IProps extends Omit, "onWheel } interface IState { - leftIndicatorOffset: number | string; - rightIndicatorOffset: number | string; + leftIndicatorOffset: string; + rightIndicatorOffset: string; } @replaceableComponent("structures.IndicatorScrollbar") @@ -50,8 +51,8 @@ export default class IndicatorScrollbar extends React.Component super(props); this.state = { - leftIndicatorOffset: 0, - rightIndicatorOffset: 0, + leftIndicatorOffset: '0', + rightIndicatorOffset: '0', }; } @@ -79,6 +80,7 @@ export default class IndicatorScrollbar extends React.Component public componentDidMount(): void { this.checkOverflow(); + UIStore.instance.on(UI_EVENTS.Resize, this.checkOverflow); } private checkOverflow = (): void => { @@ -122,9 +124,8 @@ export default class IndicatorScrollbar extends React.Component }; public componentWillUnmount(): void { - if (this.scrollElement) { - this.scrollElement.removeEventListener("scroll", this.checkOverflow); - } + this.scrollElement?.removeEventListener("scroll", this.checkOverflow); + UIStore.instance.off(UI_EVENTS.Resize, this.checkOverflow); } private onMouseWheel = (e: React.WheelEvent): void => { From 745219c5c088f5f6ffc52e9147a7134534180133 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 26 Jan 2022 14:46:58 +0000 Subject: [PATCH 2/2] Pass all dynamic children to IndicatorScrollbar so that it knows when to check overscroll --- src/components/views/spaces/SpacePanel.tsx | 57 +++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/components/views/spaces/SpacePanel.tsx b/src/components/views/spaces/SpacePanel.tsx index 3c21c244da8..6c2bee4a3c2 100644 --- a/src/components/views/spaces/SpacePanel.tsx +++ b/src/components/views/spaces/SpacePanel.tsx @@ -18,6 +18,7 @@ import React, { ComponentProps, Dispatch, ReactNode, + RefCallback, SetStateAction, useCallback, useEffect, @@ -25,7 +26,7 @@ import React, { useRef, useState, } from "react"; -import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd"; +import { DragDropContext, Draggable, Droppable, DroppableProvidedProps } from "react-beautiful-dnd"; import classNames from "classnames"; import { Room } from "matrix-js-sdk/src/models/room"; @@ -87,12 +88,6 @@ const useSpaces = (): [Room[], MetaSpace[], Room[], SpaceKey] => { return [invites, metaSpaces, actualSpaces, activeSpace]; }; -interface IInnerSpacePanelProps { - children?: ReactNode; - isPanelCollapsed: boolean; - setPanelCollapsed: Dispatch>; -} - export const HomeButtonContextMenu = ({ onFinished, hideHeader, @@ -260,8 +255,23 @@ const metaSpaceComponentMap: Record = { [MetaSpace.Orphans]: OrphansButton, }; +interface IInnerSpacePanelProps extends DroppableProvidedProps { + children?: ReactNode; + isPanelCollapsed: boolean; + setPanelCollapsed: Dispatch>; + isDraggingOver: boolean; + innerRef: RefCallback; +} + // Optimisation based on https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/api/droppable.md#recommended-droppable--performance-optimisation -const InnerSpacePanel = React.memo(({ children, isPanelCollapsed, setPanelCollapsed }) => { +const InnerSpacePanel = React.memo(({ + children, + isPanelCollapsed, + setPanelCollapsed, + isDraggingOver, + innerRef, + ...props +}) => { const [invites, metaSpaces, actualSpaces, activeSpace] = useSpaces(); const activeSpaces = activeSpace ? [activeSpace] : []; @@ -270,7 +280,14 @@ const InnerSpacePanel = React.memo(({ children, isPanelCo return ; }); - return
+ return { metaSpacesSection } { invites.map(s => ( (({ children, isPanelCo )) } { children } -
; + ; }); const SpacePanel = () => { @@ -352,21 +369,15 @@ const SpacePanel = () => { { (provided, snapshot) => ( - - - { provided.placeholder } - - + { provided.placeholder } + ) }