-
Notifications
You must be signed in to change notification settings - Fork 571
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
feat: wip on replacing artwork grids with more performant masonry #doNotMerge #7693
Changes from 2 commits
ded1dc7
058d072
b7c6345
6b59e8e
ad404c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { OwnerType } from "@artsy/cohesion" | ||
import { MasonryFlashList } from "@shopify/flash-list" | ||
import { ArtistArtworks_artist$data } from "__generated__/ArtistArtworks_artist.graphql" | ||
import { ArtworkFilterNavigator, FilterModalMode } from "app/Components/ArtworkFilter" | ||
import { Aggregations, FilterArray } from "app/Components/ArtworkFilter/ArtworkFilterHelpers" | ||
|
@@ -13,19 +14,31 @@ import { | |
useArtworkFilters, | ||
useSelectedFiltersCount, | ||
} from "app/Components/ArtworkFilter/useArtworkFilters" | ||
import { Artwork } from "app/Components/ArtworkGrids/ArtworkGridItem" | ||
import { ArtworksFilterHeader } from "app/Components/ArtworkGrids/ArtworksFilterHeader" | ||
import { FilteredArtworkGridZeroState } from "app/Components/ArtworkGrids/FilteredArtworkGridZeroState" | ||
import { | ||
InfiniteScrollArtworksGridContainer as InfiniteScrollArtworksGrid, | ||
Props as InfiniteScrollGridProps, | ||
} from "app/Components/ArtworkGrids/InfiniteScrollArtworksGrid" | ||
import { PAGE_SIZE } from "app/Components/constants" | ||
import { StickyTabPageFlatListContext } from "app/Components/StickyTabPage/StickyTabPageFlatList" | ||
import { StickyTabPageScrollView } from "app/Components/StickyTabPage/StickyTabPageScrollView" | ||
import { extractNodes } from "app/utils/extractNodes" | ||
import { Schema } from "app/utils/track" | ||
import { Box, Message, Spacer } from "palette" | ||
import { Box, Flex, Message, OpaqueImageView, Spacer, Text, useSpace } from "palette" | ||
import { Masonry } from "palette/elements/VirtualizedMasonry" | ||
import React, { useContext, useEffect, useState } from "react" | ||
import { | ||
ActivityIndicator, | ||
FlatList, | ||
Platform, | ||
SafeAreaView, | ||
useWindowDimensions, | ||
} from "react-native" | ||
import { createPaginationContainer, graphql, RelayPaginationProp } from "react-relay" | ||
import { useTracking } from "react-tracking" | ||
import { useScreenDimensions } from "shared/hooks" | ||
import { SavedSearchButtonV2 } from "./SavedSearchButtonV2" | ||
|
||
interface ArtworksGridProps extends InfiniteScrollGridProps { | ||
|
@@ -193,19 +206,62 @@ const ArtistArtworksContainer: React.FC<ArtworksGridProps & ArtistArtworksContai | |
</Box> | ||
) | ||
} else { | ||
const space = useSpace() | ||
const { width } = useScreenDimensions() | ||
const artworkdata = extractNodes(artist.artworks) | ||
|
||
const fetchNextPage = () => { | ||
if (!relay.hasMore() || relay.isLoading()) { | ||
return | ||
} | ||
|
||
relay.loadMore(PAGE_SIZE) | ||
} | ||
|
||
const { height } = useWindowDimensions() | ||
|
||
return ( | ||
<> | ||
<Spacer mb={1} /> | ||
<InfiniteScrollArtworksGrid | ||
connection={artist.artworks!} | ||
loadMore={relay.loadMore} | ||
hasMore={relay.hasMore} | ||
{...props} | ||
contextScreenOwnerType={OwnerType.artist} | ||
contextScreenOwnerId={artist.internalID} | ||
contextScreenOwnerSlug={artist.slug} | ||
<Box flex={1} height={height}> | ||
<MasonryFlashList | ||
data={artworkdata} | ||
numColumns={2} | ||
estimatedItemSize={width / 2} | ||
// contentContainerStyle={{ paddingTop: space(2), paddingHorizontal: space(2) }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove this completely |
||
renderItem={({ item, index }) => ( | ||
<Flex backgroundColor="red"> | ||
<Text>{item.title}</Text> | ||
<OpaqueImageView | ||
aspectRatio={item.image?.aspectRatio} | ||
width={width / 2 - space(2)} | ||
imageURL={item.image?.url} | ||
/> | ||
</Flex> | ||
// <Artwork | ||
// artwork={item} | ||
// updateRecentSearchesOnTap | ||
// itemIndex={index} | ||
// /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is our artwork component. If we use it instead of the other one above the images jump a bit, they basically display another image briefly before rendering the correct one. |
||
)} | ||
ListFooterComponent={() => | ||
relay.isLoading() ? ( | ||
<Flex | ||
alignItems="center" | ||
justifyContent="center" | ||
p="3" | ||
pb="9" | ||
style={{ opacity: relay.hasMore() ? 1 : 0 }} | ||
> | ||
<ActivityIndicator color={Platform.OS === "android" ? "black" : undefined} /> | ||
</Flex> | ||
) : null | ||
} | ||
onEndReachedThreshold={0.2} | ||
onEndReached={() => { | ||
console.warn("i was called") | ||
fetchNextPage() | ||
}} | ||
/> | ||
</> | ||
</Box> | ||
) | ||
} | ||
} | ||
|
@@ -268,8 +324,19 @@ export default createPaginationContainer( | |
edges { | ||
node { | ||
id | ||
title | ||
image { | ||
url(version: "large") | ||
aspectRatio | ||
} | ||
...ArtworkGridItem_artwork | ||
} | ||
} | ||
pageInfo { | ||
hasNextPage | ||
startCursor | ||
endCursor | ||
} | ||
counts { | ||
total | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,7 @@ export const StickyTabPage: React.FC<StickyTabPageProps> = ({ | |
> | ||
{tabs.map(({ content }, index) => { | ||
return ( | ||
<View style={{ flex: 1, width }} key={index}> | ||
<View style={{ backgroundColor: "green", flex: 1, width }} key={index}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can also be removed, it was added for debugging |
||
<StickyTabPageFlatListContext.Provider | ||
value={{ | ||
tabIsActive: Animated.eq(index, activeTabIndexNative), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { OwnerType } from "@artsy/cohesion" | ||
import { MasonryFlashList, MasonryFlashListScrollEvent } from "@shopify/flash-list" | ||
import { NewWorksForYou_viewer$data } from "__generated__/NewWorksForYou_viewer.graphql" | ||
import { NewWorksForYouQuery } from "__generated__/NewWorksForYouQuery.graphql" | ||
import { InfiniteScrollArtworksGridContainer } from "app/Components/ArtworkGrids/InfiniteScrollArtworksGrid" | ||
import { PageWithSimpleHeader } from "app/Components/PageWithSimpleHeader" | ||
import { defaultEnvironment } from "app/relay/createEnvironment" | ||
import { extractNodes } from "app/utils/extractNodes" | ||
import { PlaceholderGrid, ProvidePlaceholderContext } from "app/utils/placeholders" | ||
import { renderWithPlaceholder } from "app/utils/renderWithPlaceholder" | ||
import { ProvideScreenTrackingWithCohesionSchema } from "app/utils/track" | ||
import { screen } from "app/utils/track/helpers" | ||
import { Box, SimpleMessage, Spacer } from "palette" | ||
import { Box, OpaqueImageView, SimpleMessage, Spacer, Text, useSpace } from "palette" | ||
import { createPaginationContainer, graphql, QueryRenderer, RelayPaginationProp } from "react-relay" | ||
import { useScreenDimensions } from "shared/hooks" | ||
|
||
const SCREEN_TITLE = "New Works for You" | ||
const PAGE_SIZE = 100 | ||
|
@@ -20,13 +23,18 @@ interface NewWorksForYouProps { | |
} | ||
|
||
const NewWorksForYou: React.FC<NewWorksForYouProps> = ({ viewer }) => { | ||
const space = useSpace() | ||
const test = extractNodes(viewer.artworks) | ||
const { width } = useScreenDimensions() | ||
console.warn({ test }) | ||
|
||
return ( | ||
<ProvideScreenTrackingWithCohesionSchema | ||
info={screen({ context_screen_owner_type: OwnerType.newWorksForYou })} | ||
> | ||
<PageWithSimpleHeader title={SCREEN_TITLE}> | ||
<Box> | ||
{!!viewer.artworks?.edges?.length ? ( | ||
{/* <Box> */} | ||
{/* {!!viewer.artworks?.edges?.length ? ( | ||
<InfiniteScrollArtworksGridContainer | ||
connection={viewer.artworks!} | ||
loadMore={() => null} | ||
|
@@ -40,8 +48,30 @@ const NewWorksForYou: React.FC<NewWorksForYouProps> = ({ viewer }) => { | |
/> | ||
) : ( | ||
<SimpleMessage m={2}>Nothing yet. Please check back later.</SimpleMessage> | ||
)} | ||
</Box> | ||
)} */} | ||
<MasonryFlashList | ||
contentContainerStyle={{ paddingVertical: space(2) }} | ||
numColumns={2} | ||
data={test} | ||
estimatedItemSize={width / 2} | ||
renderItem={({ item }) => { | ||
console.warn({ img: item.image?.url }) | ||
return ( | ||
<Box mx={1}> | ||
<OpaqueImageView | ||
imageURL={item.image?.url} | ||
width={width / 2 - space("2")} | ||
aspectRatio={item.image?.aspectRatio} | ||
/> | ||
<Text>{item.title}</Text> | ||
</Box> | ||
) | ||
}} | ||
ListEmptyComponent={ | ||
<SimpleMessage m={2}>Nothing yet. Please check back later.</SimpleMessage> | ||
} | ||
/> | ||
Comment on lines
+52
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without the need of infinite scrolling flashlist works amazingly well without issues. |
||
{/* </Box> */} | ||
</PageWithSimpleHeader> | ||
</ProvideScreenTrackingWithCohesionSchema> | ||
) | ||
|
@@ -62,9 +92,13 @@ export const NewWorksForYouFragmentContainer = createPaginationContainer( | |
edges { | ||
node { | ||
id | ||
title | ||
image { | ||
url(version: "large") | ||
aspectRatio | ||
} | ||
} | ||
} | ||
...InfiniteScrollArtworksGrid_connection | ||
} | ||
} | ||
`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3633,6 +3633,14 @@ | |
xcode "3.0.1" | ||
yargs "^16.2.0" | ||
|
||
"@shopify/[email protected]": | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/@shopify/flash-list/-/flash-list-1.4.0.tgz#cf299486ec9a7c97b7a8b1e8b6bf144a78141ed6" | ||
integrity sha512-PvPOyk353LuETFnNA038+QaJsAFlCQ2TYC7DHP3YnYqTX72g2BM6qLoLsPaptXKuoXX+dinOo0MbEm7HDjTy1g== | ||
dependencies: | ||
recyclerlistview "4.2.0" | ||
tslib "2.4.0" | ||
|
||
"@sideway/address@^4.1.3": | ||
version "4.1.3" | ||
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.3.tgz#d93cce5d45c5daec92ad76db492cc2ee3c64ab27" | ||
|
@@ -10317,7 +10325,7 @@ lodash.compact@^3.0.1: | |
resolved "https://registry.yarnpkg.com/lodash.compact/-/lodash.compact-3.0.1.tgz#540ce3837745975807471e16b4a2ba21e7256ca5" | ||
integrity sha1-VAzjg3dFl1gHRx4WtKK6IeclbKU= | ||
|
||
lodash.debounce@^4.0.8: | ||
lodash.debounce@4.0.8, lodash.debounce@^4.0.8: | ||
version "4.0.8" | ||
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" | ||
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168= | ||
|
@@ -12159,7 +12167,7 @@ [email protected]: | |
object-assign "^4.1.1" | ||
react-is "^16.8.1" | ||
|
||
prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: | ||
prop-types@15.8.1, prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: | ||
version "15.8.1" | ||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" | ||
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== | ||
|
@@ -12985,6 +12993,15 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/recursive-readdir-sync/-/recursive-readdir-sync-1.0.6.tgz#1dbf6d32f3c5bb8d3cde97a6c588d547a9e13d56" | ||
integrity sha1-Hb9tMvPFu4083pemxYjVR6nhPVY= | ||
|
||
[email protected]: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/recyclerlistview/-/recyclerlistview-4.2.0.tgz#a140149aaa470c9787a1426452651934240d69ef" | ||
integrity sha512-uuBCi0c+ggqHKwrzPX4Z/mJOzsBbjZEAwGGmlwpD/sD7raXixdAbdJ6BTcAmuWG50Cg4ru9p12M94Njwhr/27A== | ||
dependencies: | ||
lodash.debounce "4.0.8" | ||
prop-types "15.8.1" | ||
ts-object-utils "0.0.5" | ||
|
||
redent@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f" | ||
|
@@ -14616,6 +14633,11 @@ [email protected]: | |
source-map-support "^0.5.6" | ||
yn "^3.0.0" | ||
|
||
[email protected]: | ||
version "0.0.5" | ||
resolved "https://registry.yarnpkg.com/ts-object-utils/-/ts-object-utils-0.0.5.tgz#95361cdecd7e52167cfc5e634c76345e90a26077" | ||
integrity sha512-iV0GvHqOmilbIKJsfyfJY9/dNHCs969z3so90dQWsO1eMMozvTpnB1MEaUbb3FYtZTGjv5sIy/xmslEz0Rg2TA== | ||
|
||
ts-toolbelt@^6.1.6: | ||
version "6.15.5" | ||
resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-6.15.5.tgz#cb3b43ed725cb63644782c64fbcad7d8f28c0a83" | ||
|
@@ -14626,6 +14648,11 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" | ||
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== | ||
|
||
[email protected]: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" | ||
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== | ||
|
||
tslib@^1, tslib@^1.10.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: | ||
version "1.14.1" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't add the height here the loadmore is triggered all the time.