[Glitch] Fix scrolling to detailed status not always working

Port d0fd14f851 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
th-downstream
Claire 10 months ago
parent 0b2c7cdb02
commit 7cd88ae2f4

@ -610,7 +610,7 @@ class Status extends ImmutablePureComponent {
this.setState({ isExpanded: value });
};
setRef = c => {
setContainerRef = c => {
this.node = c;
};
@ -618,12 +618,16 @@ class Status extends ImmutablePureComponent {
this.column = c;
};
setStatusRef = c => {
this.statusNode = c;
};
_scrollStatusIntoView () {
const { status, multiColumn } = this.props;
if (status) {
window.requestAnimationFrame(() => {
this.node?.querySelector('.detailed-status__wrapper')?.scrollIntoView(true);
requestIdleCallback(() => {
this.statusNode?.scrollIntoView(true);
// In the single-column interface, `scrollIntoView` will put the post behind the header,
// so compensate for that.
@ -661,9 +665,8 @@ class Status extends ImmutablePureComponent {
}
// Scroll to focused post if it is loaded
const child = this.node?.querySelector('.detailed-status__wrapper');
if (child) {
return [0, child.offsetTop];
if (this.statusNode) {
return [0, this.statusNode.offsetTop];
}
// Do not scroll otherwise, `componentDidUpdate` will take care of that
@ -730,11 +733,11 @@ class Status extends ImmutablePureComponent {
/>
<ScrollContainer scrollKey='thread' shouldUpdateScroll={this.shouldUpdateScroll}>
<div className={classNames('scrollable', { fullscreen })} ref={this.setRef}>
<div className={classNames('scrollable', { fullscreen })} ref={this.setContainerRef}>
{ancestors}
<HotKeys handlers={handlers}>
<div className={classNames('focusable', 'detailed-status__wrapper', `detailed-status__wrapper-${status.get('visibility')}`)} tabIndex={0} aria-label={textForScreenReader(intl, status, false, isExpanded)}>
<div className={classNames('focusable', 'detailed-status__wrapper', `detailed-status__wrapper-${status.get('visibility')}`)} tabIndex={0} aria-label={textForScreenReader(intl, status, false, isExpanded)} ref={this.setStatusRef}>
<DetailedStatus
key={`details-${status.get('id')}`}
status={status}

Loading…
Cancel
Save