react-native-fit-image
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -21,12 +21,20 @@ import React, { | ||
if(!props.height && !props.originalHeight) { | ||
throw("Props error: at least one props must be " + | ||
"present among height and originalHeight."); | ||
const size = [props.width, props.height]; | ||
const originalSize = [props.originalWidth, props.originalHeight]; | ||
if(size.filter((e) => { return e; }).length == 1) { | ||
throw("Props error: size props must be present " + | ||
"none or both of width and height."); | ||
} | ||
if(!props.width && !props.originalWidth) { | ||
throw("Props error: at least one props must be " + | ||
"present among width and originalWidth."); | ||
if(originalSize.filter((e) => { return e; }).length === 1) { | ||
throw("Props error: originalSize props must be present " + | ||
"none or both of originalWidth and originalHeight."); | ||
} | ||
if([...size, ...originalSize].filter((e) => { return e; }).length === 0) { | ||
throw("Props error: at least one props must be present " + | ||
"among (originalWidth, originalHeight) and (width, height)."); | ||
} | ||
this.state = { | ||
@@ -37,11 +45,12 @@ height: 0, | ||
_getWidthObject() { | ||
_getStyle() { | ||
if(this.props.width) { | ||
return { width: this.props.width }; | ||
} else { | ||
return { flex: 1 }; | ||
} | ||
return null; | ||
} | ||
_getRatio(width) { | ||
return this._getWidthObject() ? 1 : width / this.props.originalWidth; | ||
return width / this.props.originalWidth; | ||
} | ||
@@ -59,2 +68,3 @@ | ||
var { width } = event.nativeEvent.layout; | ||
console.log('width', width); | ||
@@ -69,2 +79,4 @@ const height = this._getHeight(width); | ||
render() { | ||
console.log(this.state.height); | ||
return ( | ||
@@ -74,8 +86,5 @@ <Image | ||
style={[ | ||
{ | ||
flex: 1, | ||
height: this.state.height, | ||
}, | ||
{ height: this.state.height }, | ||
this.props.style, | ||
this._getWidthObject(), | ||
this._getStyle(), | ||
]} | ||
@@ -82,0 +91,0 @@ onLayout={(event) => this._setHeight(event)} |
{ | ||
"name": "react-native-fit-image", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Responsive image component to fit perfectly itself.", | ||
@@ -5,0 +5,0 @@ "main": "FitImage.js", |
@@ -21,3 +21,3 @@ # React Native Fit Image [![npm version](https://badge.fury.io/js/react-native-fit-image.svg)](https://badge.fury.io/js/react-native-fit-image) | ||
<FitImage | ||
source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} | ||
source={{ uri: 'http://facebook.github.io/react/img/logo_og.png' }} | ||
originalWidth={400} | ||
@@ -30,3 +30,3 @@ originalHeight={400} | ||
<FitImage | ||
source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} | ||
source={{ uri: 'http://facebook.github.io/react/img/logo_og.png' }} | ||
width={200} | ||
@@ -33,0 +33,0 @@ height={200} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3797
76