Skip to content

Nuke the Viewport component, FCize Canvas #1767

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

Merged
merged 22 commits into from
Oct 7, 2019
Merged

Conversation

nstepien
Copy link
Contributor

@nstepien nstepien commented Oct 4, 2019

No description provided.

@nstepien nstepien self-assigned this Oct 4, 2019
static displayName = 'Canvas';

readonly state: Readonly<CanvasState> = {
Copy link
Contributor

@qili26 qili26 Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe considering to move this scroll related functions to Grid? Even we use ref.current.setScrollLeft to populate the scrolling offset, we could still split the horizontal scroll bar out of the Canvas (ag-grid, airtable are all doing like this, though google sheet and Microsoft excel online is using <canvas/> for rendering the cells, scroll bar is also splitted). After viewport is removed, I think it will be easier and clearer to see the benefit for splitting the horizontal scroll bar.
bvaughn/react-virtualized#647 (comment)

In Grid.tsx, the horizontal scroll bar only sets the scrollLeft to the Grid, and it can use Header ref and Canvas ref to set scroll left so everything will be in sync. Although we don't need to do the split thing right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure I understand what you're proposing, maybe let's discuss this in another PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/adazzle/react-data-grid/pull/1757/files#diff-118f6af5f1d0d8769e6f01f4d2b33362R202

I was talking about this.

If we move the scrollLeft / scrolLTop state in Grid.tsx level, we don't need to pass the onScroll to Canvas anymore, the state in Grid.tsx would just trigger the Header setScrollLeft call. Rendering the scroll bar separately can make sure header.ref.setScrolLeft and canvas.ref.setScrollLeft being called at same time, so everything will be in sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we need a component to scroll so we can call the setScrollLeft methods, are you suggesting we add another scroll layer on top of Canvas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically not a scroll layer, it's just a div with height: 17px at the bottom of the current viewport (well, you removed it) which only handles the UI horizontal scrolling event. We know the row full width, and displaying with, so the scroll left offset will be same.

@nstepien nstepien changed the title Nuke the Viewport component Nuke the Viewport component, FCize Canvas Oct 4, 2019
@nstepien nstepien marked this pull request as ready for review October 4, 2019 16:33
@nstepien nstepien requested a review from amanmahajan7 October 4, 2019 16:34
Copy link
Contributor

@amanmahajan7 amanmahajan7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments so far, I will do a full review tomorrow. Looks good overall

if (scrollToRowIndex) {
scrollToRow(scrollToRowIndex);
}
}, [scrollToRowIndex]); // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move the scrollToRow logic here and remove eslint-disable-line react-hooks/exhaustive-deps

Copy link
Contributor Author

@nstepien nstepien Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't disable the eslint rule, we'll end up scrolling to the row every time we change any other dependency changes. 🤷‍♂

if (current) {
current.scrollTop += this.props.rowHeight + this.getClientScrollTopOffset(current);
current.scrollTop = (rowIdx + 1) * rowHeight - clientHeight;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if rowIdx < rowsCount?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could but it's not necessary. If we try to scroll to last row + 1, we'll end up scrolling to the last row anyway.

It also enables this scenario:

  • select a cell on the last row
  • scroll up, hide last row
  • press down arrow
  • we scroll back to the last row

if (!current) return;
const { rowHeight, rowsCount, height } = this.props;
current.scrollTop = Math.min(
scrollToRowIndex * rowHeight,
rowsCount * rowHeight - height
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use clientHeight instead of height here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this now.

this.scrollToColumn(idx);
};
function handleHitColummBoundary({ idx }: Position) {
scrollToColumn(idx, columnMetrics.columns);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to pass columnMetrics.columns? Can we not read it directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It simplifies the dependencies for the EventTypes.SCROLL_TO_COLUMN useEffect.

Copy link
Contributor

@amanmahajan7 amanmahajan7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@amanmahajan7 amanmahajan7 merged commit 416c944 into am-improve-props Oct 7, 2019
@amanmahajan7 amanmahajan7 deleted the ns-viewport branch October 7, 2019 13:31
nstepien added a commit that referenced this pull request Oct 7, 2019
* Replace Canvas placeholders with top/bottom padding

* Move Viewport scroll state and logic into Canvas

* Nuke Viewport component

* Nuke Viewport file

* FCize Canvas

* completely unwrap the props object

* Clean up a few props, fix tests

* Cleanup Canvas getRows

* fix new scrollLeft/Top usage in handleScroll

* Fix rowVisible{Start,End}Idx, improve top/bottom navigation accuracy

* Don't use useMemo to get the clientHeight

* Fix rowOverscanEndIdx usage

* Fix the tests

* Move handleRowSelectionChange back in the root component to prevent some row/cell re-renders

* improve isScrolling example

* Remove viewportWidth props

* Remove scrollToRow, simplify/fix scrollToRowIndex usage

* Add a comment

* Don't disable the eslint rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants