mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(ImagePreview): longpress error on mobile safari (#6660)
This commit is contained in:
parent
1ee44f772a
commit
0a5f8ed37a
@ -38,6 +38,7 @@ export default {
|
||||
moveY: 0,
|
||||
moving: false,
|
||||
zooming: false,
|
||||
vertical: false,
|
||||
displayWidth: 0,
|
||||
displayHeight: 0,
|
||||
};
|
||||
@ -155,7 +156,6 @@ export default {
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (this.moving || this.zooming) {
|
||||
|
||||
stopPropagation = true;
|
||||
|
||||
if (
|
||||
@ -220,12 +220,14 @@ export default {
|
||||
const windowRatio = windowHeight / windowWidth;
|
||||
const imageRatio = naturalHeight / naturalWidth;
|
||||
|
||||
if (imageRatio < windowRatio) {
|
||||
this.displayWidth = windowWidth;
|
||||
this.displayHeight = windowWidth * imageRatio;
|
||||
} else {
|
||||
this.vertical = imageRatio > windowRatio;
|
||||
|
||||
if (this.vertical) {
|
||||
this.displayWidth = windowHeight / imageRatio;
|
||||
this.displayHeight = windowHeight;
|
||||
} else {
|
||||
this.displayWidth = windowWidth;
|
||||
this.displayHeight = windowWidth * imageRatio;
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -236,11 +238,11 @@ export default {
|
||||
};
|
||||
|
||||
return (
|
||||
<SwipeItem>
|
||||
<SwipeItem class={bem('swipe-item')}>
|
||||
<Image
|
||||
src={this.src}
|
||||
fit="contain"
|
||||
class={bem('image')}
|
||||
class={bem('image', { vertical: this.vertical })}
|
||||
style={this.imageStyle}
|
||||
scopedSlots={imageSlots}
|
||||
onLoad={this.onLoad}
|
||||
|
@ -9,6 +9,12 @@
|
||||
|
||||
&__swipe {
|
||||
height: 100%;
|
||||
|
||||
&-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
&__cover {
|
||||
@ -18,13 +24,14 @@
|
||||
}
|
||||
|
||||
&__image {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
transition-property: transform;
|
||||
|
||||
&--vertical {
|
||||
width: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
// disable desktop browser image drag
|
||||
-webkit-user-drag: none;
|
||||
|
@ -43,9 +43,9 @@ exports[`render image 1`] = `
|
||||
<div class="van-image-preview" name="van-fade">
|
||||
<div class="van-swipe van-image-preview__swipe">
|
||||
<div class="van-swipe__track" style="width: 0px; transition-duration: 500ms; transform: translateX(0px);">
|
||||
<div class="van-swipe-item" style="width: 0px;"></div>
|
||||
<div class="van-swipe-item" style="width: 0px;"></div>
|
||||
<div class="van-swipe-item" style="width: 0px;"></div>
|
||||
<div class="van-swipe-item van-image-preview__swipe-item" style="width: 0px;"></div>
|
||||
<div class="van-swipe-item van-image-preview__swipe-item" style="width: 0px;"></div>
|
||||
<div class="van-swipe-item van-image-preview__swipe-item" style="width: 0px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="van-image-preview__index">1 / 3</div>
|
||||
|
@ -139,6 +139,7 @@ test('double click', async () => {
|
||||
const swipe = instance.$el.querySelector('.van-swipe-item');
|
||||
triggerDrag(swipe, 0, 0);
|
||||
triggerDrag(swipe, 0, 0);
|
||||
await later();
|
||||
expect(onScale).toHaveBeenCalledWith({
|
||||
index: 0,
|
||||
scale: 2,
|
||||
|
Loading…
x
Reference in New Issue
Block a user