alexbrillant / react-native-deck-swiper

tinder like react-native deck swiper
ISC License
1.56k stars 465 forks source link

Modal popup should render the same info that is being rendered onto the card #393

Open RahulBhandari18 opened 1 year ago

RahulBhandari18 commented 1 year ago

I have a Modal screen component as well as the Swiper component to return. The onTapCard prop for thr Swiper component should change the state of the modal popup to make it visible. When the card is clicked, the modal should render the same image and text that is on the card that was clicked. The Modal component with the Swiper component is shown below where 'pictures' is the input data array in state. Any help would be appreciated.

HomeScreen extends Component { constructor (props) { super(props) this.state = { isVisible: false, currentPic: null, pictures: [... ], }; this.setCurrentPic = this.setCurrentPic.bind(this); };

setCurrentPic(id) { this.setState({currentPic: id}); }

onSwiped = (type) => { console.log(${type}) };

swipeLeft = () => { this.swiper.swipeLeft() };

render () { return (

{/* MODAL POPUP STARTS HERE */} {this.state.pictures.map((picture) => { return ( this.setState({ isVisible:!this.state.isVisible })} > { this.modal = modal }} animationType = {"fade"} onPress = {() => {this.setState( false );this.props.setCurrentPic(this.props.id)}} transparent = {true} visible = {this.state.isVisible} > this.setState(false)}>
        )
      })}

      {/* CARD STARTS HERE */}
      <Swiper
        ref={swiper => {
          this.swiper = swiper
        }}
        containerStyle={{ backgroundColor: 'transparent' }}
        backgroundColor={"4FD0E9"}
        //onSwiped={() => this.onSwiped('general')}
        onSwiped={() => this.setCurrentPic(this.props.id)}
        onSwipedLeft={() => this.onSwiped(0)}
        onSwipedRight={() => this.onSwiped(1)}
        onSwipedTop={() => this.onSwiped(2)}
        onSwipedBottom={() => this.onSwiped(-1)}
        onTapCard={() => this.setState({ isVisible:!this.state.isVisible })} // this one to be used for modal pop up
        cards={this.state.pictures}
        cardIndex={0}
        cardVerticalMargin={1}
        cardHorizontalMargin={10}
        swipeDirection= {''}
        renderCard={(card) => (

          {/* WHAT IS BEING RENDERED ONTO THE CARD */}
          <View 
            key={card.id}
            className="relative bg-blue h-3/4 rounded-xl"
          >
            <Image 
                className="absolute top-0 h-full w-full rounded-xl" 
                source={{ uri: card.photoURL}}
                //source={require(./logo.png)}
            />
          </View>
        )}
        stackSize={3}
        stackSeparation={1}
        animateOverlayLabelsOpacity
        animateCardOpacity
        swipeBackCard
      >
      </Swiper>
    </View>
    {/* CARD ENDS HERE */}
)

} }

export default HomeScreen;

alecdhansen commented 1 year ago

I would make sure to increase the index of your pictures array each time you swipe, so when you tap on the card the appropriate information will be available.