From 2b4c5bafe3fe7dc2edff624b23c1902d8c82d9f8 Mon Sep 17 00:00:00 2001 From: shahen94 Date: Sun, 30 Oct 2016 21:46:01 +0400 Subject: [PATCH] set default width/height if it's a local image --- lib/ImageViewer.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/ImageViewer.js b/lib/ImageViewer.js index 821ce00..86f5bb5 100644 --- a/lib/ImageViewer.js +++ b/lib/ImageViewer.js @@ -42,13 +42,19 @@ export class ImageViewer extends Component { // zoomed image zoomedImageStyle: Image.propTypes.style, zoomedImageProps: PropTypes.arrayOf(PropTypes.object), + + // required if it's a local image + imageWidth: PropTypes.number, + imageHeight: PropTypes.number, // callbacks onMove: PropTypes.func, onPress: PropTypes.func, }; static defaultProps = { - doubleTapEnabled: true + doubleTapEnabled: true, + imageWidth: width, + imageHeight: height / 2 }; constructor(props, context) { @@ -66,8 +72,8 @@ export class ImageViewer extends Component { this.layoutListener = null; this._imageSize = { - width: null, - height: null + width: typeof props.source !== 'object' ? props.imageWidth : null, + height: typeof props.source !== 'object' ? props.imageHeight : null, }; this._layoutX = 0; @@ -106,11 +112,10 @@ export class ImageViewer extends Component { if (typeof source === 'object' && typeof source.uri === 'string') { Image.prefetch(this.props.source); + Image.getSize(this.props.source, (width, height) => { + this._imageSize = { width, height }; + }); } - - Image.getSize(this.props.source, (width, height) => { - this._imageSize = { width, height }; - }); } componentWillUnmount() { this.state.layout.x.removeAllListeners();