mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-24 15:39:15 +08:00
fix(ImagePreview): disable zoom when swiping (#11504)
This commit is contained in:
parent
9306db90ca
commit
7a42c9a616
@ -44,10 +44,10 @@ const [name, bem] = createNamespace('image-preview');
|
|||||||
|
|
||||||
const popupProps = [
|
const popupProps = [
|
||||||
'show',
|
'show',
|
||||||
|
'teleport',
|
||||||
'transition',
|
'transition',
|
||||||
'overlayStyle',
|
'overlayStyle',
|
||||||
'closeOnPopstate',
|
'closeOnPopstate',
|
||||||
'teleport'
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const imagePreviewProps = {
|
export const imagePreviewProps = {
|
||||||
@ -89,6 +89,7 @@ export default defineComponent({
|
|||||||
active: 0,
|
active: 0,
|
||||||
rootWidth: 0,
|
rootWidth: 0,
|
||||||
rootHeight: 0,
|
rootHeight: 0,
|
||||||
|
disableZoom: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const resize = () => {
|
const resize = () => {
|
||||||
@ -137,6 +138,14 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onDragStart = () => {
|
||||||
|
state.disableZoom = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDragEnd = () => {
|
||||||
|
state.disableZoom = false;
|
||||||
|
};
|
||||||
|
|
||||||
const renderImages = () => (
|
const renderImages = () => (
|
||||||
<Swipe
|
<Swipe
|
||||||
ref={swipeRef}
|
ref={swipeRef}
|
||||||
@ -148,9 +157,14 @@ export default defineComponent({
|
|||||||
showIndicators={props.showIndicators}
|
showIndicators={props.showIndicators}
|
||||||
indicatorColor="white"
|
indicatorColor="white"
|
||||||
onChange={setActive}
|
onChange={setActive}
|
||||||
|
onDragEnd={onDragEnd}
|
||||||
|
onDragStart={onDragStart}
|
||||||
>
|
>
|
||||||
{props.images.map((image, index) => (
|
{props.images.map((image, index) => (
|
||||||
<ImagePreviewItem
|
<ImagePreviewItem
|
||||||
|
v-slots={{
|
||||||
|
image: slots.image,
|
||||||
|
}}
|
||||||
src={image}
|
src={image}
|
||||||
show={props.show}
|
show={props.show}
|
||||||
active={state.active}
|
active={state.active}
|
||||||
@ -158,12 +172,10 @@ export default defineComponent({
|
|||||||
minZoom={props.minZoom}
|
minZoom={props.minZoom}
|
||||||
rootWidth={state.rootWidth}
|
rootWidth={state.rootWidth}
|
||||||
rootHeight={state.rootHeight}
|
rootHeight={state.rootHeight}
|
||||||
|
disableZoom={state.disableZoom}
|
||||||
onScale={emitScale}
|
onScale={emitScale}
|
||||||
onClose={emitClose}
|
onClose={emitClose}
|
||||||
onLongPress={() => emit('longPress', { index })}
|
onLongPress={() => emit('longPress', { index })}
|
||||||
v-slots={{
|
|
||||||
image: slots.image,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Swipe>
|
</Swipe>
|
||||||
|
@ -44,6 +44,7 @@ export default defineComponent({
|
|||||||
maxZoom: makeRequiredProp(numericProp),
|
maxZoom: makeRequiredProp(numericProp),
|
||||||
rootWidth: makeRequiredProp(Number),
|
rootWidth: makeRequiredProp(Number),
|
||||||
rootHeight: makeRequiredProp(Number),
|
rootHeight: makeRequiredProp(Number),
|
||||||
|
disableZoom: Boolean,
|
||||||
},
|
},
|
||||||
|
|
||||||
emits: ['scale', 'close', 'longPress'],
|
emits: ['scale', 'close', 'longPress'],
|
||||||
@ -146,11 +147,16 @@ export default defineComponent({
|
|||||||
|
|
||||||
const onTouchStart = (event: TouchEvent) => {
|
const onTouchStart = (event: TouchEvent) => {
|
||||||
const { touches } = event;
|
const { touches } = event;
|
||||||
|
fingerNum = touches.length;
|
||||||
|
|
||||||
|
if (fingerNum === 2 && props.disableZoom) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { offsetX } = touch;
|
const { offsetX } = touch;
|
||||||
|
|
||||||
touch.start(event);
|
touch.start(event);
|
||||||
|
|
||||||
fingerNum = touches.length;
|
|
||||||
startMoveX = state.moveX;
|
startMoveX = state.moveX;
|
||||||
startMoveY = state.moveY;
|
startMoveY = state.moveY;
|
||||||
touchStartTime = Date.now();
|
touchStartTime = Date.now();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user