fix(ImagePreview): disable zoom when swiping (#11504)

This commit is contained in:
neverland 2023-01-22 20:37:10 +08:00 committed by GitHub
parent 9306db90ca
commit 7a42c9a616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View File

@ -44,10 +44,10 @@ const [name, bem] = createNamespace('image-preview');
const popupProps = [
'show',
'teleport',
'transition',
'overlayStyle',
'closeOnPopstate',
'teleport'
] as const;
export const imagePreviewProps = {
@ -89,6 +89,7 @@ export default defineComponent({
active: 0,
rootWidth: 0,
rootHeight: 0,
disableZoom: false,
});
const resize = () => {
@ -137,6 +138,14 @@ export default defineComponent({
}
};
const onDragStart = () => {
state.disableZoom = true;
};
const onDragEnd = () => {
state.disableZoom = false;
};
const renderImages = () => (
<Swipe
ref={swipeRef}
@ -148,9 +157,14 @@ export default defineComponent({
showIndicators={props.showIndicators}
indicatorColor="white"
onChange={setActive}
onDragEnd={onDragEnd}
onDragStart={onDragStart}
>
{props.images.map((image, index) => (
<ImagePreviewItem
v-slots={{
image: slots.image,
}}
src={image}
show={props.show}
active={state.active}
@ -158,12 +172,10 @@ export default defineComponent({
minZoom={props.minZoom}
rootWidth={state.rootWidth}
rootHeight={state.rootHeight}
disableZoom={state.disableZoom}
onScale={emitScale}
onClose={emitClose}
onLongPress={() => emit('longPress', { index })}
v-slots={{
image: slots.image,
}}
/>
))}
</Swipe>

View File

@ -44,6 +44,7 @@ export default defineComponent({
maxZoom: makeRequiredProp(numericProp),
rootWidth: makeRequiredProp(Number),
rootHeight: makeRequiredProp(Number),
disableZoom: Boolean,
},
emits: ['scale', 'close', 'longPress'],
@ -146,11 +147,16 @@ export default defineComponent({
const onTouchStart = (event: TouchEvent) => {
const { touches } = event;
fingerNum = touches.length;
if (fingerNum === 2 && props.disableZoom) {
return;
}
const { offsetX } = touch;
touch.start(event);
fingerNum = touches.length;
startMoveX = state.moveX;
startMoveY = state.moveY;
touchStartTime = Date.now();