Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(DIA-1019): pass a component to FancySwiperCard instead of JSX #11439

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

iskounen
Copy link
Contributor

This PR refactors FancySwiper to receive an array of React components instead of JSX. I wanted to make this change because I will want to reuse the useSaveArtwork hook to allow users to save artworks, and I can't use that hook for each artwork card unless it is inside of a component.

InfiniteDiscovery.mp4
ArtTasteQuiz.mp4

PR Checklist

  • I have tested my changes on iOS and Android.
  • I hid my changes behind a feature flag, or they don't need one.
  • I have included screenshots or videos, or I have not changed the UI.
  • I have added tests, or my changes don't require any.
  • I added an app state migration, or my changes do not require one.
  • I have documented any follow-up work that this PR will require, or it does not require any.
  • I have added a changelog entry below, or my changes do not require one.

To the reviewers 👀

  • I would like at least one of the reviewers to run this PR on the simulator or device.
Changelog updates

Changelog updates

Cross-platform user-facing changes

iOS user-facing changes

Android user-facing changes

Dev changes

  • Refactored FancySwiper to receive an array of components instead of JSX

Need help with something? Have a look at our docs, or get in touch with us.

@iskounen iskounen self-assigned this Jan 23, 2025
const artworkCards: React.ReactNode[] = useMemo(
() => artworks.map((artwork, index) => <ArtQuizArtworkCard artwork={artwork} key={index} />),
[artworks]
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I memoized this because the artwork cards were being recalculated on each swipe and causing the screen to flicker. This stopped the flickering.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I was gonna ask about performance but this makes sense!

@@ -69,6 +59,10 @@ export const InfiniteDiscovery: React.FC = () => {
})
}, [])

const artworkCards: React.ReactNode[] = useMemo(() => {
return artworks.map((artwork, i) => <InfiniteDiscoveryArtworkCard artwork={artwork} key={i} />)
}, [artworks])
Copy link
Contributor Author

@iskounen iskounen Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memoizing this mapping stopped the flickering on each swipe, but there is still a flicker when a new batch of artworks is retrieved. (You can see this flicker after the 3rd and 8th swipe in the Infinite Discovery video in the description.)

I need to find a way to not recalculate the existing ones...

@ArtsyOpenSource
Copy link
Contributor

This PR contains the following changes:

  • Dev changes (Refactored FancySwiper to receive an array of components instead of JSX - iskounen)

Generated by 🚫 dangerJS against f483903

const { color } = useTheme()
const { width: screenWidth } = useScreenDimensions()

const src = !!artwork?.images?.[0]?.url ? artwork.images[0].url : undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#superminor - There's a couple simpler ways to do this kind of thing:

If its undefined, its undefined; no need to use a ternary and then assignment:

const src = artwork?.images?.[0]?.url

const { width: screenWidth } = useScreenDimensions()

const src = !!artwork?.images?.[0]?.url ? artwork.images[0].url : undefined
const width = !!artwork?.images?.[0]?.width ? artwork.images[0].width : 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here -- can use the nullish operator:

const width = artwork?.images?.[0]?.width ?? 0


const src = !!artwork?.images?.[0]?.url ? artwork.images[0].url : undefined
const width = !!artwork?.images?.[0]?.width ? artwork.images[0].width : 0
const height = !!artwork?.images?.[0]?.height ? artwork.images[0].height : 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as well as here

<Flex backgroundColor={color("white100")} width="100%" height={800}>
<EntityHeader
name={artwork?.artistNames ?? ""}
meta={artwork?.artists?.[0]?.formattedNationalityAndBirthday ?? undefined}
Copy link
Member

@damassi damassi Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this stuff not just fall back to undefined? Like do we need to explicitly define ?? undefined (or ?? "" -- ie, fallbacks ?

Copy link
Member

@damassi damassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple #superminor comments, but nothing blocking 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants