Giter Site home page Giter Site logo

hzuleo / react-native-image-viewer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ascoders/react-native-image-viewer

0.0 2.0 0.0 628 KB

๐Ÿš€ tiny & fast lib for react native image viewer pan and zoom

License: MIT License

TypeScript 100.00%

react-native-image-viewer's Introduction

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',
    // You can pass props to <Image />.
    props: {
        // headers: ...
    }
}, {
    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

{uri: 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 () => {}
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

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

react-native-image-viewer's People

Contributors

andrew avatar ascoders avatar aterribili avatar beilunyang avatar bolandrm avatar bradsolves avatar huangming1994 avatar jakewtaylor avatar labithiotis avatar shayanjavadi avatar sunkibaek avatar timothystewart6 avatar yunkaiwang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.