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

feat(MdRipple): multiple waves #1419

Merged
merged 4 commits into from
Jan 23, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/components/MdRipple/MdRipple.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
<template>
<div
class="md-ripple"
:class="rippleClasses"
:class="['md-ripple', rippleClasses]"
@touchstart.passive.stop="touchStartCheck"
@touchmove.passive.stop="touchMoveCheck"
@mousedown.passive.stop="startRipple">
@touchend.passive.stop="clearWave"
@mousedown.passive.stop="startRipple"
@mouseup.passive.stop="clearWave">
<slot />

<transition name="md-ripple" @after-enter="clearWave" v-if="!isDisabled">
<span class="md-ripple-wave" :class="waveClasses" :style="waveStyles" v-if="animating" ref="rippleWave" />
</transition>
<transition-group name="md-ripple" v-if="!isDisabled">
<span v-for="(ripple, index) in ripples" :key="'ripple'+index" :class="['md-ripple-wave', waveClasses]" :style="ripple.waveStyles" />
</transition-group>
</div>
</template>

<script>
import raf from 'raf'
import MdComponent from 'core/MdComponent'

const debounce = function (fn, delay) {
var timeoutID = null
return function () {
clearTimeout(timeoutID)
var args = arguments
var that = this
timeoutID = setTimeout(function () {
fn.apply(that, args)
}, delay)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I think this method could put it into /src/core/utils and name it MdDebounce.

It could be shorter with es6:

  const debounce = (fn, delay) => {
    let timeoutID = null
    return (...args) => {
      clearTimeout(timeoutID)
      timeoutID = setTimeout(() => fn(...args), delay)
    }
  }

export default new MdComponent({
name: 'MdRipple',
props: {
Expand All @@ -25,10 +38,9 @@
mdCentered: Boolean
},
data: () => ({
eventType: null,
waveStyles: null,
animating: false,
touchTimeout: null
ripples: [],
touchTimeout: null,
eventType: null
}),
computed: {
isDisabled () {
Expand Down Expand Up @@ -84,29 +96,26 @@
position = this.getHitPosition($event, size)
}

await this.clearWave()

this.eventType = $event.type
this.animating = true
this.applyStyles(position, size)
this.ripples.push({
animating: true,
waveStyles: this.applyStyles(position, size)
})
}
})
},
applyStyles (position, size) {
size += 'px'

this.waveStyles = {
return {
...position,
width: size,
height: size
}
},
clearWave () {
this.waveStyles = null
this.animating = false

return this.$nextTick()
},
clearWave: debounce(function () {
this.ripples = []
}, 2000),
getSize () {
const { offsetWidth, offsetHeight } = this.$el

Expand Down Expand Up @@ -161,11 +170,11 @@
transform: scale(2) translateZ(0);

&.md-centered {
animation-duration: 1.2s;
top: 50%;
left: 50%;
}

~ * {
~ *:not(.md-ripple-wave) {
position: relative;
z-index: 2;
}
Expand All @@ -175,7 +184,6 @@
transition: .8s $md-transition-stand-timing;
transition-property: opacity, transform;
will-change: opacity, transform;

&.md-centered {
transition-duration: 1.2s;
}
Expand Down