Skip to content
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

Allow touch scroll to be default prevented by making the handlers passive #423

Merged
merged 9 commits into from
Apr 4, 2019

Conversation

pradeepnschrodinger
Copy link
Collaborator

Description

Made the touch handler passive through addEventListener (similar to #422)
Moved event.preventDefault calls to the top so that they are always executed.

Motivation and Context

Allows event to be default prevented, and thus (hopefully) fixes

How Has This Been Tested?

Tested on our touch scroll example using chrome device tools. With the fix the page doesn't get scrolled, even when the table is already scrolled to the start/end

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@@ -25,7 +25,7 @@ class TouchScrollExample extends React.Component {
// scrolling of parent containers of FDT. This style is a work around to fix this. By applying 'none' to
// touch-action, we are disabling touch events from propagating.
const tableParentStyle = {
'touch-action': 'none'
'touchAction': 'none'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Typo.. It worked anyway, so I guess React was being lenient.

@@ -148,6 +148,7 @@ class ReactTouchHandler {
}

onTouchMove(/*object*/ event) {
event.preventDefault();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if the delta is zero, preventDefault wasn't being called. This is why the parent container / page get's scrolled
when the table is at any start/end scroll position

Copy link
Member

Choose a reason for hiding this comment

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

Will this lead to the issue where you can't scroll the parent page with your pointer over the grid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@wcjordan , Yes exactly. My reasoning was that I wouldn't want to scroll any container if the cursor is on the table. But now I agree, that it's better to have a FF control this instead (#419 (comment)). Will add

@@ -148,6 +148,7 @@ class ReactTouchHandler {
}

onTouchMove(/*object*/ event) {
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

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

Will this lead to the issue where you can't scroll the parent page with your pointer over the grid?

@@ -64,6 +64,8 @@ class ReactWheelHandler {
}

onWheel(/*object*/ event) {
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

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

Will this lead to the issue where you can't scroll the parent page with your pointer over the grid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, same as above.

@@ -456,11 +456,18 @@ class FixedDataTable extends React.Component {
}

componentWillUnmount() {
// TODO (pradeep): Remove these and pass to our table component directly after
Copy link
Member

Choose a reason for hiding this comment

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

Here's the related issue if you want to reference it:
facebook/react#6436

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks, will put.

Copy link
Collaborator Author

@pradeepnschrodinger pradeepnschrodinger left a comment

Choose a reason for hiding this comment

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

I'll have a FF control the behavior. And default it so that scroll handlers are only default prevented when scroll offsets have changed (existing behavior)

@@ -456,11 +456,18 @@ class FixedDataTable extends React.Component {
}

componentWillUnmount() {
// TODO (pradeep): Remove these and pass to our table component directly after
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks, will put.

@@ -148,6 +148,7 @@ class ReactTouchHandler {
}

onTouchMove(/*object*/ event) {
event.preventDefault();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@wcjordan , Yes exactly. My reasoning was that I wouldn't want to scroll any container if the cursor is on the table. But now I agree, that it's better to have a FF control this instead (#419 (comment)). Will add

@@ -64,6 +64,8 @@ class ReactWheelHandler {
}

onWheel(/*object*/ event) {
event.preventDefault();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, same as above.

@pradeepnschrodinger
Copy link
Collaborator Author

@wcjordan , added a flag to work around the behavior seen in #419.
I noticed that ReactWheelHandler and ReactTouchHandler accepts these flags as functions (see here and here), but I don't think we use them this way as the docs (from props) tell they must be booleans. Thoughts?

/>
</Table>
</div>
<Table
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just removed the wrapper div since the parent element and style is no longer needed

* doesn't lead to a change in scroll offsets, which is preferable if you like
* the page/container to scroll up when the table is already scrolled up max.
*/
stopScrollDefaultHandling: PropTypes.bool,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the prop name and description fine?

Copy link
Member

Choose a reason for hiding this comment

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

Could you change the term "default handled" to "bubbled to the browser default handler"?
I'd also change "disabled/unspecified" to "disabled (default when unspecified)"

Otherwise looks good.

Copy link
Member

@wcjordan wcjordan left a comment

Choose a reason for hiding this comment

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

lgtm

* doesn't lead to a change in scroll offsets, which is preferable if you like
* the page/container to scroll up when the table is already scrolled up max.
*/
stopScrollDefaultHandling: PropTypes.bool,
Copy link
Member

Choose a reason for hiding this comment

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

Could you change the term "default handled" to "bubbled to the browser default handler"?
I'd also change "disabled/unspecified" to "disabled (default when unspecified)"

Otherwise looks good.

@@ -78,7 +79,15 @@ class ReactTouchHandler {
emptyFunction.thatReturnsFalse;
}

// Can we just make this a boolean flag instead?
if (typeof preventDefault !== 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

yep, let's not support passing a function. It doesn't take args, so I can't imagine what they would be using to decide...

@pradeepnschrodinger pradeepnschrodinger merged commit 6da172b into v1.0-beta Apr 4, 2019
@pradeepnschrodinger pradeepnschrodinger deleted the Beta-Fix-Passive-Scrolls branch April 4, 2019 22:34
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.

2 participants