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

Reset to first card when modal is presented #46

Closed
acesetmatch opened this issue Aug 7, 2017 · 8 comments
Closed

Reset to first card when modal is presented #46

acesetmatch opened this issue Aug 7, 2017 · 8 comments
Labels

Comments

@acesetmatch
Copy link

acesetmatch commented Aug 7, 2017

I have a modal that presents whenever the user swipes Right. The view is presented by setting a isModalVisible state variable. However, when I dismiss the modal view, the card stack resets to the first card. Why does this occur and how do I fix this?

Here is my code:

<Swiper
          ref={swiper => {
            this.swiper = swiper;
          }}
          infinite={true}
          cards={this.state.cards}
          cardIndex={this.state.cardIndex}
          cardVerticalMargin={(Platform.OS === 'ios') ? 15: 160}
          marginTop={(Platform.OS === 'ios') ? 0: -150}
          marginBottom={(Platform.OS === 'ios') ? 115 : 0}
          backgroundColor={'#ffffff'}
          renderCard={this.renderCard}
          onSwipedAll={this.onSwipedAllCards}
          onSwiped={this.onSwiped}
          onSwipedRight={this.handleYup}
          onSwipedLeft={this.handleNope}
          showSecondCard={true}
          overlayLabels={{
            bottom: {
              title: 'BLEAH',
              swipeColor: '#9262C2',
              backgroundOpacity: '0.75',
              fontColor: '#FFF'
            },
            left: {
              title: 'NOPE',
              swipeColor: '#FF6C6C',
              backgroundOpacity: '0.75',
              fontColor: '#FFF'
            },
            right: {
              title: 'LIKE',
              swipeColor: '#4CCC93',
              backgroundOpacity: '0.75',
              fontColor: '#FFF'
            },
            top: {
              title: 'SUPER LIKE',
              swipeColor: '#4EB8B7',
              backgroundOpacity: '0.75',
              fontColor: '#FFF'
            }
          }}
          animateOverlayLabelsOpacity
          animateCardOpacity
        >
      </Swiper>
@alexbrillant
Copy link
Owner

@acesetmatch I think 1.3.3 fixed it. closing the issue.

@DFelten
Copy link

DFelten commented Oct 11, 2017

This problem is still there with version 1.4.2. I've created a modal which appears when tapping on the card and when opening the modal, the card stack resets to the first card.

onTapCard = (cardIndex) => {
  this.setState({currentCardIndex: cardIndex});
  this.setDetailsVisible(true);
};
<Swiper
  ref={swiper => {
    this.swiper = swiper;
  }}
  cards={this.state.cards}
  renderCard={this.renderCard}
  onTapCard={this.onTapCard}
  cardIndex={this.state.cardIndex}
  horizontalSwipe={this.state.horizontalSwipe}
  verticalSwipe={this.state.verticalSwipe}
  showSecondCard={this.state.showNextCard}
  goBackToPreviousCardOnSwipeBottom={this.state.verticalSwipeBack}
  goBackToPreviousCardOnSwipeRight={this.state.horizontalSwipeBack}
  infinite={this.state.infiniteSwiping}
  backgroundColor={Colors.transparent}
  cardStyle={styles.cardSwiper}
  cardVerticalMargin={10}>
</Swiper>
<Modal
  animationType="slide"
  transparent={false}
  visible={this.state.detailsVisible}
  onRequestClose={() => {
    this.setDetailsVisible(false);
    this.setState({cardIndex: this.state.currentCardIndex}); // workaround with warning
  }}
>

In the moment I need so set the cardIndex manually to the current index, but then there is a warning.

Warning: flattenChildren(...): Encountered two children with the same key, 1. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

An other problem with this workaround is that the next visible card is now the second card and not the next one.

this.swiper.jumpToCardIndex(currentIndex); when closing the modal is also not working, nothing happens.

@vivianmauer
Copy link

I have the same problem, when open modal, cards resets to the first card

@DFelten you can work around this issue?

@unmec
Copy link

unmec commented Dec 18, 2017

I guess this issue should be reopened.
I looked into example project in the repo and it throws "Encountered two children with the same key" warning too.

@bispul
Copy link

bispul commented Dec 28, 2017

yeah I am getting the following error and it resets the card to first index:

Warning: flattenChildren(...): Encountered two children with the same key, 0. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

@zelgan90
Copy link

zelgan90 commented Feb 6, 2018

Has anyone found a solution or effective workaround for this? This component works much better than other swipers, but things like this are almost a deal breaker.

@yonahforst
Copy link

please reopen

@mrexodia
Copy link

When setting infinite={true} you need to have at least stackSize elements in your cards, which works around the issue for me.

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

No branches or pull requests

9 participants