Skip to content

Commit

Permalink
made artwork card fill content area
Browse files Browse the repository at this point in the history
  • Loading branch information
iskounen committed Dec 17, 2024
1 parent e718291 commit 03cba7b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 68 deletions.
14 changes: 10 additions & 4 deletions src/app/Components/FancySwiper/FancySwiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ export const OFFSET_X = 100

interface FancySwiperProps {
cards: Card[]
onSwipeRight: () => void
hideActionButtons?: boolean
onSwipeLeft: () => void
onSwipeRight: () => void
}

export const FancySwiper = ({ cards, onSwipeRight, onSwipeLeft }: FancySwiperProps) => {
export const FancySwiper = ({
cards,
hideActionButtons = false,
onSwipeLeft,
onSwipeRight,
}: FancySwiperProps) => {
const remainingCards = cards.reverse()
const swiper = useRef<Animated.ValueXY>(new Animated.ValueXY()).current

Expand Down Expand Up @@ -66,7 +72,7 @@ export const FancySwiper = ({ cards, onSwipeRight, onSwipeLeft }: FancySwiperPro

return (
<>
<Flex justifyContent="center" alignItems="center" flex={1}>
<Flex flex={1}>
{remainingCards.map((card, index) => {
const isTopCard = index === remainingCards.length - 1

Expand All @@ -84,7 +90,7 @@ export const FancySwiper = ({ cards, onSwipeRight, onSwipeLeft }: FancySwiperPro
)
})}
</Flex>
<FancySwiperIcons swiper={swiper} OnPress={onSwipeHandler} />
{!hideActionButtons && <FancySwiperIcons swiper={swiper} OnPress={onSwipeHandler} />}
</>
)
}
8 changes: 6 additions & 2 deletions src/app/Components/FancySwiper/FancySwiperCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo } from "react"
import { Animated, GestureResponderHandlers } from "react-native"
import { Animated, GestureResponderHandlers, StyleSheet } from "react-native"
import { OFFSET_X } from "./FancySwiper"

export interface Card {
Expand All @@ -26,7 +26,11 @@ export const FancySwiperCard = memo(

return (
<Animated.View
style={[{ position: "absolute", zIndex: -1 }, isTopCard && animatedStyle]}
style={[
StyleSheet.absoluteFillObject,
{ zIndex: -1, backgroundColor: "white" },
isTopCard && animatedStyle,
]}
{...rest}
>
{card.jsx}
Expand Down
90 changes: 39 additions & 51 deletions src/app/Scenes/InfiniteDiscovery/InfiniteDiscovery.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
Button,
Color,
Flex,
Screen,
Text,
Touchable,
useScreenDimensions,
useTheme,
} from "@artsy/palette-mobile"
import { Button, Flex, Image, Screen, Text, Touchable, useTheme } from "@artsy/palette-mobile"
import { FancySwiper } from "app/Components/FancySwiper/FancySwiper"
import { Card } from "app/Components/FancySwiper/FancySwiperCard"
import { InfiniteDiscoveryContext } from "app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext"
import { navigate } from "app/system/navigation/navigate"

Expand All @@ -21,6 +13,8 @@ export const InfiniteDiscoveryView: React.FC = () => {
}

export const InfiniteDiscovery: React.FC = () => {
const { color } = useTheme()

const artworks = InfiniteDiscoveryContext.useStoreState((state) => state.artworks)
const currentArtwork = InfiniteDiscoveryContext.useStoreState((state) => state.currentArtwork)
const goToPreviousArtwork = InfiniteDiscoveryContext.useStoreActions(
Expand All @@ -30,7 +24,8 @@ export const InfiniteDiscovery: React.FC = () => {
(actions) => actions.goToNextArtwork
)

const canGoBack = artworks.length && currentArtwork !== artworks[0]
const currentArtworkIndex = artworks.indexOf(currentArtwork)
const canGoBack = currentArtworkIndex > 0

const handleBackPressed = () => {
goToPreviousArtwork()
Expand All @@ -48,51 +43,17 @@ export const InfiniteDiscovery: React.FC = () => {
goToNextArtwork()
}

return (
<Screen>
<Screen.Header
title="Discovery"
leftElements={
<Touchable onPress={handleBackPressed}>
<Text variant="xs">Back</Text>
</Touchable>
}
hideLeftElements={!canGoBack}
rightElements={
<Touchable onPress={handleExitPressed}>
<Text variant="xs">Exit</Text>
</Touchable>
}
/>
<Screen.Body>
<FancySwiper
cards={artworkCards(artworks)}
onSwipeRight={handleSwipedRight}
onSwipeLeft={handleSwipedLeft}
/>
</Screen.Body>
</Screen>
)
}

const artworkCards = (artworks: Color[]) => {
return artworks.map((artwork) => {
const { color, space } = useTheme()
const { width } = useScreenDimensions()
const artworkCards: Card[] = artworks.slice(currentArtworkIndex).map((artwork) => {
return {
jsx: (
<Flex width={width - space(4)} height={500} backgroundColor="white">
<>
<Flex flexDirection="row" justifyContent="space-between" testID="artist-header">
<Text variant="sm-display">Artist Name</Text>
<Button variant="outlineGray">Follow</Button>
</Flex>
<Flex
backgroundColor={color(artwork)}
height={250}
testID="image-frame"
width={250}
></Flex>
<Flex testID="multi-image-tabs" />
<Flex alignItems="center">
<Image src="https://d32dm0rphc51dk.cloudfront.net/Wor_U4FSvsAmEAEFj1iyVg/medium.jpg" />
</Flex>
<Flex flexDirection="row" justifyContent="space-between" testID="artwork-info">
<Flex>
<Flex flexDirection="row">
Expand All @@ -107,9 +68,36 @@ const artworkCards = (artworks: Color[]) => {
</Flex>
<Button variant="fillGray">Save</Button>
</Flex>
</Flex>
</>
),
id: artwork,
}
})

return (
<Screen>
<Screen.Header
title="Discovery"
leftElements={
<Touchable onPress={handleBackPressed}>
<Text variant="xs">Back</Text>
</Touchable>
}
hideLeftElements={!canGoBack}
rightElements={
<Touchable onPress={handleExitPressed}>
<Text variant="xs">Exit</Text>
</Touchable>
}
/>
<Screen.Body fullwidth>
<FancySwiper
cards={artworkCards}
hideActionButtons
onSwipeRight={handleSwipedRight}
onSwipeLeft={handleSwipedLeft}
/>
</Screen.Body>
</Screen>
)
}
13 changes: 2 additions & 11 deletions src/app/Scenes/InfiniteDiscovery/InfiniteDiscoveryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,8 @@ export interface InfiniteDiscoveryContextModel {
}

export const initialModel: InfiniteDiscoveryContextModel = {
artworks: [
"black100",
"white100",
"green100",
"yellow100",
"orange100",
"red100",
"purple100",
"blue100",
],
currentArtwork: "black100",
artworks: ["red100", "green100", "blue100"],
currentArtwork: "red100",
goToPreviousArtwork: action((state) => {
const currentIndex = state.artworks.indexOf(state.currentArtwork)
if (currentIndex - 1 < 0) return
Expand Down

0 comments on commit 03cba7b

Please sign in to comment.