Message List: Fix focusing to top of tall messages
This commit is contained in:
parent
92a17c6cf1
commit
d86fb4a558
@ -156,7 +156,7 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
const memoFirstUnreadIdRef = useRef<number>();
|
||||
const memoFocusingIdRef = useRef<number>();
|
||||
const isScrollTopJustUpdatedRef = useRef(false);
|
||||
const shouldAnimateAppearanceRef = useRef(!messageIds);
|
||||
const shouldAnimateAppearanceRef = useRef(Boolean(lastMessage));
|
||||
|
||||
const [containerHeight, setContainerHeight] = useState<number | undefined>();
|
||||
const [hasFocusing, setHasFocusing] = useState<boolean>(Boolean(focusingId));
|
||||
|
||||
@ -13,7 +13,7 @@ let isAnimating = false;
|
||||
export default function fastSmoothScroll(
|
||||
container: HTMLElement,
|
||||
element: HTMLElement,
|
||||
position: ScrollLogicalPosition,
|
||||
position: ScrollLogicalPosition | 'centerOrTop',
|
||||
margin = 0,
|
||||
maxDistance = MAX_DISTANCE,
|
||||
forceDirection?: FocusDirection,
|
||||
@ -21,7 +21,15 @@ export default function fastSmoothScroll(
|
||||
forceCurrentContainerHeight?: boolean,
|
||||
) {
|
||||
if (forceDirection === FocusDirection.Static) {
|
||||
element.scrollIntoView({ block: position });
|
||||
let block!: ScrollLogicalPosition;
|
||||
|
||||
if (position === 'centerOrTop') {
|
||||
block = element.offsetHeight < container.offsetHeight ? 'center' : 'start';
|
||||
} else {
|
||||
block = position;
|
||||
}
|
||||
|
||||
element.scrollIntoView({ block });
|
||||
|
||||
return;
|
||||
}
|
||||
@ -55,7 +63,7 @@ export function isAnimatingScroll() {
|
||||
function scrollWithJs(
|
||||
container: HTMLElement,
|
||||
element: HTMLElement,
|
||||
position: ScrollLogicalPosition,
|
||||
position: ScrollLogicalPosition | 'centerOrTop',
|
||||
margin = 0,
|
||||
forceDuration?: number,
|
||||
forceCurrentContainerHeight?: boolean,
|
||||
@ -78,6 +86,7 @@ function scrollWithJs(
|
||||
// 'nearest' is not supported yet
|
||||
case 'nearest':
|
||||
case 'center':
|
||||
case 'centerOrTop':
|
||||
path = elementHeight < targetContainerHeight
|
||||
? (elementTop + elementHeight / 2) - (scrollTop + targetContainerHeight / 2)
|
||||
: (elementTop - margin) - scrollTop;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user