Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (height) {
imgStyles.height = typeof height !== 'number' ? Number(height) : height;
}
// react native styles/StyleSheets can be merged by passing them as an array to the native Image component
newAttrs.style = style ? [imgStyles, style] : imgStyles;
// in react-native, you need to "import" static assets via `require` statements
// when the packager builds your app, it (presumably) statically analyzes your code, extracts
// the assets that are `require`d into an array/map, then assigns them a numerical value.
if (typeof src === 'number') {
newAttrs.source = src;
} else {
// assume we have a "network image", i.e. something loaded via http(s)
// update image URL for jss handler and image rendering params
const uri = mediaApi.updateImageUrl(src, imageUrlParams);
// for network images, the "source" prop is an object with at least "uri" value, e.g. { uri: 'http://aviato.com/myimg.jpg' }
newAttrs.source = { uri };
}
return newAttrs;
};
private getImageAttrs(fieldAttrs: any, parsedAttrs: any, imageParams: any): any {
const combinedAttrs = {
...fieldAttrs,
...parsedAttrs,
};
// tslint:disable-next-line:prefer-const
let { src, srcSet, ...otherAttrs } = combinedAttrs;
if (!src) {
return null;
}
const newAttrs = {
...otherAttrs,
};
// update image URL for jss handler and image rendering params
src = mediaApi.updateImageUrl(src, imageParams);
if (srcSet) {
// replace with HTML-formatted srcset, including updated image URLs
newAttrs.srcSet = mediaApi.getSrcSet(src, srcSet, imageParams);
} else {
newAttrs.src = src;
}
return newAttrs;
}
src: string;
srcSet: any;
otherAttrs: any[];
},
imageParams: any
) => {
if (!src) {
return null;
}
const newAttrs: any = {
...otherAttrs,
};
// update image URL for jss handler and image rendering params
const resolvedSrc = mediaApi.updateImageUrl(src, imageParams);
if (srcSet) {
// replace with HTML-formatted srcset, including updated image URLs
newAttrs.srcSet = mediaApi.getSrcSet(resolvedSrc, srcSet, imageParams);
} else {
newAttrs.src = resolvedSrc;
}
return newAttrs;
};