3.0.1 • Published 4 years ago

react-native-image-zoom-viewer v3.0.1

Weekly downloads
28,235
License
MIT
Repository
github
Last release
4 years ago

Show Cases

Swiper image

npm.io

Zoom while sliding

npm.io

Swipe down

npm.io

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

parametertyperequireddescriptiondefault
imageUrlsarrayyesImage Source
enableImageZoombooleannoEnable image zoomtrue
onShowModalfunction(content?: JSX.Element) => voidnoThe callback for show modal() => {}
onCancelfunction() => 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{url: string}noplaceholder for fail''
loadingRenderfunction() => React.ReactElement<any>noplaceholder for loading() => null
onSaveToCamerafunction(index?: number => voidnoThe callback for save to camera() => {}
onChangefunction(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(onCancel?: function) => voidnoOnclick(onCancel) => {onCancel()}
onDoubleClickfunction(onCancel?: function) => voidnoOnDoubleClick(onCancel) => {onCancel()}
onSavefunction(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(currentIndex?: number) => React.ReactElement<any>noCustom header() => null
renderFooterfunction(currentIndex?: number) => React.ReactElement<any>noCustom footer() => null
renderIndicatorfunction(currentIndex?: number, allSize?) => React.ReactElement<any>: numbernoCustom indicator(currentIndex, allSize) => currentIndex + "/" + allSize
renderImagefunction(props: any) => React.ReactElement<any>noCustom image component(props) => <Image {...props} />
renderArrowLeftfunction() => React.ReactElement<any>noCustom left arrow() => null
renderArrowRightfunction() => React.ReactElement<any>noCustom right arrow() => null
onSwipeDownfunction() => voidnoCallback for swipe down() => null
footerContainerStyleobject{someStyle: someValue}nocustom style props for container that will be holding your footer that you passbottom: 0, position: "absolute", zIndex: 9999
backgroundColorstringwhitenoComponent 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({cancel,saveToLocal}) => React.ReactElement<any>noCustom menus, with 2 methods:cancel to hide menus and saveToLocal to save image to camera
menuContextobject{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

qiscus-chat-widgetreact-native-itabletcode-avenue-design-systems@qiscus-integration/react-native-multichannel-widgetolx-mall@carrybible/stream-chat-react-native-corereact-native-nuno-uiraodaor-appraodaor-app-poetryraodaor-app1corbeappcorbeta@infinitebrahmanuniverse/nolb-react-native-icf-design-rn@everything-registry/sub-chunk-2581hcpk-rn-core-uiluxe-app-frameworkmaro-rnelephant-comreact-native-foocaa-librariesmoor-react-native-componentsreact-native-diaozhao-commonreact-native-dl-bmkitreact-native-foocaareact-native-image-pagereact-native-form0react-native-hecom-commonreact-native-1appreact-native-1app-themereact-native-bm001-rnkitreact-native-chat-imagesscorpiousscorpious_kogorunner-camp-shoprunnercamp-shopreact-native-photo-browsereact-native-optimusreact-native-aplusreact-native-zgy-modulesreact-native-lib-cus-comreact-native-librarysreact-native-md-componentsreact-native-template-umbappsamplereact-native-usefulapprn-upload-imagern-widgetcontus-mf-rnuat-image-browseruat-lifetimett-design-rnclub-rn-basecraftmusic-stream-chat-react-native-coreundigitals-chat-apibaracota-stylestream-chat-react-native-core-tyketstream-chat-react-native-ui-tweakscode-avenue-design-system@ezviz/ys-rn-pub-mini@fruits-chain/react-native-uploadcrov-cameracrov-camere@ledvance/eziot-rn-pub@iduty/modules@mifind/taro-rn@gifyourgame/stream-chat-react-native-core@rtarojs/taro-rnbee-uidp-taro-taro-rnwallet-appdl-kit@dymp/dylphin-rn@harrysong/taro-rn@unovo/taro-rn@vnxjs/vnmf-rn@tarojs/taro-rn@zalastax/nolb-react-native-i@agreejs/taro-rn@aks-dev/easyui
3.0.1

4 years ago

3.0.0

4 years ago

2.2.27

4 years ago

2.2.26

5 years ago

2.2.25

5 years ago

2.2.24

5 years ago

2.2.23

6 years ago

2.2.22

6 years ago

2.2.21

6 years ago

2.2.20

6 years ago

2.2.19

6 years ago

2.2.18

6 years ago

2.2.17

6 years ago

2.2.16

6 years ago

2.2.15

6 years ago

2.2.14

6 years ago

2.2.13

6 years ago

2.2.12

6 years ago

2.2.11

6 years ago

2.2.10

6 years ago

2.2.9

6 years ago

2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.0

6 years ago

2.0.20

6 years ago

2.0.19

6 years ago

2.0.18

6 years ago

2.0.17

6 years ago

2.0.16

6 years ago

2.0.15

6 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

7 years ago

2.0.10

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.47

7 years ago

1.2.46

7 years ago

1.2.45

7 years ago

1.2.44

7 years ago

1.2.43

7 years ago

1.2.42

7 years ago

1.2.41

7 years ago

1.2.40

7 years ago

1.2.39

7 years ago

1.2.38

7 years ago

1.2.37

7 years ago

1.2.36

7 years ago

1.2.35

7 years ago

1.2.34

7 years ago

1.2.33

7 years ago

1.2.32

7 years ago

1.2.31

7 years ago

1.2.30

7 years ago

1.2.29

7 years ago

1.2.28

7 years ago

1.2.27

7 years ago

1.2.26

7 years ago

1.2.25

7 years ago

1.2.24

8 years ago

1.2.23

8 years ago

1.2.22

8 years ago

1.2.21

8 years ago

1.2.20

8 years ago

1.2.19

8 years ago

1.2.18

8 years ago

1.2.17

8 years ago

1.2.16

8 years ago

1.2.15

8 years ago

1.2.14

8 years ago

1.2.13

8 years ago

1.2.12

8 years ago

1.2.11

8 years ago

1.2.10

8 years ago

1.2.9

8 years ago

1.2.8

8 years ago

1.2.7

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.2

8 years ago