Skip to content

Commit

Permalink
chore: Retire PrefetchFlatList (and replace with FlatList and RouterL…
Browse files Browse the repository at this point in the history
…ink) (#11545)

* chore: Retire PrefetchFlatList

* InfiniteScrollFlashList
  • Loading branch information
olerichter00 authored Feb 13, 2025
1 parent fdf062e commit db5ec8b
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 226 deletions.
17 changes: 11 additions & 6 deletions src/app/Components/AboveTheFoldFlatList.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { useState } from "react"
import { PrefetchFlatList, PrefetchFlatListProps } from "./PrefetchFlatList"
import { Ref, useState } from "react"
import { FlatList, FlatListProps } from "react-native"

export type AboveTheFoldFlatListProps<ItemType> = {
initialNumToRender?: number
} & PrefetchFlatListProps<ItemType>
} & FlatListProps<ItemType>

export function AboveTheFoldFlatList<ItemType>(props: AboveTheFoldFlatListProps<ItemType>) {
export function AboveTheFoldFlatList<ItemType>(
props: {
initialNumToRender: number
listRef?: Ref<FlatList<ItemType | any>>
} & FlatListProps<ItemType>
) {
const { listRef, onScrollBeginDrag, ...restProps } = props
const [userHasScrolled, setUserHasScrolled] = useState(false)

return (
<PrefetchFlatList<ItemType>
<FlatList<ItemType>
{...restProps}
listRef={listRef}
ref={listRef}
onScrollBeginDrag={(event) => {
if (onScrollBeginDrag) {
onScrollBeginDrag(event)
Expand Down
14 changes: 7 additions & 7 deletions src/app/Components/CardRail/CardRailFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import {
AboveTheFoldFlatListProps,
} from "app/Components/AboveTheFoldFlatList"
import Spinner from "app/Components/Spinner"
import { View } from "react-native"
import { Ref } from "react"
import { FlatListProps, View } from "react-native"

export const INTER_CARD_PADDING = 15

type CardRailFlatList<ItemType> = AboveTheFoldFlatListProps<ItemType>

export function CardRailFlatList<ItemType>({
initialNumToRender: initialNumToRenderProp,
...restProps
}: CardRailFlatList<ItemType>) {
const initialNumToRender = initialNumToRenderProp || 2
export function CardRailFlatList<ItemType>(
props: { listRef?: Ref<ItemType | any> } & FlatListProps<ItemType>
) {
const initialNumToRender = props.initialNumToRender || 2

return (
<AboveTheFoldFlatList<ItemType>
Expand All @@ -26,7 +26,7 @@ export function CardRailFlatList<ItemType>({
showsHorizontalScrollIndicator={false}
scrollsToTop={false}
initialNumToRender={initialNumToRender}
{...restProps}
{...props}
/>
)
}
11 changes: 7 additions & 4 deletions src/app/Components/InfiniteScrollFlashList.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Flex } from "@artsy/palette-mobile"
import { PrefetchFlashList, PrefetchFlashListProps } from "app/Components/PrefetchFlashList"
import { FlashList, FlashListProps } from "@shopify/flash-list"
import { Ref } from "react"

export type InfiniteScrollFlashListProps<ItemType> = {
listRef?: Ref<ItemType | any>
initialNumToRender?: number
} & PrefetchFlashListProps<ItemType>
} & FlashListProps<ItemType>

const ESTIMATED_ITEM_SIZE = 60

export function InfiniteScrollFlashList<ItemType>(props: InfiniteScrollFlashListProps<ItemType>) {
const { listRef, onScrollBeginDrag, ...restProps } = props

return (
<Flex flex={1}>
<PrefetchFlashList<ItemType>
<FlashList<ItemType>
{...restProps}
listRef={listRef}
ref={listRef}
estimatedItemSize={ESTIMATED_ITEM_SIZE}
onScrollBeginDrag={(event) => {
if (onScrollBeginDrag) {
Expand Down
74 changes: 0 additions & 74 deletions src/app/Components/PrefetchFlashList.tsx

This file was deleted.

74 changes: 0 additions & 74 deletions src/app/Components/PrefetchFlatList.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionFairs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ export const HomeViewSectionFairs: React.FC<HomeViewSectionFairsProps> = ({
<CardRailFlatList<FairItem>
data={fairs}
initialNumToRender={HORIZONTAL_FLATLIST_INTIAL_NUMBER_TO_RENDER_DEFAULT}
prefetchUrlExtractor={(fair) => {
return `/fair/${fair?.slug}`
}}
prefetchVariablesExtractor={(item) => {
return {
fairID: item?.slug,
}
}}
renderItem={({ item, index }) => {
return (
<HomeViewSectionFairsFairItem
Expand Down
55 changes: 28 additions & 27 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionFairsFairItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "__generated__/HomeViewSectionFairsFairItem_fair.graphql"
import { CardRailCard, CardRailMetadataContainer } from "app/Components/CardRail/CardRailCard"
import { ThreeUpImageLayout } from "app/Components/ThreeUpImageLayout"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { extractNodes } from "app/utils/extractNodes"
import { compact, concat, take } from "lodash"
import { FC } from "react"
Expand Down Expand Up @@ -39,32 +39,33 @@ export const HomeViewSectionFairsFairItem: FC<HomeViewSectionFairsFairItemProps>
const location = fair.location?.city || fair.location?.country

return (
<CardRailCard
key={fair.slug}
onPress={() => {
onPress?.(fair)
navigate(`/fair/${fair.slug}`)
}}
>
<Flex>
<ThreeUpImageLayout imageURLs={artworkImageURLs} />
<CardRailMetadataContainer>
<Text numberOfLines={1} lineHeight="20px" variant="sm">
{fair.name}
</Text>
<Text
numberOfLines={1}
lineHeight="20px"
color="black60"
variant="sm"
testID="card-subtitle"
ellipsizeMode="middle"
>
{fair.exhibitionPeriod}
{Boolean(location) && ` ${bullet} ${location}`}
</Text>
</CardRailMetadataContainer>
</Flex>
<CardRailCard key={fair.slug}>
<RouterLink
to={`/fair/${fair.slug}`}
onPress={() => {
onPress?.(fair)
}}
>
<Flex>
<ThreeUpImageLayout imageURLs={artworkImageURLs} />
<CardRailMetadataContainer>
<Text numberOfLines={1} lineHeight="20px" variant="sm">
{fair.name}
</Text>
<Text
numberOfLines={1}
lineHeight="20px"
color="black60"
variant="sm"
testID="card-subtitle"
ellipsizeMode="middle"
>
{fair.exhibitionPeriod}
{Boolean(location) && ` ${bullet} ${location}`}
</Text>
</CardRailMetadataContainer>
</Flex>
</RouterLink>
</CardRailCard>
)
}
Expand Down
2 changes: 0 additions & 2 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionSales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export const HomeViewSectionSales: React.FC<HomeViewSectionSalesProps> = ({
</Flex>

<CardRailFlatList
prefetchUrlExtractor={(item) => item?.href}
prefetchVariablesExtractor={(item) => ({ saleSlug: item?.slug })}
listRef={listRef}
data={sales}
initialNumToRender={HORIZONTAL_FLATLIST_INTIAL_NUMBER_TO_RENDER_DEFAULT}
Expand Down
22 changes: 6 additions & 16 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionSalesItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
CardRailMetadataContainer as MetadataContainer,
} from "app/Components/CardRail/CardRailCard"
import { ThreeUpImageLayout } from "app/Components/ThreeUpImageLayout"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { extractNodes } from "app/utils/extractNodes"
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
import { compact } from "lodash"
import { FC } from "react"
import { View } from "react-native"
import { graphql, useFragment } from "react-relay"

interface HomeViewSectionSalesItemProps {
Expand All @@ -41,20 +40,11 @@ export const HomeViewSectionSalesItem: FC<HomeViewSectionSalesItemProps> = ({
// still be cautious to avoid crashes if this assumption is broken.
const availableArtworkImageURLs = compact(imageURLs)

return (
<CardRailCard
key={sale.href}
onPress={() => {
const url = sale.liveURLIfOpen ?? sale.href

onPress?.(sale)
const url = sale.liveURLIfOpen ?? sale.href

if (url) {
navigate(url)
}
}}
>
<View>
return (
<CardRailCard key={sale.href}>
<RouterLink to={url} onPress={() => onPress?.(sale)}>
<ThreeUpImageLayout imageURLs={availableArtworkImageURLs} />
<MetadataContainer>
<Text numberOfLines={2} lineHeight="20px" variant="sm">
Expand All @@ -70,7 +60,7 @@ export const HomeViewSectionSalesItem: FC<HomeViewSectionSalesItemProps> = ({
{sale.formattedStartDateTime}
</Text>
</MetadataContainer>
</View>
</RouterLink>
</CardRailCard>
)
}
Expand Down
Loading

0 comments on commit db5ec8b

Please sign in to comment.