mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] ImagePreview: support dbclick zoom (#3839)
This commit is contained in:
parent
7b9331aee4
commit
f50dc30484
@ -77,7 +77,8 @@ export default createComponent({
|
||||
moveY: 0,
|
||||
moving: false,
|
||||
zooming: false,
|
||||
active: 0
|
||||
active: 0,
|
||||
doubleClickTimer: null
|
||||
};
|
||||
},
|
||||
|
||||
@ -120,6 +121,8 @@ export default createComponent({
|
||||
|
||||
// prevent long tap to close component
|
||||
if (deltaTime < 300 && offsetX < 10 && offsetY < 10) {
|
||||
if (!this.doubleClickTimer) {
|
||||
this.doubleClickTimer = setTimeout(() => {
|
||||
const index = this.active;
|
||||
|
||||
this.resetScale();
|
||||
@ -131,6 +134,14 @@ export default createComponent({
|
||||
if (!this.asyncClose) {
|
||||
this.$emit('input', false);
|
||||
}
|
||||
|
||||
this.doubleClickTimer = null;
|
||||
}, 300);
|
||||
} else {
|
||||
clearTimeout(this.doubleClickTimer);
|
||||
this.doubleClickTimer = null;
|
||||
this.toggleScale();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -228,6 +239,14 @@ export default createComponent({
|
||||
this.scale = 1;
|
||||
this.moveX = 0;
|
||||
this.moveY = 0;
|
||||
},
|
||||
|
||||
toggleScale() {
|
||||
const scale = this.scale > 1 ? 1 : 2;
|
||||
|
||||
this.scale = scale;
|
||||
this.moveX = 0;
|
||||
this.moveY = 0;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -20,7 +20,7 @@ const images = [
|
||||
'https://img.yzcdn.cn/3.png'
|
||||
];
|
||||
|
||||
test('render image', () => {
|
||||
test('render image', async () => {
|
||||
const wrapper = mount(ImagePreviewVue, {
|
||||
propsData: { images, value: true }
|
||||
});
|
||||
@ -31,6 +31,9 @@ test('render image', () => {
|
||||
triggerDrag(swipe, 500, 0);
|
||||
expect(wrapper.emitted('input')).toBeFalsy();
|
||||
triggerDrag(swipe, 0, 0);
|
||||
|
||||
await later(300);
|
||||
|
||||
expect(wrapper.emitted('input')[0][0]).toBeFalsy();
|
||||
expect(wrapper.emitted('change')[0][0]).toEqual(2);
|
||||
});
|
||||
@ -64,6 +67,22 @@ test('function call', done => {
|
||||
});
|
||||
});
|
||||
|
||||
test('double click', async done => {
|
||||
const instance = ImagePreview(images);
|
||||
|
||||
const swipe = instance.$el.querySelector('.van-swipe__track');
|
||||
triggerDrag(swipe, 0, 0);
|
||||
triggerDrag(swipe, 0, 0);
|
||||
expect(instance.scale).toEqual(2);
|
||||
|
||||
await later();
|
||||
|
||||
triggerDrag(swipe, 0, 0);
|
||||
triggerDrag(swipe, 0, 0);
|
||||
expect(instance.scale).toEqual(1);
|
||||
done();
|
||||
});
|
||||
|
||||
test('onClose option', async done => {
|
||||
const onClose = jest.fn();
|
||||
const instance = ImagePreview({
|
||||
@ -75,7 +94,7 @@ test('onClose option', async done => {
|
||||
instance.$emit('input', true);
|
||||
expect(onClose).toHaveBeenCalledTimes(0);
|
||||
|
||||
await later();
|
||||
await later(300);
|
||||
|
||||
const wrapper = document.querySelector('.van-image-preview');
|
||||
const swipe = wrapper.querySelector('.van-swipe__track');
|
||||
|
Loading…
x
Reference in New Issue
Block a user