-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Question: Compatibility with react-custom-scrollbars #143
Comments
Interesting suggestion @t1mmen. I've commented on the issue you linked, although unless I'm missing something... I don't initially see any changes that react-custom-scrollbars would need to make. |
I have a proof-of-concept working in a branch (issues/143). Started to integrate with The code in question is: <ScrollSync>
{({ clientHeight, clientWidth, onScroll, scrollHeight, scrollLeft, scrollTop, scrollWidth }) => {
const x = scrollLeft / (scrollWidth - clientWidth)
const y = scrollTop / (scrollHeight - clientHeight)
return (
<AutoSizer disableHeight>
{({ width }) => (
<div style={{
backgroundColor: `rgb(${Math.round(y * 255)}, ${Math.round(x * 255)}, 255)`,
color: `rgb(${Math.round(255 * y)}, ${Math.round(255 * y)}, ${Math.round(255 * y)})`,
height,
width
}}>
<Grid
className={styles.BodyGrid}
columnWidth={columnWidth}
columnsCount={columnsCount}
height={height}
onScroll={onScroll}
overscanColumnsCount={overscanColumnsCount}
overscanRowsCount={overscanRowsCount}
renderCell={this._renderBodyCell}
rowHeight={rowHeight}
rowsCount={rowsCount}
width={width}
/>
</div>
)}
</AutoSizer>
)
}}
</ScrollSync> Note that this requires 2 small changes to
|
That's looking pretty slick, good work! I'm excited to give it a try in my project! |
Great! :) I'll try to get it finished up this evening after work. (This is a side project for me so I can't do much with it during the day.) |
I completely understand @bvaughn – no rush, just thankful you've decided to take this issue on! Appreciate your hard work 👍 |
Added additional properties to ScrollSync callback to enable scroll-driven UI changes
Just released version 5.5.0 with this feature. Enjoy~ Updated demo: https://bvaughn.github.io/react-virtualized/?component=ScrollSync Source code: https://github.com/bvaughn/react-virtualized/blob/master/source/ScrollSync/ScrollSync.example.js |
Wow, that was quick :) I'll have a look at it! |
Sadly, it looks like both libraries do not work well together :( I tried two approaches:
@t1mmen Nevertheless it should be easy to implement you own scrollbars with the changes in v5.5.0. You only need to render the tracks and thumbs and update their styles like I did here |
Quick update to this issue in case anyone else sees it and is curious. react-virtualized now supports a custom renderer prop- function ({
columnMetadata:Array<Object>,
columnStartIndex: number,
columnStopIndex: number,
renderCell: Function,
rowMetadata:Array<Object>,
rowStartIndex: number,
rowStopIndex: number
}): Array<PropTypes.node>
If you're curious, you can see the default implementation here: https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/Grid.js#L729 |
Hey, thank you for your help guys, I would love for some help and love, thank you guys ! :) |
Hi @amitripshtos, RV Maybe something more or less like this? import { defaultCellRangeRenderer, Table } from 'react-virtualized'
function cellRangeRenderer (props) {
const children = defaultCellRangeRenderer(props) // Render Table rows
children.push(
// Push custom scrollbar container
)
return children
}
function renderTableWithCustomScrollbars (tableProps) {
return (
<Table
{...tableProps}
cellRangeRenderer={cellRangeRenderer}
gridStyle={{
// I'm unsure about this part because
// I'm unfamiliar with react-custom-scrollbars
overflowY: 'hidden'
}}
/>
)
} |
@amitripshtos Were you able to get these two packages to work together? Also having troubles trying to get these to work and can't quite figure it out. |
Actually I did not, just gave up and used normal scrollbar :) |
Hello to all, and sorry for my english I tried to integrate the list of react-virtualized with react-custom scrollbars. There are two div. One with the list and one with the scrollbar. So, i connected the two components' scroll action. When you scroll from List, also scrollbar's div scrolls. When you scroll from scrollbar, also the List scroll. import React from 'react';
import { Scrollbars } from 'react-custom-scrollbars';
import {
AutoSizer,
List,
} from 'react-virtualized';
import scrollbarSize from 'dom-helpers/util/scrollbarSize';
type Props = {
items: Array<*>,
height: number,
rowRender: Function,
rowHeight: number,
lightScrollbar?: boolean,
}
type State = {
scrollTop: number,
}
export default class VirtualizedListScroll extends React.Component {
props: Props;
state: State;
constructor(props: Props) {
super(props);
this.state = {
scrollTop: 0,
};
}
customScrollBar = null;
handleCustomScroll = (event: Object) => {
if (event) {
const { target } = event;
if (!(target instanceof HTMLDivElement)) {
return;
}
this.setState({ scrollTop: target.scrollTop });
}
}
handleVirtualizedScroll = (event: Object) => {
if (event && event.scrollTop) {
this.setState({ scrollTop: event.scrollTop });
if (this.customScrollBar) {
this.customScrollBar.scrollTop(event.scrollTop);
}
}
}
render() {
const propsHeight = this.props.height;
const itemsCount = this.props.items.length || 0;
const rowRender = this.props.rowRender;
const rowHeight = this.props.rowHeight;
const scrollbarColor = this.props.lightScrollbar ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.2)';
const scrollBarWidth = ((itemsCount * rowHeight) > propsHeight) ? scrollbarSize() : 0;
return (
<AutoSizer disableHeight>
{({ width }) => (
<div className="VirtualizedScroll" style={{ heigth: `${propsHeight}px`, width }}>
<List
style={{ zIndex: '1', position: 'absolute' }}
{...this.props}
width={width + scrollBarWidth}
height={propsHeight}
scrollTop={this.state.scrollTop}
rowCount={itemsCount}
rowHeight={rowHeight}
onScroll={this.handleVirtualizedScroll}
rowRenderer={rowRender}
/>
<Scrollbars
className="ScrollContent"
style={{ height: `${propsHeight}px`, width: scrollbarSize() }}
onScroll={this.handleCustomScroll}
ref={scrollbars => { this.customScrollBar = scrollbars; }}
renderThumbVertical={({ style }) => <div style={{ ...style, backgroundColor: scrollbarColor, borderRadius: '3px' }} />}
>
<div className="ScrollBarContainer" style={{ height: (itemsCount * rowHeight) }} />
</Scrollbars>
</div>
)}
</AutoSizer>
);
}
} And this is the CSS .VirtualizedScroll {
position: relative;
overflow-x: hidden;
}
.ScrollContent {
background: transparent;
z-index: 2;
float: right;
}
.ScrollBarContainer {
width: auto;
} |
@enjoyyournoise yeah, yours is too complicated and not that efficient. I've found that you can just rewrite the Grid's _onScroll method and it will work like a charm. Actually, the only thing preventing on using inner _onScroll in the first place is container node check. @bvaughn can you maybe add a second parameter to _onScroll that let you pass event from another container? |
@bvaughn Hey! I'm back at it again. Seems like integrating |
Was hoping to be able to get custom scrollbars into the table as well. @5angel did you come up with/get any suggestions for solutions around how to do this cleanly? I took a quick peek at the source and it didn't look like there was any easy way to get at wrapping the grid component in the table. |
@MrMint yeah, that was my first thought too. Well, there is a way—you might want to add That's why I asked @bvaughn if he has some thoughts already. |
Got Here is the demo: https://codesandbox.io/s/32m23wyo9m UPD: realized that |
Hi,
I opened an issue at malte-wessel/react-custom-scrollbars#30, looking for a way to leverage
react-virtualized
withreact-custom-scrollbars
.As the author @malte-wessel mentioned, this'll require changes in both libraries. He seems keen on making the changes on his end, so I'm hopeful that I can interest you in doing the same? :)
The text was updated successfully, but these errors were encountered: