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

[TouchRipple] Abort on scroll #3407

Merged
merged 1 commit into from
Feb 22, 2016
Merged

[TouchRipple] Abort on scroll #3407

merged 1 commit into from
Feb 22, 2016

Conversation

owencm
Copy link
Contributor

@owencm owencm commented Feb 21, 2016

Fixes #2165. This change causes touch-ripple to be cancelled by default if the user begins to scroll.

This is only my second PR to this project so feedback on code and PR process are extremely appreciated.

How to verify PR

  1. Open the docs page in a mobile emulation mode, or on a mobile device
  2. Tap the leftNav menu button
  3. Scroll the menu.
  4. Observe that scrolling in this menu doesn't trigger ripples on the list-items (as prod does today), but tapping them (or holding etc) does cause the ripple.
  5. Observe the same effect on buttons - tapping them works the same as today, but starting a scroll prevents a ripple from appearing.

How it was implemented
To do this, when a touch starts we add a touchmove listener, which aborts the animation if a scroll of more than 6px is detected in the first 300ms.

To abort the animation, the relevant ripple is replaced by a clone with aborted set to true which tells it to disappear immediately when componentWillLeave is called. this.end() is then called, removing the ripple from the ReactTransitionGroup, triggering componentWillLeave.

Additional note
Note that I reduced touchRippleOpacity on list-item to 0.1 as it felt a little too dark before, and since the ripple starts really dark and eases out quickly sometimes there would be a dark flash as the animation started before it aborted. Reducing the opacity is a visual improvement IMHO, and lessens this issue. For additional polish, in the future we may want to move from an ease out animation to one where the opacity starts lower and remains there for slightly longer before fading out, which would also help with this issue.

Review on Reviewable

@mbrookes mbrookes changed the title Ripples are now aborted on scroll [TouchRipple] Abort on scroll Feb 21, 2016
@@ -665,6 +665,7 @@ const ListItem = React.createClass({
onTouchTap={primaryTogglesNestedList ? this._handleNestedListToggle : onTouchTap}
ref="enhancedButton"
style={Object.assign({}, styles.root, style)}
touchRippleOpacity={0.1}
Copy link
Member

Choose a reason for hiding this comment

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

I believe that we could use 0.1 as the default value instead of 0.16.
As far as I have looked at the code.
This is the only place where the default value is used.
So, what about removing this line and changing the default value?

@oliviertassinari
Copy link
Member

Reducing the opacity is a visual improvement IMHO

I agree with you. Having a look at material spec is enough to be convinced.
I have the same feeling for the <Tab /> component. I think that we could be using 0.1 instead of 0.3.

@@ -65,6 +73,12 @@ const TouchRipple = React.createClass({
return;
}

//If the user is swiping (not just tapping), save the position so we can
Copy link
Member

Choose a reason for hiding this comment

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

What about moving this block inside the _handleTouchStart() method?

@oliviertassinari
Copy link
Member

@owencm That looks good so far, thanks for starting this PR 👍.

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Feb 21, 2016
@oliviertassinari oliviertassinari added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Feb 21, 2016
@owencm
Copy link
Contributor Author

owencm commented Feb 21, 2016

Thanks for the swift feedback @oliviertassinari!

I've made all of those suggested changes and verified it as still working. Nice catch on the < when it should have been > by the way!

@oliviertassinari
Copy link
Member

I think that we can merge this PR 👍. Anyone else want to have a look? cc @alitaheri @newoga @mbrookes.
fevr 21 2016 23 18

@alitaheri
Copy link
Member

This is looking great 👍 Thanks a lot @owencm

alitaheri added a commit that referenced this pull request Feb 22, 2016
@alitaheri alitaheri merged commit 9708219 into mui:master Feb 22, 2016
@zannager zannager added the package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ripples fire on drag/swipe on iOS and Android
4 participants