-
-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react custom scrollbar with react-window #110
Comments
This library and I don't know if something like But we can continue to chat on it if you have follow up questions 😄 |
I'll figure out something about this, I am interested in using I'll use |
@Rahul-Sagore did you end up getting custom scrollbars working with |
No, did not get time for that. Need to check and figure out. |
Not sure if @bvaughn approves this, but it seems to work: https://codesandbox.io/s/00nw2w1jv |
Better approach would be to pass const CustomScrollbars = ({ onScroll, forwardedRef, style, children }) => {
const refSetter = useCallback(scrollbarsRef => {
if (scrollbarsRef) {
forwardedRef(scrollbarsRef.view);
} else {
forwardedRef(null);
}
}, []);
return (
<Scrollbars
ref={refSetter}
style={{ ...style, overflow: "hidden" }}
onScroll={onScroll}
>
{children}
</Scrollbars>
);
};
const CustomScrollbarsVirtualList = React.forwardRef((props, ref) => (
<CustomScrollbars {...props} forwardedRef={ref} />
));
// ...
<FixedSizeList
outerElementType={CustomScrollbarsVirtualList}
{...rest}
/> |
I love how many advanced things are possible using |
I am trying to detect the scroll position at the bottom of react-window. |
You should be able to use the available ref props to ask the list for its |
I have tried to use
|
@rufoot something like this https://codesandbox.io/s/4zjwwq98j4 ? |
https://codesandbox.io/embed/jzo2lool2y When you scroll down at the bottom of react-window, then you can see one alert. |
@piecyk I have tried your solution with |
I have tried it with |
@jancama2 didn't battletested it 😂Can you share Code Sandbox when it gets laggy? |
I am using your implementation but I get an error saying forwardedRef is not a function. The problem in my app that I am trying to solve is that I have a large list of items and when I click on one, the app will redirect to another route so I need to keep track of the scroll position (probably in redux) and then set the scroll position after the route change. |
@piecyk have you tried combining it with the InfiniteLoader from My code:
Update: I don't think that it's related to the infinite scroll component. I can't get it to work with the custom scrollbar. I'd appreciate if someone can share the implementation for react-scrollbars-custom with me |
@ranihorev do you need to use that package? The code pen @piecyk shared above uses react-custom-scrollbars and works well (except when creating a ref, which for some reason is null in my code) |
Ok I need to ask again. @piecyk I am using your code sample from above (where you replied to @simjes ). instead of using a fixed sized list though, I am using the auto sizer to wrap a VariableSizeList and specify the outerElementType. Something like this: I implement the CustomScrollbars and CustomScrollbarsVirtualList the same as you have however the ref is always null. I have tried creating the ref in the component I am using the AutoSizer as well as in it's parent but it's always null. I would really appreciate some help understanding why. As I mentioned above, I need to keep track of the scroll position and be able to set it on a route change in my app so the list doesn't jump back to the top. |
@ChristopherHButler I'm already using that package multiple times in my code, so I'd rather keep using the same package. I solution is pretty similar however it doesn't fetch new data ptoperly |
@ChristopherHButler really hard to say without any Code Sandbox example of the issue, can you share something? AutoSizer or VariableSizeList will work with this approach, as in this example |
@ranihorev can you also share Code Sandbox example? |
@piecyk I create a simple (and broken) example: I also tried other variations (e.g. setting the ref to be the scroller wrapper) but no success... Thanks! |
@ranihorev this approach would be the same regardless of custom scroll implementation. They need to set reference to the same element that is responsible for scroll and handle that scroll event.
Didn't do any profiling, hope this helps 👍 |
@piecyk I am working with your demo here: https://codesandbox.io/s/4zjwwq98j4. I want to use the onScrollStop to dispatch an action in redux so I can set the scroll position (an idea from this thread: malte-wessel/react-custom-scrollbars#146 but onScrollStart and onScrollStop do not seem to work in my code or in your demo. Do you know why this is? Is there any way to pass props from the List to the Scrollbars? |
@ChristopherHButler I think your best option is to use context to pass the props, something like https://codesandbox.io/s/bvaughnreact-window-fixed-size-list-vertical-v2-usi1m --- Edited |
@piecyk that's awesome, thanks! |
@piecyk sorry I should have mentioned my implementation of the VariableSizeList is wrapped in an AutoSizer and the component which renders it is a class based component so I'm not sure I can use context. Maybe this is why I cannot get onScrollStop to work? |
Quick update: ` const mapStateToProps = state => ({ const mapDispatchToProps = dispatch => ({ export default connect(mapStateToProps, mapDispatchToProps)(BaseTree); then on componentWillUnmout I dispatch the action to set the position in redux like this:
my only issue now is being able to set the scroll position when the component re-mounts. I tried accessing the scrollTop method on this.listRef like this:
|
@ranihorev @ChristopherHButler context should work as exactly for this they are build, from docs
But yeah as mention before if you unmount the whole component on route change there is no need to pass the props. Would not store onScroll={({ scrollOffset }) => this.setState({ scrollPosition: scrollOffset })}
// to
lastScrollOffsetRef = React.createRef(0);
<List
onScroll={({ scrollOffset }) => {
this.lastScrollOffsetRef.current = scrollOffset
}}
// ...rest
/>
// then in
componentWillUnmount() {
this.props.setTreeScrollPosition(this.lastScrollOffsetRef.current);
} Regarding https://codesandbox.io/s/bvaughnreact-window-fixed-size-list-vertical-80zo7 looks like some timing problem while setting refs, maybe AutoSizer delays render of the List that makes the this.listRef.current to be undefined, hacky option is to, break from react life cycle with setTimeout, and call the ref on next tick componentDidMount() {
window.setTimeout(() => {
if (this.listRef.current) {
this.listRef.current.scrollTo(this.props.scrollPosition);
}
}, 0);
} |
@piecyk thanks a lot for the help, I really appreciate it :) |
Thanks @piecyk That seems to work. There is a slight flicker on mounting after the route change but I can live with it :) I also tried another hack which was to use the className to pass the scrollPosition and set scrollTop in the refSetter of CustomScrollbars: |
Unfortunately, all the examples in this issue do not work correctly (sometimes the mouse stops responding to scroll). But this example work perfect!
|
Did you get it done? What's the final solution? |
If this helps anyone, I've managed to make it work with OverlayScrollbars. You just need to pass the scroll event to the corresponding element. This is how:
And then, in your virtualized component:
I'm using this with Hope it helps. |
@joa-queen is this working, I am getting this error in the
|
For some reason with using this with lists it does not display all the elements, if I have 29 rows in the table it will only show 15 after scrolling to the bottom |
If someone has problem with |
I am using
react-custom-scrollbar
and would like to integrate it withFixedSizeList
.I have checked the solution on this issue on
react-virtualized
: bvaughn/react-virtualized#692 (comment)But the code is throwing error:
Uncaught TypeError: Cannot read property 'handleScrollEvent' of undefined
on scroll, in this function:I have added
ref={ instance => { this.List = instance; } }
on fixedSixe<List
component.The text was updated successfully, but these errors were encountered: