stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
35 lines • 1.23 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getResizedImageUrl = getResizedImageUrl;
var _reactNative = require("react-native");
var _ChatConfigContext = require("../contexts/chatConfigContext/ChatConfigContext");
function getResizedImageUrl({
height,
resizableCDNHosts = _ChatConfigContext.chatConfigContextDefaultvalue.resizableCDNHosts,
resize = 'clip',
url,
width
}) {
try {
var parsedUrl = new URL(url);
var originalHeight = parsedUrl.searchParams.get('oh');
var originalWidth = parsedUrl.searchParams.get('ow');
var isResizableUrl = resizableCDNHosts?.some(rCDNh => url.includes(rCDNh)) && originalHeight && originalWidth;
if (!isResizableUrl || !height && !width) {
return url;
}
if (height) {
parsedUrl.searchParams.set('h', `${_reactNative.PixelRatio.getPixelSizeForLayoutSize(Number(height))}`);
}
if (width) {
parsedUrl.searchParams.set('w', `${_reactNative.PixelRatio.getPixelSizeForLayoutSize(Number(width))}`);
}
parsedUrl.searchParams.set('resize', `${resize}`);
return parsedUrl.toString();
} catch (error) {
console.warn(error);
return url;
}
}
//# sourceMappingURL=getResizedImageUrl.js.map