Skip to content

Commit

Permalink
feat(ui/ripple): determine whether to prevent ripple's fast touchmove…
Browse files Browse the repository at this point in the history
… by supporting touch events
  • Loading branch information
haoziqaq committed Mar 18, 2022
1 parent 42366db commit f859144
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
14 changes: 1 addition & 13 deletions packages/varlet-ui/src/button/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ import VarButton from '../index'
import VarIcon from '../../icon'
import AppType from '@varlet/cli/site/mobile/components/AppType'
import Snackbar from '../../snackbar'
import context from '../../context'
import dark from '../../themes/dark'
import { pack, use } from './locale'
import { watchLang, watchPlatform, watchDarkMode } from '@varlet/cli/site/utils'
import { onUnmounted } from 'vue'
import { watchLang, watchDarkMode } from '@varlet/cli/site/utils'
export default {
components: {
Expand All @@ -96,16 +94,6 @@ export default {
watchLang(use)
watchDarkMode(dark)
const prevTouchmoveForbid = context.touchmoveForbid
watchPlatform((platform) => {
if (platform === 'pc') {
context.touchmoveForbid = false
}
})
onUnmounted(() => {
context.touchmoveForbid = prevTouchmoveForbid
})
return {
pack,
handleClick,
Expand Down
6 changes: 6 additions & 0 deletions packages/varlet-ui/src/ripple/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import context from '../context'
import './ripple.less'
import '../styles/common.less'
import { supportTouch } from '../utils/elements'
import type { Directive, Plugin, App } from 'vue'
import type { DirectiveBinding } from '@vue/runtime-core'

Expand Down Expand Up @@ -113,6 +114,11 @@ function removeRipple(this: RippleHTMLElement) {

function forbidRippleTask(this: RippleHTMLElement) {
const _ripple = this._ripple as RippleOptions

if (!supportTouch()) {
return
}

if (!_ripple.touchmoveForbid) {
return
}
Expand Down
5 changes: 5 additions & 0 deletions packages/varlet-ui/src/utils/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,8 @@ export function formatStyleVars(styleVars: StyleVars | null) {
return styles
}, {} as StyleVars)
}

export function supportTouch() {
const inBrowser = typeof window !== 'undefined'
return inBrowser && 'ontouchstart' in window
}

0 comments on commit f859144

Please sign in to comment.