Skip to content

Commit c44814b

Browse files
committed
ff, tests and touchable fix
1 parent ac6611d commit c44814b

File tree

4 files changed

+123
-43
lines changed

4 files changed

+123
-43
lines changed

src/app/Components/ArtworkRail/ArtworkRailCard.tsx

+27-27
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,30 @@ export const ArtworkRailCard: React.FC<ArtworkRailCardProps> = ({
9292
contextScreenOwnerSlug={contextScreenOwnerSlug}
9393
contextScreenOwnerType={contextScreenOwnerType}
9494
>
95-
<ContextMenuArtwork
96-
contextModule={contextModule}
97-
contextScreenOwnerType={contextScreenOwnerType}
98-
onCreateAlertActionPress={() => setShowCreateArtworkAlertModal(true)}
99-
onSupressArtwork={supressArtwork}
100-
artwork={artwork}
101-
artworkDisplayProps={{
102-
dark,
103-
showPartnerName,
104-
hideArtistName,
105-
lotLabel,
106-
SalePriceComponent,
107-
}}
108-
>
109-
<Box pr={2}>
110-
<RouterLink
111-
to={href || artwork.href}
112-
underlayColor={backgroundColor}
113-
activeOpacity={0.8}
114-
onPress={onPress}
115-
// To prevent navigation when opening the long-press context menu, `onLongPress` & `delayLongPress` need to be set (https://github.com/mpiannucci/react-native-context-menu-view/issues/60)
116-
onLongPress={() => {}}
117-
delayLongPress={400}
118-
testID={testID}
95+
<Box pr={2}>
96+
<RouterLink
97+
to={href || artwork.href}
98+
underlayColor={backgroundColor}
99+
activeOpacity={0.8}
100+
onPress={onPress}
101+
// To prevent navigation when opening the long-press context menu, `onLongPress` & `delayLongPress` need to be set (https://github.com/mpiannucci/react-native-context-menu-view/issues/60)
102+
onLongPress={() => {}}
103+
delayLongPress={400}
104+
testID={testID}
105+
>
106+
<ContextMenuArtwork
107+
contextModule={contextModule}
108+
contextScreenOwnerType={contextScreenOwnerType}
109+
onCreateAlertActionPress={() => setShowCreateArtworkAlertModal(true)}
110+
onSupressArtwork={supressArtwork}
111+
artwork={artwork}
112+
artworkDisplayProps={{
113+
dark,
114+
showPartnerName,
115+
hideArtistName,
116+
lotLabel,
117+
SalePriceComponent,
118+
}}
119119
>
120120
<Flex
121121
height={
@@ -161,9 +161,9 @@ export const ArtworkRailCard: React.FC<ArtworkRailCardProps> = ({
161161
contextScreenOwnerType={contextScreenOwnerType}
162162
/>
163163
</Flex>
164-
</RouterLink>
165-
</Box>
166-
</ContextMenuArtwork>
164+
</ContextMenuArtwork>
165+
</RouterLink>
166+
</Box>
167167

168168
<CreateArtworkAlertModal
169169
artwork={artwork}

src/app/Components/ContextMenu/ContextMenuArtwork.tsx

+21-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { isEmpty } from "lodash"
1616
import { useState } from "react"
1717
import { InteractionManager, Platform } from "react-native"
1818
import ContextMenu, { ContextMenuAction, ContextMenuProps } from "react-native-context-menu-view"
19-
import { TouchableWithoutFeedback } from "react-native-gesture-handler"
19+
import { TouchableHighlight } from "react-native-gesture-handler"
2020
import { HapticFeedbackTypes, trigger } from "react-native-haptic-feedback"
2121
import { graphql, useFragment } from "react-relay"
2222
import { useTracking } from "react-tracking"
@@ -56,7 +56,8 @@ export const ContextMenuArtwork: React.FC<ContextMenuArtworkProps> = ({
5656

5757
const { trackEvent } = useTracking()
5858
const { showShareSheet } = useShareSheet()
59-
const enableContextMenu = useFeatureFlag("AREnableArtworkCardContextMenuIOS")
59+
const enableContextMenuIOS = useFeatureFlag("AREnableArtworkCardContextMenuIOS")
60+
const enableContextMenuAndroid = useFeatureFlag("AREnableArtworkCardContextMenuAndroid")
6061
const { submitMutation: dislikeArtworkMutation } = useDislikeArtwork()
6162
const isIOS = Platform.OS === "ios"
6263
const color = useColor()
@@ -223,25 +224,26 @@ export const ContextMenuArtwork: React.FC<ContextMenuArtworkProps> = ({
223224
)
224225
}
225226

226-
const [modalVisible, setModalVisible] = useState(false)
227+
const [androidVisible, setAndroidVisible] = useState(false)
227228

228229
const handleAndroidLongPress = () => {
229-
setModalVisible(true)
230+
setAndroidVisible(true)
230231
}
231232

232-
if (!enableContextMenu) {
233-
return <>{children}</>
234-
}
235-
236-
// TODO: Remove the `true ||` before merging!
237-
if (true || !isIOS) {
233+
// Fall back to a bottom sheet on Android
234+
if (!isIOS && enableContextMenuAndroid) {
238235
return (
239236
<>
240-
<TouchableWithoutFeedback onLongPress={handleAndroidLongPress}>
237+
<TouchableHighlight
238+
underlayColor={color("white100")}
239+
activeOpacity={0.8}
240+
onLongPress={handleAndroidLongPress}
241+
onPress={undefined}
242+
>
241243
{children}
242-
</TouchableWithoutFeedback>
244+
</TouchableHighlight>
243245

244-
<AutoHeightBottomSheet visible={modalVisible} onDismiss={() => setModalVisible(false)}>
246+
<AutoHeightBottomSheet visible={androidVisible} onDismiss={() => setAndroidVisible(false)}>
245247
<Flex pb={4} pt={1} mx={2} height="100%">
246248
<Flex ml={-1} mb={1}>
247249
{artworkPreviewComponent(artwork)}
@@ -252,8 +254,8 @@ export const ContextMenuArtwork: React.FC<ContextMenuArtworkProps> = ({
252254
return (
253255
<Touchable
254256
key={index}
255-
onPress={async () => {
256-
setModalVisible(false)
257+
onPress={() => {
258+
setAndroidVisible(false)
257259

258260
action.onPress?.()
259261
}}
@@ -271,6 +273,10 @@ export const ContextMenuArtwork: React.FC<ContextMenuArtworkProps> = ({
271273
)
272274
}
273275

276+
if (!enableContextMenuIOS) {
277+
return <>{children}</>
278+
}
279+
274280
return (
275281
<ContextMenu
276282
actions={contextActions}
@@ -279,7 +285,6 @@ export const ContextMenuArtwork: React.FC<ContextMenuArtworkProps> = ({
279285
preview={artworkPreviewComponent(artwork)}
280286
hideShadows={true}
281287
previewBackgroundColor={!!dark ? color("black100") : color("white100")}
282-
disabled={!enableContextMenu}
283288
>
284289
{children}
285290
</ContextMenu>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { fireEvent, screen, waitFor } from "@testing-library/react-native"
2+
import { ArtworkRailCardTestsQuery } from "__generated__/ArtworkRailCardTestsQuery.graphql"
3+
import { ArtworkRailCard } from "app/Components/ArtworkRail/ArtworkRailCard"
4+
import { __globalStoreTestUtils__ } from "app/store/GlobalStore"
5+
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper"
6+
import { Platform } from "react-native"
7+
import { graphql } from "react-relay"
8+
9+
describe("ContextMenuArtwork", () => {
10+
const { renderWithRelay } = setupTestWrapper<ArtworkRailCardTestsQuery>({
11+
Component: (props) => {
12+
if (!props.artwork) return null
13+
14+
return <ArtworkRailCard {...props} artwork={props.artwork} testID="artwork-card" />
15+
},
16+
query: graphql`
17+
query ContextMenuArtworkTestsQuery @relay_test_operation {
18+
artwork(id: "the-artwork") {
19+
...ArtworkRailCard_artwork
20+
}
21+
}
22+
`,
23+
})
24+
25+
describe("on Android", () => {
26+
beforeEach(() => {
27+
Platform.OS = "android"
28+
29+
__globalStoreTestUtils__?.injectFeatureFlags({
30+
AREnableArtworkCardContextMenuAndroid: true,
31+
})
32+
})
33+
34+
it("shows context menu on long press", async () => {
35+
renderWithRelay()
36+
37+
const artworkCard = screen.getByTestId("artwork-card")
38+
39+
fireEvent(artworkCard, "onLongPress")
40+
41+
await waitFor(() => {
42+
expect(screen.getByText("Create alert")).toBeOnTheScreen()
43+
})
44+
await waitFor(() => {
45+
expect(screen.getByText("Share")).toBeOnTheScreen()
46+
})
47+
})
48+
49+
describe("when feature flag is disabled", () => {
50+
beforeEach(() => {
51+
__globalStoreTestUtils__?.injectFeatureFlags({
52+
AREnableArtworkCardContextMenuAndroid: false,
53+
})
54+
})
55+
56+
it("does NOT show context menu on long press", async () => {
57+
renderWithRelay()
58+
59+
const artworkCard = screen.getByTestId("artwork-card")
60+
61+
fireEvent(artworkCard, "onLongPress")
62+
63+
await waitFor(() => {
64+
expect(screen.queryByText("Create alert")).not.toBeOnTheScreen()
65+
})
66+
})
67+
})
68+
})
69+
})

src/app/store/config/features.ts

+6
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ export const features = {
252252
showInDevMenu: true,
253253
echoFlagKey: "AREnableArtworkCardContextMenuIOS",
254254
},
255+
AREnableArtworkCardContextMenuAndroid: {
256+
description: "Enable long press menu on artwork cards for Android",
257+
readyForRelease: true,
258+
showInDevMenu: true,
259+
echoFlagKey: "AREnableArtworkCardContextMenuAndroid",
260+
},
255261
} satisfies { [key: string]: FeatureDescriptor }
256262

257263
export interface DevToggleDescriptor {

0 commit comments

Comments
 (0)