Skip to content

Commit d47a767

Browse files
authored
fix: bug #678 (#713)
* fix: bug #678 * Revert "fix: bug #678" This reverts commit 599c750. * fix: bug #678
1 parent a08682d commit d47a767

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

packages/react-vant/src/components/image-preview/ImagePreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const ImagePreview = React.forwardRef<ImagePreviewRef, ImagePreviewProps>(
5252
defaultIndex={props.startPosition}
5353
onIndexChange={onSwipeChange}
5454
images={props.images}
55+
lazyload={props.lazyload}
5556
onTap={() => {
5657
if (!props.closeOnlyClickCloseIcon) {
5758
onClose()

packages/react-vant/src/components/image-preview/slide.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { bound } from '../utils/bound'
55
import { rubberbandIfOutOfBounds } from '../utils/rubberband'
66
import clsx from 'clsx'
77
import { createNamespace } from '../utils'
8+
import { LazyImageType } from '../image/PropsType'
9+
import { getLazyImagePlaceholder } from '../image/LazyImage'
10+
import Lazyload from '../lazyload'
811

912
type Props = {
1013
image: string
1114
maxZoom: number
15+
lazyload?: LazyImageType
1216
onTap: () => void
1317
onZoomChange?: (zoom: number) => void
1418
dragLockRef?: MutableRefObject<boolean>
@@ -145,6 +149,12 @@ export const Slide: FC<Props> = props => {
145149
}
146150
)
147151

152+
const { lazyload } = props
153+
const renderPlaceholder = () => {
154+
if (typeof lazyload === 'boolean') return getLazyImagePlaceholder(bem)
155+
return lazyload.placeholder || getLazyImagePlaceholder(bem)
156+
}
157+
148158
return (
149159
<div
150160
className={clsx(bem('slide'))}
@@ -163,12 +173,23 @@ export const Slide: FC<Props> = props => {
163173
scale: zoom,
164174
}}
165175
>
166-
<img
167-
ref={imgRef}
168-
src={props.image}
169-
draggable={false}
170-
alt={props.image}
171-
/>
176+
{props.lazyload ? (
177+
<Lazyload placeholder={renderPlaceholder()}>
178+
<img
179+
ref={imgRef}
180+
src={props.image}
181+
draggable={false}
182+
alt={props.image}
183+
/>
184+
</Lazyload>
185+
) : (
186+
<img
187+
ref={imgRef}
188+
src={props.image}
189+
draggable={false}
190+
alt={props.image}
191+
/>
192+
)}
172193
</animated.div>
173194
</div>
174195
</div>

packages/react-vant/src/components/image-preview/slides.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { bound } from '../utils/bound'
66
import { createNamespace, unitToPx } from '../utils'
77
import clsx from 'clsx'
88
import { useUpdateEffect } from '../hooks'
9+
import { LazyImageType } from '../image/PropsType'
910

1011
export type SlidesType = {
1112
images: string[]
1213
onTap: () => void
1314
maxZoom: number
1415
defaultIndex: number
16+
lazyload?: LazyImageType
1517
onIndexChange?: (index: number) => void
1618
}
1719

@@ -98,6 +100,7 @@ export const Slides = forwardRef<SlidesRef, SlidesType>((props, ref) => {
98100
image={image}
99101
onTap={props.onTap}
100102
maxZoom={props.maxZoom}
103+
lazyload={props.lazyload}
101104
onZoomChange={zoom => {
102105
if (zoom !== 1) {
103106
const index: number = Math.round(x.get() / slideWidth)

0 commit comments

Comments
 (0)