-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import React from 'react' | ||
import styles from './demo1.less' | ||
|
||
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']}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不要改,要用到自定义内容的地方复制一下数组加一个数据即可 |
||
自定义内容 | ||
</div>, | ||
] | ||
|
||
export const demoImage = demoImages[0] | ||
export const demoImage = demoImages[0] as string |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import classNames from 'classnames' | ||
import type { FC, ReactNode } from 'react' | ||
import React, { | ||
forwardRef, | ||
useCallback, | ||
useImperativeHandle, | ||
useRef, | ||
useState, | ||
useCallback, | ||
} from 'react' | ||
import type { FC, ReactNode } from 'react' | ||
import { mergeProps } from '../../utils/with-default-props' | ||
import { | ||
GetContainer, | ||
renderToContainer, | ||
} from '../../utils/render-to-container' | ||
import { mergeProps } from '../../utils/with-default-props' | ||
import Mask from '../mask' | ||
import SafeArea from '../safe-area' | ||
import { Slide } from './slide' | ||
import { Slides, SlidesRef } from './slides' | ||
import classNames from 'classnames' | ||
|
||
const classPrefix = `adm-image-viewer` | ||
|
||
export type ImageViewerProps = { | ||
image?: string | ||
image?: ReactNode | ||
maxZoom?: number | 'auto' | ||
getContainer?: GetContainer | ||
visible?: boolean | ||
onClose?: () => void | ||
afterClose?: () => void | ||
renderFooter?: (image: string) => ReactNode | ||
renderFooter?: (image: ReactNode) => ReactNode | ||
classNames?: { | ||
mask?: string | ||
body?: string | ||
|
@@ -57,13 +57,11 @@ export const ImageViewer: FC<ImageViewerProps> = p => { | |
props?.classNames?.body | ||
)} | ||
> | ||
{props.image && ( | ||
<Slide | ||
image={props.image} | ||
onTap={props.onClose} | ||
maxZoom={props.maxZoom} | ||
/> | ||
)} | ||
<Slide | ||
image={props.image} | ||
onTap={props.onClose} | ||
maxZoom={props.maxZoom} | ||
/> | ||
</div> | ||
{props.image && ( | ||
<div className={`${classPrefix}-footer`}> | ||
|
@@ -82,10 +80,13 @@ export type MultiImageViewerProps = Omit< | |
ImageViewerProps, | ||
'image' | 'renderFooter' | ||
> & { | ||
images?: string[] | ||
images?: (string | ReactNode)[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #6801 里不是这个意思,是渲染内容可以改,不是数据层给的就是 ReactNode。否则在组件载入的时候就需要把节点都生成一遍。参考一下 antd pc 侧的: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我一开改的确实是不动image类型,参考antd的直接在单张图片渲染模式下加一个自定义渲染方法。很简单,但是感觉我现在这种方式更加灵活,应用场景更多。 可以支持图片与其他类型的混合渲染。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
已修改 |
||
defaultIndex?: number | ||
onIndexChange?: (index: number) => void | ||
renderFooter?: (image: string, index: number) => ReactNode | ||
renderFooter?: ( | ||
image: string | ReactNode | undefined, | ||
index: number | ||
) => ReactNode | ||
} | ||
|
||
const multiDefaultProps = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接改名叫
查看图片
吧,这里去做分支会把 Demo 变得复杂