Skip to content

Commit

Permalink
set default width/height if it's a local image
Browse files Browse the repository at this point in the history
  • Loading branch information
shahen94 committed Oct 30, 2016
1 parent c43da0e commit 2b4c5ba
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2b4c5ba

Please sign in to comment.