Skip to content

Commit 7436032

Browse files
authored
Fix asset store preview (#4729)
Do not show in changelog
1 parent aa4fd1b commit 7436032

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

newIDE/app/src/AssetStore/AssetDetails.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
getUserPublicProfilesByIds,
4141
type UserPublicProfile,
4242
} from '../Utils/GDevelopServices/User';
43+
import { getPixelatedImageRendering } from '../Utils/CssHelpers';
4344

4445
const FIXED_HEIGHT = 250;
4546
const FIXED_WIDTH = 300;
@@ -64,6 +65,10 @@ const styles = {
6465
maxHeight: '100%',
6566
verticalAlign: 'middle',
6667
pointerEvents: 'none',
68+
// Compromise between having a preview of the asset slightly more zoomed
69+
// compared to the search results and a not too zoomed image for small
70+
// smooth assets that could give a sense of bad quality.
71+
flex: 0.6,
6772
},
6873
arrowContainer: {
6974
padding: 6,
@@ -153,6 +158,15 @@ export const AssetDetails = React.forwardRef<Props, AssetDetailsInterface>(
153158
},
154159
}));
155160

161+
const getImagePreviewStyle = (assetShortHeader: Asset) => {
162+
return {
163+
...styles.previewImage,
164+
imageRendering: isPixelArt(assetShortHeader)
165+
? getPixelatedImageRendering()
166+
: undefined,
167+
};
168+
};
169+
156170
const loadAsset = React.useCallback(
157171
() => {
158172
(async () => {
@@ -293,7 +307,7 @@ export const AssetDetails = React.forwardRef<Props, AssetDetailsInterface>(
293307
</Text>
294308
{!!assetAuthors &&
295309
assetAuthors.map(author => (
296-
<Text size="body">
310+
<Text size="body" key={author.name}>
297311
<Link
298312
key={author.name}
299313
href={author.website}
@@ -310,7 +324,7 @@ export const AssetDetails = React.forwardRef<Props, AssetDetailsInterface>(
310324
const username =
311325
userPublicProfile.username || 'GDevelop user';
312326
return (
313-
<Text size="body">
327+
<Text size="body" key={userPublicProfile.id}>
314328
<Link
315329
key={userPublicProfile.id}
316330
href="#"
@@ -391,13 +405,13 @@ export const AssetDetails = React.forwardRef<Props, AssetDetailsInterface>(
391405
<div style={styles.previewBackground}>
392406
{isAssetPrivate ? (
393407
<AuthorizedAssetImage
394-
style={styles.previewImage}
408+
style={getImagePreviewStyle(asset)}
395409
url={asset.previewImageUrls[0]}
396410
alt={asset.name}
397411
/>
398412
) : (
399413
<CorsAwareImage
400-
style={styles.previewImage}
414+
style={getImagePreviewStyle(asset)}
401415
src={asset.previewImageUrls[0]}
402416
alt={asset.name}
403417
/>

newIDE/app/src/ResourcesEditor/ResourcePropertiesEditor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const styles = {
2121
padding: 8,
2222
overflowY: 'scroll',
2323
overflowX: 'hidden',
24-
flex: 2,
24+
flex: 1,
2525
},
2626
};
2727

newIDE/app/src/ResourcesList/ResourcePreview/ImagePreview.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
const gd: libGDevelop = global.gd;
3030

3131
const MARGIN = 50;
32-
const SPRITE_MARGIN_RATIO = 1.3;
32+
const SPRITE_MARGIN_RATIO = 1.5;
3333

3434
const styles = {
3535
previewImagePixelated: {
@@ -167,10 +167,14 @@ const ImagePreview = ({
167167
// the zoom factor to the image.
168168
React.useEffect(
169169
() => {
170-
if (hasZoomBeenAdaptedToImageRef.current) return;
170+
if (hasZoomBeenAdaptedToImageRef.current || initialZoom) {
171+
// Do not adapt zoom to image if a zoom as been provided in the props
172+
// or if the zoom has already been adapted.
173+
return;
174+
}
171175
hasZoomBeenAdaptedToImageRef.current = adaptZoomFactorToImage();
172176
},
173-
[adaptZoomFactorToImage]
177+
[adaptZoomFactorToImage, initialZoom]
174178
);
175179

176180
const handleImageLoaded = (e: any) => {

0 commit comments

Comments
 (0)