Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug #678 #713

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ImagePreview = React.forwardRef<ImagePreviewRef, ImagePreviewProps>(
defaultIndex={props.startPosition}
onIndexChange={onSwipeChange}
images={props.images}
lazyload={props.lazyload}
onTap={() => {
if (!props.closeOnlyClickCloseIcon) {
onClose()
Expand Down
33 changes: 27 additions & 6 deletions packages/react-vant/src/components/image-preview/slide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { bound } from '../utils/bound'
import { rubberbandIfOutOfBounds } from '../utils/rubberband'
import clsx from 'clsx'
import { createNamespace } from '../utils'
import { LazyImageType } from '../image/PropsType'
import { getLazyImagePlaceholder } from '../image/LazyImage'
import Lazyload from '../lazyload'

type Props = {
image: string
maxZoom: number
lazyload?: LazyImageType
onTap: () => void
onZoomChange?: (zoom: number) => void
dragLockRef?: MutableRefObject<boolean>
Expand Down Expand Up @@ -145,6 +149,12 @@ export const Slide: FC<Props> = props => {
}
)

const { lazyload } = props
const renderPlaceholder = () => {
if (typeof lazyload === 'boolean') return getLazyImagePlaceholder(bem)
return lazyload.placeholder || getLazyImagePlaceholder(bem)
}

return (
<div
className={clsx(bem('slide'))}
Expand All @@ -163,12 +173,23 @@ export const Slide: FC<Props> = props => {
scale: zoom,
}}
>
<img
ref={imgRef}
src={props.image}
draggable={false}
alt={props.image}
/>
{props.lazyload ? (
<Lazyload placeholder={renderPlaceholder()}>
<img
ref={imgRef}
src={props.image}
draggable={false}
alt={props.image}
/>
</Lazyload>
) : (
<img
ref={imgRef}
src={props.image}
draggable={false}
alt={props.image}
/>
)}
</animated.div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/react-vant/src/components/image-preview/slides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { bound } from '../utils/bound'
import { createNamespace, unitToPx } from '../utils'
import clsx from 'clsx'
import { useUpdateEffect } from '../hooks'
import { LazyImageType } from '../image/PropsType'

export type SlidesType = {
images: string[]
onTap: () => void
maxZoom: number
defaultIndex: number
lazyload?: LazyImageType
onIndexChange?: (index: number) => void
}

Expand Down Expand Up @@ -98,6 +100,7 @@ export const Slides = forwardRef<SlidesRef, SlidesType>((props, ref) => {
image={image}
onTap={props.onTap}
maxZoom={props.maxZoom}
lazyload={props.lazyload}
onZoomChange={zoom => {
if (zoom !== 1) {
const index: number = Math.round(x.get() / slideWidth)
Expand Down
Loading