Skip to content

Commit

Permalink
fix: bug #678 (#713)
Browse files Browse the repository at this point in the history
* fix:  bug #678

* Revert "fix:  bug #678"

This reverts commit 599c750.

* fix:  bug #678
  • Loading branch information
nieyunliang authored Apr 8, 2024
1 parent a08682d commit d47a767
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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

3 comments on commit d47a767

@cycyewt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 fix 计划什么时候发布新版本呢? @3lang3

@3lang3
Copy link
Owner

@3lang3 3lang3 commented on d47a767 May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cycyewt 抱歉 最近一直忙于私事,晚点我review完 今天下班时发布

@cycyewt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cycyewt 抱歉 最近一直忙于私事,晚点我review完 今天下班时发布

非常感谢

Please sign in to comment.