question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable stretch height on Carousel Container

See original GitHub issue

Hello,

I am having a problem here, current carousel height is stretched. If i inspect there is a view that having flex:1. I have tried to set containerCustomStyle, contentContainerCustomStyle, slideStyle flex to 0 but the carousel still stretching the height.

<View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
  <View>
    <Carousel
      sliderWidth={width}
      itemWidth={width-70}
      showsHorizontalScrollIndicator={false}

      containerCustomStyle={{flex:0}}
      contentContainerCustomStyle={{flex:0,alignItems:'flex-start'}}
      slideStyle={{flex:0}}
      onSnapToItem={this.activeSlide}>

      {items}
    </Carousel>
  </View>
</View>

screenshot_20170412-173449

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
bd-arccommented, Sep 12, 2017

@mostafa No problem 😃 I’ll add the following to the documentation as soon as I’m finished with the update I’m currently working on.


Carousel’s stretched height

Since <Carousel /> is, ultimately, based on <ScrollView />, it inherits its default styles and particularly { flexGrow: 1 }. This means that, by default, the carousel container will stretch to fill all the available space.

If this is not what you’re after, you can prevent this behavior by passing { flexGrow: 0 } to the prop containerCustomStyle.

Alternatively, you can either use this prop to pass a custom height to the container, or wrap the carousel in a <View /> with a fixed height.

4reactions
bd-arccommented, Apr 21, 2017

@ariona After giving this a second thought, I realized that I’ve made a mistake: our <Carousel /> is basically a <ScrollView /> and, as such, inherits from its default styles, especially flexGrow: 1.

You should be able to deal with it thanks to the prop containerCustomStyle. I know you’ve tried flex: 0, but can you give flexGrow: 0 a try? If this doesn’t work, you should either use this prop to pass a custom height to the container or wrap the carousel in a <View /> with fixed height.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable stretch height on Carousel Container #57 - GitHub
Hello, I am having a problem here, current carousel height is stretched. If i inspect there is a view that having flex:1.
Read more >
carousel - Set caroseul to a fixed height and prevent images ...
Solution - 1. Make the container that holds the image to height:500px and use photoshop or any online tool to make the image's...
Read more >
Consistent Height Carousels with CSS Gradients and Object Fit
The documentation tells you to add an an image with a class of d-block w-100 That means that it will shrink or stretch...
Read more >
overscroll-behavior - CSS: Cascading Style Sheets | MDN
The overscroll-behavior CSS property sets what a browser does when reaching the boundary of a scrolling area.
Read more >
Carousel - Bootstrap
Carousels don't automatically normalize slide dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found