Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix the stretched image on web
Browse files Browse the repository at this point in the history
  • Loading branch information
alantoa committed Sep 28, 2023
1 parent 288052c commit 2f2b145
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions packages/design-system/image/image.web.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentProps, CSSProperties, useCallback } from "react";
import { ComponentProps, CSSProperties, useCallback, useMemo } from "react";
import { ImageURISource } from "react-native";

// @ts-ignore
Expand Down Expand Up @@ -73,46 +73,52 @@ function Img({
},
[onLoad, onLoadingCompleteProps]
);

const newProps = useMemo(() => {
return {
style: {
objectFit: (contentFit ?? resizeMode) as any,
...style,
},
alt: alt ?? "",
width,
height,
fill: !hasHeightOrWidth,
loading,
priority: loading === "eager",
...props,
};
}, [
alt,
contentFit,
hasHeightOrWidth,
height,
loading,
props,
resizeMode,
style,
width,
]);

if (source?.uri && typeof source?.uri === "string") {
return (
<Image
src={source.uri}
style={{
objectFit: (contentFit ?? resizeMode) as any,
...style,
}}
loading={loading}
priority={loading === "eager"}
width={width}
height={height}
onLoadingComplete={onLoad ? onLoadingComplete : noop}
placeholder={width > 40 && props.blurhash ? "blur" : "empty"}
blurDataURL={
width > 40 && props.blurhash
? getBase64Blurhash(props.blurhash)
: undefined
}
alt={alt ?? ""}
fill={!hasHeightOrWidth}
unoptimized // We already optimize the images with our CDN
{...props}
{...newProps}
/>
);
}

if (typeof source === "string") {
return (
<Image
src={source}
loading={loading}
priority={loading === "eager"}
width={width}
height={height}
fill={!hasHeightOrWidth}
alt={alt ?? ""}
{...props}
/>
);
return <Image src={source} {...newProps} />;
}

return null;
Expand All @@ -124,11 +130,12 @@ function StyledImage({ borderRadius = 0, tw = "", ...props }: ImageProps) {
return (
<View
style={{
width: "inherit",
height: "inherit",
width: "inherit" as any,
height: "inherit" as any,
borderRadius,
overflow: "hidden",
}}
tw="w-in"
>
<Img {...props} className={Array.isArray(tw) ? tw.join(" ") : tw} />
</View>
Expand Down

0 comments on commit 2f2b145

Please sign in to comment.