1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-03-05 13:21:25 -05:00

Fix jump to character for Collections and Discover

Fix for a regression introduced in react-virtualized 9.21.2 when WindowScroller is used with Grids
This commit is contained in:
Bogdan
2025-05-22 15:39:29 +03:00
parent b823ad8e65
commit 159f5df8cc
4 changed files with 81 additions and 11 deletions

View File

@@ -92,15 +92,14 @@ class CollectionOverviews extends Component {
if (this._grid && scrollTop !== 0 && !scrollRestored) { if (this._grid && scrollTop !== 0 && !scrollRestored) {
this.setState({ scrollRestored: true }); this.setState({ scrollRestored: true });
this._grid.scrollToPosition({ scrollTop }); this._gridScrollToPosition({ scrollTop });
} }
if (jumpToCharacter != null && jumpToCharacter !== prevProps.jumpToCharacter) { if (jumpToCharacter != null && jumpToCharacter !== prevProps.jumpToCharacter) {
const index = getIndexOfFirstCharacter(items, jumpToCharacter); const index = getIndexOfFirstCharacter(items, jumpToCharacter);
if (this._grid && index != null) { if (this._grid && index != null) {
this._gridScrollToCell({
this._grid.scrollToCell({
rowIndex: index, rowIndex: index,
columnIndex: 0 columnIndex: 0
}); });
@@ -186,6 +185,19 @@ class CollectionOverviews extends Component {
); );
}; };
_gridScrollToCell = ({ rowIndex = 0, columnIndex = 0 }) => {
const scrollOffset = this._grid.getOffsetForCell({
rowIndex,
columnIndex
});
this._gridScrollToPosition(scrollOffset);
};
_gridScrollToPosition = ({ scrollTop = 0, scrollLeft = 0 }) => {
this.props.scroller?.scrollTo({ top: scrollTop, left: scrollLeft });
};
// //
// Listeners // Listeners

View File

@@ -1,4 +1,4 @@
import React, { ReactNode, useEffect, useRef } from 'react'; import React, { ReactNode, useCallback, useEffect, useRef } from 'react';
import { Grid, GridCellProps, WindowScroller } from 'react-virtualized'; import { Grid, GridCellProps, WindowScroller } from 'react-virtualized';
import ModelBase from 'App/ModelBase'; import ModelBase from 'App/ModelBase';
import Scroller from 'Components/Scroller/Scroller'; import Scroller from 'Components/Scroller/Scroller';
@@ -79,6 +79,39 @@ function VirtualTable<T extends ModelBase>({
position: undefined, position: undefined,
}; };
const handleScrollToPosition = useCallback(
({
scrollTop = 0,
scrollLeft = 0,
}: {
scrollTop: number;
scrollLeft: number;
}) => {
scroller?.scrollTo({ top: scrollTop, left: scrollLeft });
},
[scroller]
);
const handleScrollToCell = useCallback(
({
rowIndex = 0,
columnIndex = 0,
}: {
rowIndex: number;
columnIndex: number;
}) => {
if (gridRef.current) {
const scrollOffset = gridRef.current.getOffsetForCell({
rowIndex,
columnIndex,
});
handleScrollToPosition(scrollOffset);
}
},
[gridRef, handleScrollToPosition]
);
useEffect(() => { useEffect(() => {
if (gridRef.current && width > 0) { if (gridRef.current && width > 0) {
gridRef.current.recomputeGridSize(); gridRef.current.recomputeGridSize();
@@ -97,10 +130,10 @@ function VirtualTable<T extends ModelBase>({
useEffect(() => { useEffect(() => {
if (gridRef.current && scrollTop && !scrollRestored.current) { if (gridRef.current && scrollTop && !scrollRestored.current) {
gridRef.current.scrollToPosition({ scrollLeft: 0, scrollTop }); handleScrollToPosition({ scrollLeft: 0, scrollTop });
scrollRestored.current = true; scrollRestored.current = true;
} }
}, [scrollTop]); }, [scrollTop, handleScrollToPosition]);
useEffect(() => { useEffect(() => {
if ( if (
@@ -108,12 +141,12 @@ function VirtualTable<T extends ModelBase>({
scrollIndex != null && scrollIndex != null &&
scrollIndex !== previousScrollIndex scrollIndex !== previousScrollIndex
) { ) {
gridRef.current.scrollToCell({ handleScrollToCell({
rowIndex: scrollIndex, rowIndex: scrollIndex,
columnIndex: 0, columnIndex: 0,
}); });
} }
}, [scrollIndex, previousScrollIndex]); }, [scrollIndex, previousScrollIndex, handleScrollToCell]);
return ( return (
<WindowScroller scrollElement={isSmallScreen ? undefined : scroller}> <WindowScroller scrollElement={isSmallScreen ? undefined : scroller}>

View File

@@ -95,8 +95,7 @@ class DiscoverMovieOverviews extends Component {
const index = getIndexOfFirstCharacter(items, jumpToCharacter); const index = getIndexOfFirstCharacter(items, jumpToCharacter);
if (this._grid && index != null) { if (this._grid && index != null) {
this._gridScrollToCell({
this._grid.scrollToCell({
rowIndex: index, rowIndex: index,
columnIndex: 0 columnIndex: 0
}); });
@@ -182,6 +181,19 @@ class DiscoverMovieOverviews extends Component {
); );
}; };
_gridScrollToCell = ({ rowIndex = 0, columnIndex = 0 }) => {
const scrollOffset = this._grid.getOffsetForCell({
rowIndex,
columnIndex
});
this._gridScrollToPosition(scrollOffset);
};
_gridScrollToPosition = ({ scrollTop = 0, scrollLeft = 0 }) => {
this.props.scroller?.scrollTo({ top: scrollTop, left: scrollLeft });
};
// //
// Listeners // Listeners

View File

@@ -170,7 +170,7 @@ class DiscoverMoviePosters extends Component {
if (this._grid && index != null) { if (this._grid && index != null) {
const row = Math.floor(index / columnCount); const row = Math.floor(index / columnCount);
this._grid.scrollToCell({ this._gridScrollToCell({
rowIndex: row, rowIndex: row,
columnIndex: 0 columnIndex: 0
}); });
@@ -271,6 +271,19 @@ class DiscoverMoviePosters extends Component {
); );
}; };
_gridScrollToCell = ({ rowIndex = 0, columnIndex = 0 }) => {
const scrollOffset = this._grid.getOffsetForCell({
rowIndex,
columnIndex
});
this._gridScrollToPosition(scrollOffset);
};
_gridScrollToPosition = ({ scrollTop = 0, scrollLeft = 0 }) => {
this.props.scroller?.scrollTo({ top: scrollTop, left: scrollLeft });
};
// //
// Listeners // Listeners