1 Star 0 Fork 30

刘洋 / react-photo-view

forked from MinJieLiu / react-photo-view 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

react-photo-view

一款精致的 React 的图片预览组件

npm react-photo-view react-photo-view

Demo: https://minjieliu.github.io/react-photo-view

特性

  1. 支持左右切换导航、上/下滑关闭、双击放大/缩小、双指放大/缩小/平移、键盘导航/关闭、旋转、点击切换控件等
  2. 打开/关闭缩放动画
  3. 自适应图像适应
  4. 长图模式
  5. 支持桌面端(兼容 IE10+)/移动端
  6. 轻量的体积
  7. 高度的扩展性
  8. 支持服务端渲染
  9. 基于 typescript

开始使用

yarn add react-photo-view

基本:

import { PhotoProvider, PhotoConsumer } from 'react-photo-view';
import 'react-photo-view/dist/index.css';

function ImageView() {
  return (
    <PhotoProvider>
      {photoImages.map((item, index) => (
        <PhotoConsumer key={index} src={item} intro={item}>
          <img src={item} alt="" />
        </PhotoConsumer>
      ))}
    </PhotoProvider>
  );
}

受控 PhotoSlider

function ImageView() {
  const [visible, setVisible] = React.useState(false);
  const [photoIndex, setPhotoIndex] = React.useState(0);

  return (
    <div>
      <Button onClick={() => setVisible(true)}>打开</Button>
      <PhotoSlider
        images={photoImages.map(item => ({ src: item }))}
        visible={visible}
        onClose={() => setVisible(false)}
        index={photoIndex}
        onIndexChange={setPhotoIndex}
      />
    </div>
  );
}

API

PhotoProvider

名称 类型 必选 描述
children React.ReactNode
maskClosable boolean 背景可点击关闭,默认 true
photoClosable boolean 图片点击可关闭,默认 false
bannerVisible boolean 导航条 visible,默认 true
introVisible boolean 简介 visible,默认 true
overlayRender (overlayProps) => React.ReactNode 自定义渲染
toolbarRender (overlayProps) => React.ReactNode 工具栏渲染
className string className
maskClassName string 遮罩 className
viewClassName string 图片容器 className
imageClassName string 图片 className
loadingElement JSX.Element 自定义 loading
brokenElement JSX.Element 加载失败 Element

PhotoConsumer

名称 类型 必选 描述
src string 图片地址
intro React.ReactNode 图片介绍
children React.ReactElement

注意:若 PhotoConsumerchildren 为自定义组件

  1. 需要向外部参数暴露 React.HTMLAttributes
  2. 展开/关闭动画精准位置则需要用 React.forwardRef 暴露内部 React.ReactHTMLElement 节点的 Ref

PhotoSlider

继承自 PhotoProvider。手动控制 react-photo-view 的展现与隐藏

名称 类型 必选 描述
images dataType[] 图片列表
index number 图片当前索引
visible boolean 可见
onClose (evt) => void 关闭事件
onIndexChange Function 索引改变回调

谁在使用

MIT License Copyright (c) 2018 MinJie Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一款精致的 React 的图片预览组件,支持左右切换导航、上/下滑关闭、双击放大/缩小、双指放大/缩小/平移、键盘导航/关闭、旋转、点击切换控件 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/leau/react-photo-view.git
git@gitee.com:leau/react-photo-view.git
leau
react-photo-view
react-photo-view
master

搜索帮助