Open tomas223 opened 2 years ago
At the end I ended up creating my own component for web. It's not tested for all use cases, but worked for me.
import { useState } from "react";
import { Image, ImageProps, ImageStyle, StyleProp } from "react-native";
interface TSource {
uri: string;
}
export type Props = {
source: TSource;
width: number;
resizeMode: ImageProps["resizeMode"];
style?: StyleProp<ImageStyle>;
};
const MyAutoHeightImage = ({ style, width, source, resizeMode }: Props) => {
const [height, setHeight] = useState(0);
const updateImageHeight = () => {
Image.getSize(source.uri, (imgWidth, imgHeight) => {
const ratio = imgWidth / imgHeight;
setHeight(width / ratio);
});
};
return (
<Image
style={[style, { width: `${width}px`, height: `${height}px` }]}
width={width}
source={source}
resizeMode={resizeMode}
onLoad={updateImageHeight}
/>
);
};
export default MyAutoHeightImage;
Describe the bug After updating Expo to v44 I started to get following bugs on Web version that stops app from starting. Apps works without any issues in Android & iOs. I was not able to monkey-patch it, though I'm not saying it's not possible.
And this in web console.log:
To Reproduce Steps to reproduce the behavior:
import AutoHeightImage from "react-native-auto-height-image"; ... <AutoHeightImage resizeMode="contain" width={200} source={{ uri: uri }} /> ...