• This repository has been archived on 29/Sep/2021
  • Stars
    star
    2,435
  • Rank 18,189 (Top 0.4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚀 tiny & fast lib for react native image viewer pan and zoom

Show Cases

Swiper image

Zoom while sliding

Swipe down

Getting Started

Installation

npm i react-native-image-zoom-viewer --save

Basic Usage

  • Install create-react-native-app first
$ npm install -g create-react-native-app
  • Initialization of a react-native project
$ create-react-native-app AwesomeProject
  • Then, edit AwesomeProject/App.js, like this:
import { Modal } from 'react-native';
import ImageViewer from 'react-native-image-zoom-viewer';

const images = [{
    // Simplest usage.
    url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460',

    // width: number
    // height: number
    // Optional, if you know the image size, you can set the optimization performance

    // You can pass props to <Image />.
    props: {
        // headers: ...
    }
}, {
    url: '',
    props: {
        // Or you can set source directory.
        source: require('../background.png')
    }
}]

export default class App extends React.Component {
    render: function() {
        return (
            <Modal visible={true} transparent={true}>
                <ImageViewer imageUrls={images}/>
            </Modal>
        )
    }
}

Props

parameter type required description default
imageUrls array yes Image Source
enableImageZoom boolean no Enable image zoom true
onShowModal function

(content?: JSX.Element) => void
no The callback for show modal () => {}
onCancel function

() => void
no The callback for cancel modal () => {}
flipThreshold number no Swipe threshold of the next page 80
maxOverflow number no The X position maximum, that current page can slide to the next page 300
index number no Init index of images 0
failImageSource string, object

{url: string}
no placeholder for fail ''
loadingRender function

() => React.ReactElement<any>
no placeholder for loading () => null
onSaveToCamera function

(index?: number => void
no The callback for save to camera () => {}
onChange function

(index?: number => void
no When the image changed () => {}
onMove ( position: IOnMove )=>void reports movement position data (helpful to build overlays) ()=> {}
saveToLocalByLongPress boolean no Enable save to camera when long press true
onClick function

(onCancel?: function) => void
no Onclick (onCancel) => {onCancel()}
onDoubleClick function

(onCancel?: function) => void
no OnDoubleClick (onCancel) => {onCancel()}
onSave function

(url: string) => void
no The picture is saved to the local method, if you write this method will not call the system default method for Android does not support saveToCameraRoll remote picture, you can call this callback in Android call native interface
renderHeader function

(currentIndex?: number) => React.ReactElement<any>
no Custom header () => null
renderFooter function

(currentIndex?: number) => React.ReactElement<any>
no Custom footer () => null
renderIndicator function

(currentIndex?: number, allSize?) => React.ReactElement<any>: number
no Custom indicator (currentIndex, allSize) => currentIndex + "/" + allSize
renderImage function

(props: any) => React.ReactElement<any>
no Custom image component (props) => <Image {...props} />
renderArrowLeft function

() => React.ReactElement<any>
no Custom left arrow () => null
renderArrowRight function

() => React.ReactElement<any>
no Custom right arrow () => null
onSwipeDown function

() => void
no Callback for swipe down () => null
footerContainerStyle object

{someStyle: someValue}
no custom style props for container that will be holding your footer that you pass bottom: 0, position: "absolute", zIndex: 9999
backgroundColor string

white
no Component background color black
enableSwipeDown boolean no Enable swipe down to close image viewer. When swipe down, will trigger onCancel. false
swipeDownThreshold number no Threshold for firing swipe down function
doubleClickInterval number no Double click interval.
pageAnimateTime number no Set the animation time for page flipping. 100
enablePreload boolean no Preload the next image false
useNativeDriver boolean no Whether to animate using useNativeDriver false
menus function

({cancel,saveToLocal}) => React.ReactElement<any>
no Custom menus, with 2 methods:cancel to hide menus and saveToLocal to save image to camera
menuContext object

{someKey: someValue}
no Custom menu context. { saveToLocal: 'save to the album', cancel: 'cancel' }

Development pattern

Step 1, run TS listener

After clone this repo, then:

npm install
npm start

Step 2, run demo

cd demo
npm install
npm start

Then, scan the QR, use your expo app.

Dependence

Depend on react-native-image-pan-zoom: https://github.com/ascoders/react-native-image-zoom

More Repositories

1

weekly

前端精读周刊。帮你理解最前沿、实用的技术。
JavaScript
27,747
star
2

gaea-editor

Design websites in your browser. A smart web editor!
TypeScript
1,341
star
3

react-native-image-zoom

react native image pan and zoom
TypeScript
632
star
4

syntax-parser

Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added!
TypeScript
460
star
5

alipay

golang SDK for alipay
Go
458
star
6

blog

博客
263
star
7

avatar

avalon开源中文社区
JavaScript
41
star
8

isomorphic-react-redux-app

react react-hot-loader redux redux-devtools react-router-redux immutable isomorphic
JavaScript
16
star
9

inject-instance

powerful inject instance
TypeScript
12
star
10

dependency-inject

Powerful dependency injection tool
TypeScript
10
star
11

as

基于 martini 的 go语言框架
Go
10
star
12

gaea-render

Render engine for gaea-editor
TypeScript
8
star
13

egg-typeorm

egg plugin for typeorm
JavaScript
8
star
14

woku

我酷官网~
JavaScript
5
star
15

run-react

Integrate webpack
TypeScript
5
star
16

gaea-basic-components

gaea-basic-components
TypeScript
4
star
17

client-ssr

JavaScript
3
star
18

kingdoms

三国军争服务端源代码
Go
3
star
19

gaea-web-components

Gaea 网页端基础组件
TypeScript
3
star
20

vscode-medusa

medusa plugin for vscode
TypeScript
2
star
21

woku-react

我酷科技
JavaScript
2
star
22

rc-stream

react reactive stream
TypeScript
2
star
23

woku_old

我酷旧版
JavaScript
2
star
24

machine-learning

Demos of machine learning
TypeScript
2
star
25

typed-store

Typed React bindings for Redux
TypeScript
2
star
26

shallow-eq

shallow equal
TypeScript
1
star
27

bi-designer

TypeScript
1
star
28

ascoders-tslint-config

ascoders-tslint-config
1
star
29

monaco-editor-commonjs

commonjs monaco-editor
JavaScript
1
star