@@ -7,46 +7,60 @@ const ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT = 50
77export interface ContextMenuArtworkPreviewCardImageProps {
88 artwork : ContextMenuArtworkPreviewCardImage_artwork$key
99 containerWidth : number
10+ containerHeight ?: number
1011}
1112
1213export const ContextMenuArtworkPreviewCardImage : React . FC <
1314 ContextMenuArtworkPreviewCardImageProps
14- > = ( { containerWidth, ...restProps } ) => {
15+ > = ( { containerWidth, containerHeight : _containerHeight , ...restProps } ) => {
1516 const artwork = useFragment ( artworkFragment , restProps . artwork )
1617 const color = useColor ( )
1718
1819 const aspectRatio = artwork ?. contextMenuImage ?. aspectRatio
1920 const { width, height, src } = artwork ?. contextMenuImage ?. resized || { }
2021
22+ const { height : screenHeight } = useScreenDimensions ( )
23+
2124 const useImageDimensions = ( ) => {
2225 const imageAspectRatio = aspectRatio ?? ( width && height ? width / height : 1 )
2326
24- const imageWidth = containerWidth
25- const imageHeight = imageWidth / imageAspectRatio
27+ // Check if this is a narrow image and we have containerHeight prop
28+ const isNarrowImage = imageAspectRatio < 1
29+ const useProvidedHeight = isNarrowImage && _containerHeight
2630
27- const { height : screenHeight } = useScreenDimensions ( )
28- const maxHeight = Math . floor ( screenHeight / 2 )
31+ if ( useProvidedHeight ) {
32+ // For narrow images with provided height: use the height and calculate width
33+ const displayImageHeight = _containerHeight
34+ const displayImageWidth = displayImageHeight * imageAspectRatio
35+ return { containerHeight : _containerHeight , displayImageWidth, displayImageHeight }
36+ } else {
37+ // For flat images: use existing logic (width-driven)
38+ const imageWidth = containerWidth
39+ const imageHeight = imageWidth / imageAspectRatio
2940
30- let containerHeight = imageHeight
41+ const maxHeight = Math . floor ( screenHeight / 2 )
3142
32- // Case when the image height is less than the minimum height
33- if ( imageHeight <= ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT ) {
34- containerHeight = ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT
35- }
43+ let calculatedContainerHeight = imageHeight
3644
37- // Case when the image height exceeds the maximum height
38- if ( imageHeight >= maxHeight ) {
39- containerHeight = maxHeight
40- }
45+ // Case when the image height is less than the minimum height
46+ if ( imageHeight <= ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT ) {
47+ calculatedContainerHeight = ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT
48+ }
4149
42- const displayImageHeight =
43- imageHeight <= ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT
44- ? Math . min ( imageHeight , ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT )
45- : Math . min ( Math . max ( imageHeight , ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT ) , maxHeight )
50+ // Case when the image height exceeds the maximum height
51+ if ( imageHeight >= maxHeight ) {
52+ calculatedContainerHeight = maxHeight
53+ }
54+
55+ const displayImageHeight =
56+ imageHeight <= ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT
57+ ? Math . min ( imageHeight , ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT )
58+ : Math . min ( Math . max ( imageHeight , ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT ) , maxHeight )
4659
47- const displayImageWidth = Math . min ( displayImageHeight * imageAspectRatio , imageWidth )
60+ const displayImageWidth = Math . min ( displayImageHeight * imageAspectRatio , imageWidth )
4861
49- return { containerHeight, displayImageWidth, displayImageHeight }
62+ return { containerHeight : calculatedContainerHeight , displayImageWidth, displayImageHeight }
63+ }
5064 }
5165
5266 const { containerHeight, displayImageWidth, displayImageHeight } = useImageDimensions ( )
@@ -74,7 +88,6 @@ export const ContextMenuArtworkPreviewCardImage: React.FC<
7488 src = { src }
7589 width = { displayImageWidth }
7690 height = { displayImageHeight }
77- aspectRatio = { aspectRatio }
7891 performResize = { false }
7992 resizeMode = "cover"
8093 testID = "artwork-rail-card-image"
0 commit comments