Skip to content

Swipeable cards #3694

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

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

Swipeable cards #3694

wants to merge 3 commits into from

Conversation

avishain
Copy link
Contributor

@avishain avishain commented Apr 24, 2025

Description

New component - addition to existing library.

The component name is SwipeableCards.
It receives the following props:

  • currentItem: T;
  • nextItems: T[];
  • onSwipe?: SwipeableCardProps['onSwipe'];
  • currentIndex: number;
  • renderNextCard: (nextItem: T) => JSX.Element;
  • renderRightCard: () => JSX.Element;
  • renderLeftCard: () => JSX.Element;
  • renderMainCard: () => JSX.Element;

Changelog

SwipeableCard - new component

Usage example

interface MyUseCaseSwipeableCardsProps extends MyUseCaseItemProps {
  items: MyUseCaseItem[];
  currentIndex: number;
}

const MyUseCaseSwipeableCards = (props: MyUseCaseSwipeableCardsProps) => {
  const {items, currentIndex} = props;

  const currentItem = items[currentIndex];
  const nextFeedItems = items.slice(currentIndex + 1, currentIndex + 5);

  const onSwipe = {
    right: () => {
      // DO SOMETHING 1
    },
    left: () => {
      // DO SOMETHING 2
    },
  };

  const renderMainCard = () => {
    return (
      <MyUseCaseItem item={currentItem} />
    );
  };

  const renderLeftCard = () => {
    return (
      <View flex center backgroundColor={Colors.red40}>
        <Text text20BL white>LEFT</Text>
      </View>
    );
  };
  const renderRightCard = () => {
    return (
      <View flex center backgroundColor={Colors.yellow40}>
        <Text text20BL white>RIGHT</Text>
      </View>
    );
  };

  const renderPlaceHolderCard = (item: MyUseCaseItemType) => {
    return (
      <View flex center>
        <Text text20BL white>{item.id}</Text>
        <Image source={Assets.illustrations.placeholderCover} size={125} />
      </View>
    );
  };

  return (
    <SwipeableCardsView
      nextItems={nextFeedItems}
      renderMainCard={renderMainCard}
      onSwipe={onSwipe}
      currentIndex={currentIndex}
      currentItem={currentItem}
      renderLeftCard={renderLeftCard}
      renderRightCard={renderRightCard}
      renderPlaceHolderCard={renderPlaceHolderCard}
    />
  );
};

export default MyUseCaseSwipeableCards;

Visuals



drawing

Additional info

None

@ethanshar ethanshar self-assigned this Apr 27, 2025
@M-i-k-e-l M-i-k-e-l self-requested a review April 30, 2025 05:58
@M-i-k-e-l M-i-k-e-l self-assigned this Apr 30, 2025
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