Skip to content

Commit f096026

Browse files
araujobarretolerichter00
authored andcommitted
fix(ContextMenu): adjust menu size to not get cut (#13286)
fix: adjust context menu for iOS tablet to respect boundaries when increasing
1 parent fbbc804 commit f096026

File tree

5 files changed

+73
-34
lines changed

5 files changed

+73
-34
lines changed

src/app/Components/ArtworkGrids/ArtworkGridItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ export const Artwork: React.FC<ArtworkProps> = memo(
266266
onCreateAlertActionPress={() => setShowCreateArtworkAlertModal(true)}
267267
artwork={artwork}
268268
hideCreateAlertOnArtworkPreview={hideCreateAlertOnArtworkPreview}
269+
width={Number(height ?? 0) * (artwork.image?.aspectRatio ?? 1)}
270+
height={height}
269271
>
270272
<RouterLink
271273
haptic

src/app/Components/ArtworkRail/ArtworkRailCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Box, Flex, Spacer } from "@artsy/palette-mobile"
22
import { ArtworkRailCard_artwork$key } from "__generated__/ArtworkRailCard_artwork.graphql"
33
import { CreateArtworkAlertModal } from "app/Components/Artist/ArtistArtworks/CreateArtworkAlertModal"
44
import {
5+
ARTWORK_RAIL_CARD_IMAGE_HEIGHT,
56
ARTWORK_RAIL_CARD_MAX_WIDTH,
67
ARTWORK_RAIL_CARD_MIN_WIDTH,
78
ArtworkRailCardImage,
@@ -108,6 +109,8 @@ export const ArtworkRailCard: React.FC<ArtworkRailCardProps> = memo(
108109
lotLabel,
109110
SalePriceComponent,
110111
}}
112+
width={ARTWORK_RAIL_CARD_MAX_WIDTH}
113+
height={ARTWORK_RAIL_CARD_IMAGE_HEIGHT}
111114
>
112115
<Flex
113116
minWidth={ARTWORK_RAIL_CARD_MIN_WIDTH}

src/app/Components/ContextMenu/ContextMenuArtwork.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ interface ContextMenuArtworkProps {
5050
contextModule?: ContextModule
5151
contextScreenOwnerType?: ScreenOwnerType
5252
hideCreateAlertOnArtworkPreview?: boolean
53+
width?: number
54+
height?: number
5355
}
5456

5557
export const ContextMenuArtwork: React.FC<React.PropsWithChildren<ContextMenuArtworkProps>> = ({
@@ -61,6 +63,8 @@ export const ContextMenuArtwork: React.FC<React.PropsWithChildren<ContextMenuArt
6163
contextModule,
6264
contextScreenOwnerType,
6365
hideCreateAlertOnArtworkPreview,
66+
width,
67+
height,
6468
...restProps
6569
}) => {
6670
const artwork = useFragment(artworkFragment, restProps.artwork)
@@ -198,7 +202,12 @@ export const ContextMenuArtwork: React.FC<React.PropsWithChildren<ContextMenuArt
198202
artworkDisplayProps: ArtworkDisplayProps | undefined
199203
) => {
200204
return (
201-
<ContextMenuArtworkPreviewCard artwork={artwork} artworkDisplayProps={artworkDisplayProps} />
205+
<ContextMenuArtworkPreviewCard
206+
artwork={artwork}
207+
artworkDisplayProps={artworkDisplayProps}
208+
width={width}
209+
height={height}
210+
/>
202211
)
203212
}
204213

src/app/Components/ContextMenu/ContextMenuArtworkPreviewCard.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ import { PixelRatio } from "react-native"
99
import { isTablet } from "react-native-device-info"
1010
import { graphql, useFragment } from "react-relay"
1111

12-
const ARTWORK_PREVIEW_TEXT_CONTAINER_HEIGHT = 70
12+
const ARTWORK_PREVIEW_TEXT_CONTAINER_HEIGHT = isTablet() ? 90 : 70
13+
const TABLET_CONTEXT_MENU_MAX_HEIGHT = 360
1314

14-
const useFullWidth = () => {
15+
const useFullWidth = (width?: number, height?: number) => {
1516
const space = useSpace()
16-
const { width } = useScreenDimensions()
17-
const extraLargeWidth = isTablet() ? 400 : width - space(4)
18-
return extraLargeWidth
17+
const { width: _width } = useScreenDimensions()
18+
19+
if (isTablet() && width && height) {
20+
return {
21+
containerWidth: width - space(4),
22+
containerHeight: Math.min(height, TABLET_CONTEXT_MENU_MAX_HEIGHT),
23+
}
24+
}
25+
26+
return { containerWidth: _width - space(4) }
1927
}
2028

2129
export interface ContextMenuArtworkPreviewCardProps {
2230
artwork: ContextMenuArtworkPreviewCard_artwork$key
2331
artworkDisplayProps?: ArtworkDisplayProps
32+
width?: number
33+
height?: number
2434
}
2535

2636
export const ContextMenuArtworkPreviewCard: React.FC<ContextMenuArtworkPreviewCardProps> = ({
2737
artworkDisplayProps,
38+
width,
39+
height,
2840
...restProps
2941
}) => {
3042
const artwork = useFragment(artworkFragment, restProps.artwork)
@@ -37,7 +49,7 @@ export const ContextMenuArtworkPreviewCard: React.FC<ContextMenuArtworkPreviewCa
3749
lotLabel,
3850
} = artworkDisplayProps ?? {}
3951

40-
const FULL_WIDTH_RAIL_CARD_IMAGE_WIDTH = useFullWidth()
52+
const { containerWidth, containerHeight } = useFullWidth(width, height)
4153

4254
const fontScale = PixelRatio.getFontScale()
4355

@@ -51,8 +63,6 @@ export const ContextMenuArtworkPreviewCard: React.FC<ContextMenuArtworkPreviewCa
5163
return ARTWORK_PREVIEW_TEXT_CONTAINER_HEIGHT
5264
}
5365

54-
const containerWidth = FULL_WIDTH_RAIL_CARD_IMAGE_WIDTH
55-
5666
const space = useSpace()
5767

5868
return (
@@ -61,15 +71,17 @@ export const ContextMenuArtworkPreviewCard: React.FC<ContextMenuArtworkPreviewCa
6171
m={1}
6272
style={{ borderRadius: space(1), padding: space(2) }}
6373
>
64-
<ContextMenuArtworkPreviewCardImage containerWidth={containerWidth} artwork={artwork} />
74+
<ContextMenuArtworkPreviewCardImage
75+
containerWidth={containerWidth}
76+
containerHeight={containerHeight}
77+
artwork={artwork}
78+
/>
6579
<Flex
6680
my={1}
6781
width={containerWidth}
6882
// Recently sold artworks require more space for the text container
6983
// to accommodate the estimate and realized price
70-
style={{
71-
height: fontScale * getTextHeight(),
72-
}}
84+
style={{ height: fontScale * getTextHeight() }}
7385
backgroundColor={backgroundColor}
7486
flexDirection="row"
7587
justifyContent="space-between"

src/app/Components/ContextMenu/ContextMenuArtworkPreviewCardImage.tsx

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,60 @@ const ARTWORK_PREVIEW_IMAGE_MIN_HEIGHT = 50
77
export interface ContextMenuArtworkPreviewCardImageProps {
88
artwork: ContextMenuArtworkPreviewCardImage_artwork$key
99
containerWidth: number
10+
containerHeight?: number
1011
}
1112

1213
export 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

Comments
 (0)