Home

Awesome

Show Cases

Swiper image

Zoom while sliding

Swipe down

Getting Started

Installation

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

Basic Usage

$ npm install -g create-react-native-app
$ create-react-native-app AwesomeProject
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

parametertyperequireddescriptiondefault
imageUrlsarrayyesImage Source
enableImageZoombooleannoEnable image zoomtrue
onShowModalfunction<br><br>(content?: JSX.Element) => voidnoThe callback for show modal() => {}
onCancelfunction<br><br>() => voidnoThe callback for cancel modal() => {}
flipThresholdnumbernoSwipe threshold of the next page80
maxOverflownumbernoThe X position maximum, that current page can slide to the next page300
indexnumbernoInit index of images0
failImageSourcestring, object<br><br>{url: string}noplaceholder for fail''
loadingRenderfunction<br><br>() => React.ReactElement<any>noplaceholder for loading() => null
onSaveToCamerafunction<br><br>(index?: number => voidnoThe callback for save to camera() => {}
onChangefunction<br><br>(index?: number => voidnoWhen the image changed() => {}
onMove( position: IOnMove )=>voidreports movement position data (helpful to build overlays)()=> {}
saveToLocalByLongPressbooleannoEnable save to camera when long presstrue
onClickfunction<br><br>(onCancel?: function) => voidnoOnclick(onCancel) => {onCancel()}
onDoubleClickfunction<br><br>(onCancel?: function) => voidnoOnDoubleClick(onCancel) => {onCancel()}
onSavefunction<br><br>(url: string) => voidnoThe 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
renderHeaderfunction<br><br>(currentIndex?: number) => React.ReactElement<any>noCustom header() => null
renderFooterfunction<br><br>(currentIndex?: number) => React.ReactElement<any>noCustom footer() => null
renderIndicatorfunction<br><br>(currentIndex?: number, allSize?) => React.ReactElement<any>: numbernoCustom indicator(currentIndex, allSize) => currentIndex + "/" + allSize
renderImagefunction<br><br>(props: any) => React.ReactElement<any>noCustom image component(props) => <Image {...props} />
renderArrowLeftfunction<br><br>() => React.ReactElement<any>noCustom left arrow() => null
renderArrowRightfunction<br><br>() => React.ReactElement<any>noCustom right arrow() => null
onSwipeDownfunction<br><br>() => voidnoCallback for swipe down() => null
footerContainerStyleobject<br><br>{someStyle: someValue}nocustom style props for container that will be holding your footer that you passbottom: 0, position: "absolute", zIndex: 9999
backgroundColorstring<br><br>whitenoComponent background colorblack
enableSwipeDownbooleannoEnable swipe down to close image viewer. When swipe down, will trigger onCancel.false
swipeDownThresholdnumbernoThreshold for firing swipe down function
doubleClickIntervalnumbernoDouble click interval.
pageAnimateTimenumbernoSet the animation time for page flipping.100
enablePreloadbooleannoPreload the next imagefalse
useNativeDriverbooleannoWhether to animate using useNativeDriverfalse
menusfunction<br><br>({cancel,saveToLocal}) => React.ReactElement<any>noCustom menus, with 2 methods:cancel to hide menus and saveToLocal to save image to camera
menuContextobject<br><br>{someKey: someValue}noCustom 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