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
ayangweb committed Mar 20, 2022
1 parent b688380 commit 719637c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
15 changes: 1 addition & 14 deletions packages/varlet-vue2-ui/src/button/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@
import VarButton from '../index'
import VarIcon from '../../icon'
import AppType from '@varlet-vue2/cli/site/mobile/components/AppType'
import context from '../../context'
import Snackbar from '../../snackbar'
import dark from '../../themes/dark'
import { pack, use } from './locale'
import { watchLang, watchPlatform, watchDarkMode } from '@varlet-vue2/cli/site/utils'
import { watchLang, watchDarkMode } from '@varlet-vue2/cli/site/utils'
export default {
name: 'ButtonExample',
Expand All @@ -91,18 +90,6 @@ export default {
created() {
watchLang(this, use)
watchDarkMode(this, dark)
const prevTouchmoveForbid = context.touchmoveForbid
watchPlatform(this, (platform) => {
if (platform === 'pc') {
context.touchmoveForbid = false
}
})
this.$on('hook:beforeDestroy', () => {
context.touchmoveForbid = prevTouchmoveForbid
})
},
methods: {
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-vue2-ui/src/collapse-item/collapseItem.less
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@collapse-background: #fff;
@collapse-text-color: #232222;
@collapse-header-font-size: var(--font-size-lg);
@collapse-header-padding: 10px 16px;
@collapse-header-padding: 10px 12px;
@collapse-content-font-size: var(--font-size-md);
@collapse-content-padding: 0 16px 10px;
@collapse-content-padding: 0 12px 10px;
@collapse-item-margin-top: 16px;
@collapse-disable-color: #bdbdbd;
@collapse-border-top: thin solid rgba(0, 0, 0, 0.12);
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-vue2-ui/src/collapse/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ Here are the CSS variables used by the component, Styles can be customized using
| `--collapse-background` | `#fff` |
| `--collapse-text-color` | `#232222` |
| `--collapse-header-font-size` | `var(--font-size-lg)` |
| `--collapse-header-padding` | `10px 16px` |
| `--collapse-header-padding` | `10px 12px` |
| `--collapse-content-font-size` | `var(--font-size-md)` |
| `--collapse-content-font-size` | `14px` |
| `--collapse-content-padding` | `0 12px 10px` |
| `--collapse-item-margin-top` | `16px` |
| `--collapse-disable-color` | `#bdbdbd` |
| `--collapse-border-top` | `thin solid rgba(0, 0, 0, 0.12)` |
4 changes: 2 additions & 2 deletions packages/varlet-vue2-ui/src/collapse/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export default {
| `--collapse-background` | `#fff` |
| `--collapse-text-color` | `#232222` |
| `--collapse-header-font-size` | `var(--font-size-lg)` |
| `--collapse-header-padding` | `10px 16px` |
| `--collapse-header-padding` | `10px 12px` |
| `--collapse-content-font-size` | `var(--font-size-md)` |
| `--collapse-content-font-size` | `14px` |
| `--collapse-content-padding` | `0 12px 10px` |
| `--collapse-item-margin-top` | `16px` |
| `--collapse-disable-color` | `#bdbdbd` |
| `--collapse-border-top` | `thin solid rgba(0, 0, 0, 0.12)` |
1 change: 1 addition & 0 deletions packages/varlet-vue2-ui/src/ripple/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ test('test ripple disabled', async () => {
})

test('test ripple touchmove', async () => {
window.ontouchstart = true
const wrapper = mount(Wrapper, { attachTo: document.body })

await triggerDrag(wrapper, 0, 20)
Expand Down
6 changes: 6 additions & 0 deletions packages/varlet-vue2-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 { VueConstructor, DirectiveOptions, PluginObject } from 'vue'
import type { DirectiveBinding } from 'vue/types/options'

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-vue2-ui/src/utils/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export function nextTickFrame(fn: FrameRequestCallback) {
})
}

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

export async function inViewport(element: HTMLElement): Promise<boolean> {
await doubleRaf()
const { top, bottom, left, right } = element.getBoundingClientRect()
Expand Down

0 comments on commit 719637c

Please sign in to comment.