mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 16:28:59 +00:00
[Glitch] Allow accessing ref of ScrollContainer's child
Port 11bd515648 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -399,7 +399,7 @@ class ScrollableList extends PureComponent {
|
|||||||
|
|
||||||
if (trackScroll) {
|
if (trackScroll) {
|
||||||
return (
|
return (
|
||||||
<ScrollContainer scrollKey={scrollKey}>
|
<ScrollContainer scrollKey={scrollKey} childRef={this.setRef}>
|
||||||
{scrollableArea}
|
{scrollableArea}
|
||||||
</ScrollContainer>
|
</ScrollContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import React, { useContext, useEffect, useRef } from 'react';
|
import React, {
|
||||||
|
useContext,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useRef,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
import { defaultShouldUpdateScroll } from './default_should_update_scroll';
|
import { defaultShouldUpdateScroll } from './default_should_update_scroll';
|
||||||
import type { ShouldUpdateScrollFn } from './default_should_update_scroll';
|
import type { ShouldUpdateScrollFn } from './default_should_update_scroll';
|
||||||
@@ -11,6 +16,7 @@ interface ScrollContainerProps {
|
|||||||
*/
|
*/
|
||||||
scrollKey: string;
|
scrollKey: string;
|
||||||
shouldUpdateScroll?: ShouldUpdateScrollFn;
|
shouldUpdateScroll?: ShouldUpdateScrollFn;
|
||||||
|
childRef?: React.ForwardedRef<HTMLElement | undefined>;
|
||||||
children: React.ReactElement;
|
children: React.ReactElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,12 +29,20 @@ interface ScrollContainerProps {
|
|||||||
export const ScrollContainer: React.FC<ScrollContainerProps> = ({
|
export const ScrollContainer: React.FC<ScrollContainerProps> = ({
|
||||||
children,
|
children,
|
||||||
scrollKey,
|
scrollKey,
|
||||||
|
childRef,
|
||||||
shouldUpdateScroll = defaultShouldUpdateScroll,
|
shouldUpdateScroll = defaultShouldUpdateScroll,
|
||||||
}) => {
|
}) => {
|
||||||
const scrollBehaviorContext = useContext(ScrollBehaviorContext);
|
const scrollBehaviorContext = useContext(ScrollBehaviorContext);
|
||||||
|
|
||||||
const containerRef = useRef<HTMLElement>();
|
const containerRef = useRef<HTMLElement>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a childRef is passed, sync it with the containerRef. This
|
||||||
|
* is necessary because in this component's return statement,
|
||||||
|
* we're overwriting the immediate child component's ref prop.
|
||||||
|
*/
|
||||||
|
useImperativeHandle(childRef, () => containerRef.current, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register/unregister scrollable element with ScrollBehavior
|
* Register/unregister scrollable element with ScrollBehavior
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ class Status extends ImmutablePureComponent {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ScrollContainer scrollKey='thread' shouldUpdateScroll={this.shouldUpdateScroll}>
|
<ScrollContainer scrollKey='thread' shouldUpdateScroll={this.shouldUpdateScroll} childRef={this.setContainerRef}>
|
||||||
<div className={classNames('scrollable item-list', { fullscreen })} ref={this.setContainerRef}>
|
<div className={classNames('scrollable item-list', { fullscreen })} ref={this.setContainerRef}>
|
||||||
{ancestors}
|
{ancestors}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user