Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-fit-image

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-fit-image - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

__tests__/__snapshots__/FitImage.test.tsx.snap

365

dist/FitImage.js

@@ -1,204 +0,163 @@

Object.defineProperty(exports,"__esModule",{value:true});var _jsxFileName='src/FitImage.js';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _react=require('react');var _react2=_interopRequireDefault(_react);
var _reactNative=require('react-native');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}
var propTypes=_extends({},
_reactNative.Image.propTypes,{
indicator:_react.PropTypes.bool,
indicatorColor:_react.PropTypes.string,
indicatorSize:_react.PropTypes.oneOfType([
_react.PropTypes.oneOf(['small','large']),
_react.PropTypes.number]),
originalHeight:_react.PropTypes.number,
originalWidth:_react.PropTypes.number});
var styles=_reactNative.StyleSheet.create({
container:{
alignItems:'center',
justifyContent:'center'}});var
FitImage=function(_Image){_inherits(FitImage,_Image);
function FitImage(props){_classCallCheck(this,FitImage);var _this=_possibleConstructorReturn(this,(FitImage.__proto__||Object.getPrototypeOf(FitImage)).call(this,
props));
_this.style=_reactNative.StyleSheet.flatten(props.style);
if(_this.style){
var size=[_this.style.width,_this.style.height];
if(size.filter(function(e){return e;}).length===1){
throw new Error('Props error: size props must be present '+
'none or both of width and height.');
}
}
var originalSize=[props.originalWidth,props.originalHeight];
if(originalSize.filter(function(e){return e;}).length===1){
throw new Error('Props error: originalSize props must be present '+
'none or both of originalWidth and originalHeight.');
}
_this.isFirstLoad=true;
_this.state={
height:0,
isLoading:false,
layoutWidth:undefined,
originalWidth:undefined,
originalHeight:undefined};
_this.getHeight=_this.getHeight.bind(_this);
_this.getOriginalHeight=_this.getOriginalHeight.bind(_this);
_this.getOriginalWidth=_this.getOriginalWidth.bind(_this);
_this.getRatio=_this.getRatio.bind(_this);
_this.getStyle=_this.getStyle.bind(_this);
_this.onLoad=_this.onLoad.bind(_this);
_this.onLoadStart=_this.onLoadStart.bind(_this);
_this.renderActivityIndicator=_this.renderActivityIndicator.bind(_this);
_this.resize=_this.resize.bind(_this);
_this.setStateSize=_this.setStateSize.bind(_this);return _this;
}_createClass(FitImage,[{key:'componentDidMount',value:function componentDidMount()
{
if(this.props.originalWidth&&this.props.originalHeight)return;
this.mounted=true;
this.refreshStateSize();
}},{key:'componentWillUnmount',value:function componentWillUnmount()
{
this.mounted=false;
}},{key:'onLoad',value:function onLoad()
{
this.setState({isLoading:false});
this.refreshStateSize();
if(typeof this.props.onLoad==='function'){
this.props.onLoad();
}
}},{key:'onLoadStart',value:function onLoadStart()
{
if(this.isFirstLoad){
this.setState({isLoading:true});
this.isFirstLoad=false;
}
}},{key:'getHeight',value:function getHeight(
layoutWidth){
if(this.style&&this.style.height){
return this.style.height;
}
return this.getOriginalHeight()*this.getRatio(layoutWidth);
}},{key:'getOriginalHeight',value:function getOriginalHeight()
{
return this.props.originalHeight||this.state.originalHeight;
}},{key:'getOriginalWidth',value:function getOriginalWidth()
{
return this.props.originalWidth||this.state.originalWidth;
}},{key:'getRatio',value:function getRatio(
width){
var layoutWidth=width||this.state.layoutWidth;
return layoutWidth/this.getOriginalWidth();
}},{key:'getStyle',value:function getStyle()
{
if(this.style&&this.style.width){
return{width:this.style.width};
}
return{flexGrow:1};
}},{key:'resize',value:function resize(
event){var
width=event.nativeEvent.layout.width;
var height=this.getHeight(width);
this.setState({
height:height,
layoutWidth:width});
}},{key:'refreshStateSize',value:function refreshStateSize()
{var _this2=this;
if(!this.props.source.uri){
return;
}
_reactNative.Image.getSize(this.props.source.uri,function(originalWidth,originalHeight){
if(!_this2.mounted){
return;
}
_this2.setStateSize(originalWidth,originalHeight);
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
exports.__esModule = true;
var PropTypes = require("prop-types");
var React = require("react");
var react_1 = require("react");
var react_native_1 = require("react-native");
var propTypes = __assign({}, react_native_1.Image.propTypes, { indicator: PropTypes.bool, indicatorColor: PropTypes.string, indicatorSize: PropTypes.oneOfType([
PropTypes.oneOf(['small', 'large']),
PropTypes.number,
]), originalHeight: PropTypes.number, originalWidth: PropTypes.number });
var styles = react_native_1.StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center'
}
});
}},{key:'setStateSize',value:function setStateSize(
originalWidth,originalHeight){
var height=this.state.layoutWidth/originalWidth;
this.setState({
height:height,
originalHeight:originalHeight,
originalWidth:originalWidth});
}},{key:'renderActivityIndicator',value:function renderActivityIndicator()
{
return(
_react2.default.createElement(_reactNative.ActivityIndicator,{
color:this.props.indicatorColor,
size:this.props.indicatorSize,__source:{fileName:_jsxFileName,lineNumber:163}}));
}},{key:'render',value:function render()
{
var children=this.props.children;
var ImageComponent=_reactNative.Image;
if(this.state.isLoading&&this.props.indicator!==false){
children=this.renderActivityIndicator();
}
if(children&&_reactNative.ImageBackground){
ImageComponent=_reactNative.ImageBackground;
}
return(
_react2.default.createElement(ImageComponent,_extends({},
this.props,{
onLayout:this.resize,
onLoad:this.onLoad,
onLoadStart:this.onLoadStart,
source:this.props.source,
style:[
this.style,
this.getStyle(),
{height:this.state.height},
styles.container],__source:{fileName:_jsxFileName,lineNumber:183}}),
children));
}}]);return FitImage;}(_reactNative.Image);
FitImage.propTypes=propTypes;exports.default=
FitImage;
var FitImage = (function (_super) {
__extends(FitImage, _super);
function FitImage(props) {
var _this = _super.call(this, props) || this;
_this.onLoad = function () {
_this.setState({ isLoading: false });
_this.refreshStateSize();
if (typeof _this.props.onLoad === 'function') {
_this.props.onLoad();
}
};
_this.onLoadStart = function () {
if (_this.isFirstLoad) {
_this.setState({ isLoading: true });
_this.isFirstLoad = false;
}
};
_this.getHeight = function (layoutWidth) {
if (_this.style && _this.style.height) {
return _this.style.height;
}
return _this.getOriginalHeight() * _this.getRatio(layoutWidth);
};
_this.getOriginalHeight = function () { return (_this.props.originalHeight || _this.state.originalHeight || 0); };
_this.getOriginalWidth = function () { return (_this.props.originalWidth || _this.state.originalWidth || 0); };
_this.getRatio = function (width) {
var originalWidth = _this.getOriginalWidth();
if (originalWidth === 0) {
return 0;
}
var layoutWidth = width || _this.state.layoutWidth || 0;
return layoutWidth / _this.getOriginalWidth();
};
_this.getStyle = function () {
if (_this.style && _this.style.width) {
return { width: _this.style.width };
}
return { flexGrow: 1 };
};
_this.resize = function (event) {
var width = event.nativeEvent.layout.width;
var height = Number(_this.getHeight(width));
_this.setState({
height: height,
layoutWidth: width
});
};
_this.refreshStateSize = function () {
var uri;
if (_this.props.source instanceof Array) {
uri = _this.props.source[0].uri;
}
else {
uri = _this.props.source.uri;
}
if (!uri) {
return;
}
react_native_1.Image.getSize(uri, function (originalWidth, originalHeight) {
if (!_this.mounted) {
return;
}
_this.setStateSize(originalWidth, originalHeight);
}, function () { return null; });
};
_this.setStateSize = function (originalWidth, originalHeight) {
var height = (_this.state.layoutWidth || 0) / originalWidth;
_this.setState({
height: height,
originalHeight: originalHeight,
originalWidth: originalWidth
});
};
_this.renderActivityIndicator = function () {
return (React.createElement(react_native_1.ActivityIndicator, { color: _this.props.indicatorColor, size: _this.props.indicatorSize }));
};
_this.style = react_native_1.StyleSheet.flatten(props.style);
if (_this.style) {
var size = [_this.style.width, _this.style.height];
if (size.filter(Boolean).length === 1) {
throw new Error('Props error: size props must be present ' +
'none or both of width and height.');
}
}
var originalSize = [props.originalWidth, props.originalHeight];
if (originalSize.filter(Boolean).length === 1) {
throw new Error('Props error: originalSize props must be present ' +
'none or both of originalWidth and originalHeight.');
}
_this.isFirstLoad = true;
_this.state = {
height: 0,
isLoading: false,
layoutWidth: undefined,
originalHeight: undefined,
originalWidth: undefined
};
return _this;
}
FitImage.prototype.componentDidMount = function () {
if (this.props.originalWidth && this.props.originalHeight) {
return;
}
this.mounted = true;
this.refreshStateSize();
};
FitImage.prototype.componentWillUnmount = function () {
this.mounted = false;
};
FitImage.prototype.render = function () {
var children = this.props.children;
var ImageComponent = react_native_1.Image;
if (this.state.isLoading && this.props.indicator !== false) {
children = this.renderActivityIndicator();
}
if (children && react_native_1.ImageBackground) {
ImageComponent = react_native_1.ImageBackground;
}
return (React.createElement(ImageComponent, __assign({}, this.props, { onLayout: this.resize, onLoad: this.onLoad, onLoadStart: this.onLoadStart, source: this.props.source, style: [
this.style,
this.getStyle(),
{ height: this.state.height },
styles.container,
] }), children));
};
FitImage.propTypes = propTypes;
return FitImage;
}(react_1.Component));
exports["default"] = FitImage;
{
"name": "react-native-fit-image",
"version": "1.5.2",
"version": "1.5.3",
"description": "Responsive image component to fit perfectly itself.",
"main": "dist/FitImage.js",
"scripts": {
"build": "babel src -d dist",
"build": "tsc",
"build:test": "tsc -p tsconfig.test.json",
"build-and-publish": "npm run build && npm publish",
"test": "tape -r babel-register -r react-native-mock/mock test/**/*.js | tap-diff"
"lint": "tslint {src,__tests__}/**/*.{ts,tsx}",
"prebuild": "rm -rf dist",
"test": "jest"
},

@@ -23,3 +26,3 @@ "repository": {

"author": "Jitae Kim <originerd@gmail.com> (http://originerd.com)",
"license": "ISC",
"license": "Beerware",
"bugs": {

@@ -29,19 +32,43 @@ "url": "https://github.com/huiseoul/react-native-fit-image/issues"

"homepage": "https://github.com/huiseoul/react-native-fit-image#readme",
"dependencies": {
"prop-types": "^15.5.10"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"@types/jest": "^20.0.5",
"@types/prop-types": "^15.5.1",
"@types/react": "^16.0.2",
"@types/react-native": "^0.47.2",
"@types/react-test-renderer": "^15.5.2",
"babel-jest": "^20.0.3",
"babel-preset-react-native": "^2.1.0",
"enzyme": "^2.3.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-native": "^0.46.3",
"react-native-mock": "^0.3.1",
"sinon": "^2.3.8",
"tap-diff": "^0.1.1",
"tape": "^4.5.1"
"jest": "^20.0.4",
"jest-cli": "^20.0.4",
"react": "16.0.0-alpha.12",
"react-native": "0.47.1",
"react-test-renderer": "16.0.0-alpha.12",
"ts-jest": "^20.0.10",
"tslint": "^5.6.0",
"typescript": "^2.4.2"
},
"babel": {
"presets": [
"react-native"
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/typescript"
],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"modulePathIgnorePatterns": [
"<rootDir>/example/"
]
}
},
"types": "dist/FitImage.d.ts"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc