NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

How to layout DeckSwiper with flex?

Open lsps9150414 opened this issue 9 years ago • 10 comments

My goal:

Note the red box is a <View /> inside the same container as the <DeckSwiper />. simulator screen shot 2017 6 30 1 09 32

My code:

render() {
    return (
      <View style={{ flex: 1, backgroundColor: 'pink' }}>
        <DeckSwiper
          dataSource={this.props.cards}
          renderItem={this.renderCard}
          onSwipeRight={() => {}}
        />
        <View style={{ backgroundColor: 'red', height: 80 }} />
      </View>
    );
  }

What I get:

Q1. Note that the red box is on the top. Seems DeckSwiper has no height?

Q2. Is there any way to give DeckSwiper the style flex: 1 to make it fill the height? (So that the cards can fill the height with flex: 1 as well)

simulator screen shot 2017 6 30 1 10 24

lsps9150414 avatar Jun 30 '17 05:06 lsps9150414

@lsps9150414 DeckSwiper, by default is absolute positioned, thus the View comes over it. You can position absolute your View and place it below DeckSwiper.

shivrajkumar avatar Jun 30 '17 06:06 shivrajkumar

@shivrajkumar Thanks! Is there any way to override it and not break things? Or can I give it bottom : 0 and wraps it inside another flex view so that it stretch with the wrapper view?

lsps9150414 avatar Jul 02 '17 05:07 lsps9150414

@lsps9150414 I don't think it will make any difference. But you can surely try and let us know if that works for you

shivrajkumar avatar Jul 11 '17 05:07 shivrajkumar

@shivrajkumar the problem is that I can't give <DeckSwiper /> any custom styles since style prop is not exposed, or is it?

lsps9150414 avatar Jul 12 '17 07:07 lsps9150414

@lsps9150414 You can just wrap your Deck inside a View, give it the style rules

shivrajkumar avatar Sep 12 '17 06:09 shivrajkumar

Closing due to inactivity

akhil-ga avatar Nov 06 '17 10:11 akhil-ga

Any suggestion on how to use deckSwipper with flex ?

gregoirelemoulant avatar Jul 25 '18 12:07 gregoirelemoulant

@shivrajkumar I am not able to set the height of the parent view (green border view equal to black border view)

capture d ecran 2018-07-25 a 10 28 42
<View style={styles.wrapper1} >
            <DeckSwiper
                looping = {false}
                dataSource={this.getStack()}
                renderItem={item =>
                  <View style={styles.wrapper}>

                  </View>
                }
                onSwipeRight={() => this.updateDeckSize()}
                onSwipeLeft={() => this.updateDeckSize()}
            />
</View>

both wrapper & wrapper1 are

position: 'absolute', left: 0, top: 0, right:0, bottom:0

Any idea ?

Thanks for the help

gregoireLem avatar Jul 25 '18 14:07 gregoireLem

@lsps9150414, @akhil-geekyants - This is an issue for me as well, I can't center the DeckSwiper in a flexed Content view using justifyContent: 'center'

How can we center this component in a flexed component?

kodayashi avatar Jan 20 '19 23:01 kodayashi

Hi @lsps9150414 , @kodayashi , DeckSwiper doesn't work with flex. You can align it with the below style. Closing this for now.

<View style={{position: 'relative', top: 100}}>
      <DeckSwiper ... />
</View>

hanykumar avatar Aug 24 '20 15:08 hanykumar