Solution: Compability with react-custom-scrollbars
See original GitHub issueAfter a long discussion in #143 I also took a shot at this problem and arrived to the following solution:
import React, { Component } from 'react';
import { Scrollbars } from 'react-custom-scrollbars';
import { List } from 'react-virtualized';
const SCROLL_DIRECTION_BACKWARD = -1;
const SCROLL_DIRECTION_FORWARD = 1;
const SCROLL_POSITION_CHANGE_REASON_OBSERVED = 'observed';
const listStyle = {
overflowX: false,
overflowY: false,
};
export default class SmartList extends Component {
_getScrollDirection(scrollTop) {
const {
scrollTop: oldScrollTop,
scrollDirectionVertical,
} = this.List.Grid.state;
if (scrollTop !== oldScrollTop) {
return scrollTop > oldScrollTop ?
SCROLL_DIRECTION_FORWARD :
SCROLL_DIRECTION_BACKWARD;
}
return scrollDirectionVertical;
}
handleScroll = ({ target }) => {
const {
scrollTop,
scrollLeft,
} = target;
const { Grid: grid } = this.List;
grid._debounceScrollEnded();
const scrollDirectionVertical = this._getScrollDirection(scrollTop);
const totalColumnsWidth = grid._columnSizeAndPositionManager.getTotalSize();
const totalRowsHeight = grid._rowSizeAndPositionManager.getTotalSize();
grid.setState({
isScrolling: true,
scrollDirectionVertical,
scrollTop,
scrollPositionChangeReason: SCROLL_POSITION_CHANGE_REASON_OBSERVED,
});
grid._invokeOnScrollMemoizer({ scrollLeft, scrollTop, totalColumnsWidth, totalRowsHeight });
};
List = null;
render() {
const { width, height } = this.props;
return (
<Scrollbars
autoHide
style={{ width, height }}
onScroll={this.handleScroll}
>
<List
{...this.props}
ref={instance => (this.List = instance)}
style={listStyle}
/>
</Scrollbars>
);
}
}
You can see that I’ve pretty much rewritten the _onScroll
method in https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/Grid.js#L1110
The simplest way to make this work will be to add a way to bypass the container node check in _onScroll
.
@bvaughn what do you think?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:16 (10 by maintainers)
Top Results From Across the Web
react-custom-scrollbars can't get styling to work - Stack Overflow
For the one that are struggling to figure out how to make the customization work. Know as it's mentioned in this question, you...
Read more >react-custom-scrollbars-2 - npm
Start using react-custom-scrollbars-2 in your project by running `npm i react-custom-scrollbars-2`. There are 54 other projects in the npm ...
Read more >Create an advanced scroll lock React Hook - LogRocket Blog
Learn how to create and troubleshoot a custom scroll lock React Hook on web and mobile with this comprehensive tutorial.
Read more >How To Implement Smooth Scrolling in React - DigitalOcean
Smooth scrolling is when instead of clicking on a button and being instantly taken to a different part of the same page, the...
Read more >How to Change the Position of Scrollbar using CSS
< title >Customize the scroll-bar</ title >. < style > ... GeeksforGeeks is a Computer Science ... explained computer science and.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone who struggles with
handleScrollEvent
and doesn’t understand how it is related to the code snippet above, here how it all looks with the new method. @5angel tons of 👍 to youCan this technique be used with the table and would it let the headers be fixed and only scroll the data?