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

ImageViewer preview component supports self-defined preview content #6825

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Jerryqun
Copy link

ImageViewer支持自定义预览 #6801

Copy link
Contributor

github-actions bot commented Feb 10, 2025

Preview is ready

@@ -67,7 +67,7 @@ const ViewWithFooter = () => {
console.log('Loading...')
}}
>
查看原图{index + 1}
{`查看${typeof image === 'string' ? '原图' : '自定义内容'}${index + 1}`}
Copy link
Member

Choose a reason for hiding this comment

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

直接改名叫 查看图片 吧,这里去做分支会把 Demo 变得复杂

export const demoImages = [
'https://images.unsplash.com/photo-1620476214170-1d8080f65cdb?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3150&q=80',
'https://images.unsplash.com/photo-1601128533718-374ffcca299b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3128&q=80',
'https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3113&q=80',
'https://images.unsplash.com/photo-1624993590528-4ee743c9896e?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=200&h=1000&q=80',
<div key={Math.random()} className={styles['render-content']}>
Copy link
Member

Choose a reason for hiding this comment

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

这个不要改,要用到自定义内容的地方复制一下数组加一个数据即可

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.69%. Comparing base (18d3b83) to head (d40b951).

Files with missing lines Patch % Lines
src/components/image-viewer/image-viewer.tsx 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6825      +/-   ##
==========================================
- Coverage   92.70%   92.69%   -0.02%     
==========================================
  Files         335      335              
  Lines        7199     7202       +3     
  Branches     1793     1771      -22     
==========================================
+ Hits         6674     6676       +2     
- Misses        490      518      +28     
+ Partials       35        8      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -82,10 +80,13 @@ export type MultiImageViewerProps = Omit<
ImageViewerProps,
'image' | 'renderFooter'
> & {
images?: string[]
images?: (string | ReactNode)[]
Copy link
Member

Choose a reason for hiding this comment

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

#6801 里不是这个意思,是渲染内容可以改,不是数据层给的就是 ReactNode。否则在组件载入的时候就需要把节点都生成一遍。参考一下 antd pc 侧的:
https://ant-design.antgroup.com/components/image-cn#image-demo-imagerender

Copy link
Author

Choose a reason for hiding this comment

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

我一开改的确实是不动image类型,参考antd的直接在单张图片渲染模式下加一个自定义渲染方法。很简单,但是感觉我现在这种方式更加灵活,应用场景更多。 可以支持图片与其他类型的混合渲染。

Copy link
Author

Choose a reason for hiding this comment

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

#6801 里不是这个意思,是渲染内容可以改,不是数据层给的就是 ReactNode。否则在组件载入的时候就需要把节点都生成一遍。参考一下 antd pc 侧的: https://ant-design.antgroup.com/components/image-cn#image-demo-imagerender

已修改

@@ -27,6 +27,8 @@ export type ImageViewerProps = {
onClose?: () => void
afterClose?: () => void
renderFooter?: (image: string) => ReactNode
imageRender?: () => ReactNode
Copy link
Member

Choose a reason for hiding this comment

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

接受一下当前 image 的 url ,否则不知道是哪一个~

Copy link
Author

Choose a reason for hiding this comment

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

接受一下当前 image 的 url ,否则不知道是哪一个~

done

Copy link
Member

Choose a reason for hiding this comment

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

这个定义看起来还是没有变哈?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants