mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
chore(touch): add isVertical/isHorizontal
This commit is contained in:
parent
46e158fa01
commit
c8d573cbe7
@ -23,6 +23,9 @@ export function useTouch() {
|
|||||||
const offsetY = ref(0);
|
const offsetY = ref(0);
|
||||||
const direction = ref('');
|
const direction = ref('');
|
||||||
|
|
||||||
|
const isVertical = () => direction.value === 'vertical';
|
||||||
|
const isHorizontal = () => direction.value === 'horizontal';
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
deltaX.value = 0;
|
deltaX.value = 0;
|
||||||
deltaY.value = 0;
|
deltaY.value = 0;
|
||||||
@ -60,5 +63,7 @@ export function useTouch() {
|
|||||||
offsetX,
|
offsetX,
|
||||||
offsetY,
|
offsetY,
|
||||||
direction,
|
direction,
|
||||||
|
isVertical,
|
||||||
|
isHorizontal,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ export default createComponent({
|
|||||||
const onTouchMove = (event) => {
|
const onTouchMove = (event) => {
|
||||||
touch.move(event);
|
touch.move(event);
|
||||||
|
|
||||||
if (touch.direction.value === 'vertical') {
|
if (touch.isVertical()) {
|
||||||
preventDefault(event);
|
preventDefault(event);
|
||||||
|
|
||||||
const { clientX, clientY } = event.touches[0];
|
const { clientX, clientY } = event.touches[0];
|
||||||
|
@ -29,7 +29,8 @@ export default createComponent({
|
|||||||
|
|
||||||
const onTouchMove = (event) => {
|
const onTouchMove = (event) => {
|
||||||
touch.move(event);
|
touch.move(event);
|
||||||
if (touch.direction) {
|
|
||||||
|
if (touch.direction.value) {
|
||||||
active.value = false;
|
active.value = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,10 +5,6 @@ import { useLazyRender } from '../composition/use-lazy-render';
|
|||||||
|
|
||||||
const [createComponent, bem] = createNamespace('overlay');
|
const [createComponent, bem] = createNamespace('overlay');
|
||||||
|
|
||||||
function preventTouchMove(event) {
|
|
||||||
preventDefault(event, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
@ -25,6 +21,10 @@ export default createComponent({
|
|||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
const lazyRender = useLazyRender(() => props.show);
|
const lazyRender = useLazyRender(() => props.show);
|
||||||
|
|
||||||
|
const preventTouchMove = (event) => {
|
||||||
|
preventDefault(event, true);
|
||||||
|
};
|
||||||
|
|
||||||
const renderOverlay = lazyRender(() => {
|
const renderOverlay = lazyRender(() => {
|
||||||
const style = {
|
const style = {
|
||||||
zIndex: props.zIndex,
|
zIndex: props.zIndex,
|
||||||
|
@ -57,7 +57,6 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const touch = useTouch();
|
const touch = useTouch();
|
||||||
const { deltaY, direction } = touch;
|
|
||||||
|
|
||||||
const getHeadStyle = () => {
|
const getHeadStyle = () => {
|
||||||
if (props.headHeight !== DEFAULT_HEAD_HEIGHT) {
|
if (props.headHeight !== DEFAULT_HEAD_HEIGHT) {
|
||||||
@ -150,9 +149,10 @@ export default createComponent({
|
|||||||
checkPosition(event);
|
checkPosition(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { deltaY } = touch;
|
||||||
touch.move(event);
|
touch.move(event);
|
||||||
|
|
||||||
if (reachTop && deltaY.value >= 0 && direction.value === 'vertical') {
|
if (reachTop && deltaY.value >= 0 && touch.isVertical()) {
|
||||||
preventDefault(event);
|
preventDefault(event);
|
||||||
setStatus(ease(deltaY.value));
|
setStatus(ease(deltaY.value));
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onTouchEnd = () => {
|
const onTouchEnd = () => {
|
||||||
if (reachTop && deltaY.value && isTouchable()) {
|
if (reachTop && touch.deltaY.value && isTouchable()) {
|
||||||
state.duration = props.animationDuration;
|
state.duration = props.animationDuration;
|
||||||
|
|
||||||
if (state.status === 'loosing') {
|
if (state.status === 'loosing') {
|
||||||
|
@ -121,7 +121,7 @@ export default createComponent({
|
|||||||
|
|
||||||
touch.move(event);
|
touch.move(event);
|
||||||
|
|
||||||
if (touch.direction.value === 'horizontal') {
|
if (touch.isHorizontal()) {
|
||||||
const { clientX } = event.touches[0];
|
const { clientX } = event.touches[0];
|
||||||
preventDefault(event);
|
preventDefault(event);
|
||||||
select(getScoreByPosition(clientX));
|
select(getScoreByPosition(clientX));
|
||||||
|
@ -44,7 +44,6 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const touch = useTouch();
|
const touch = useTouch();
|
||||||
const { deltaX, direction } = touch;
|
|
||||||
|
|
||||||
const getWidthByRef = (ref) => (ref.value ? useRect(ref).width : 0);
|
const getWidthByRef = (ref) => (ref.value ? useRect(ref).width : 0);
|
||||||
|
|
||||||
@ -107,9 +106,10 @@ export default createComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { deltaX } = touch;
|
||||||
touch.move(event);
|
touch.move(event);
|
||||||
|
|
||||||
if (direction.value === 'horizontal') {
|
if (touch.isHorizontal()) {
|
||||||
lockClick = true;
|
lockClick = true;
|
||||||
state.dragging = true;
|
state.dragging = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user