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.

Wrong size (width and height) when embedded in other components

See original GitHub issue

When <Swiper> is embedded into a component hierarchy, it will not fit in into the dimensions of the container. Both width and height are completely wrong and much to big.

Imagine the following screen:

- top bar 
- container (flex: 4)
  + swiper embedded in container (flex: 4)
  + bottom bar of container (flex: 1)
- bottom bar (flex: 1)

This looks like this and you can see, that the swiper gots dimensions far away from the size of the container component. screen shot 2016-05-23 at 20 18 32

I provided the whole code in a gist: https://gist.github.com/itinance/7d9c14f01bd0dd34008607f25c4391a7

When i set a specific height-attribute, everything works fine:

screen shot 2016-05-23 at 20 19 21

But to set a specific height destroys the flexibility of the whole flex based layout system.

Did i something wrong here?

This is the structure:

        return (
            <View style={{ flex: 1 }}>
                <NavigationBar
                  style={ styles.navBar }
                  title={titleConfig}
                  rightButton={rightButtonConfig}
                  leftButton={leftButtonConfig}>
                  </NavigationBar>

                <View style={styles.container}>
                    <View style={styles.topBox}>

                    </View>
                    <View style={styles.storyContainer}>

                        <View style={styles.storyImageContainer}>
                            <Swiper showsButtons={true} showsPagination={true} styles={styles.slider}>
                                <Image
                                    style={styles.sliderImage}
                                    source={{uri: 'https://upload.wikimedia.org/wikipedia/commons/f/fc/HGM_Raketengesch%C3%BCtz_1865.jpg'}}
                                  />
                            </Swiper>
                        </View>

                        <View style={styles.storyBox}>
                        </View>

                    </View>
                </View>
            </View>
        );

The styles you will find at the bottom of my gist.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

19reactions
itinancecommented, May 23, 2016

I’ve found a possible work around on application side:

I use state to manage the height of the swiper and change this height on the onLayout-Event of the parent container:

                    <View style={styles.storyImageContainer} onLayout={ (e) => {
                        var {x, y, width, height} = e.nativeEvent.layout;
                        this.setState({
                            swiperHeight: height
                        })
                    } }>
                        <Swiper showsButtons={true} showsPagination={true} styles={styles.slider} height={this.state.swiperHeight} >
                                                                  { slides... ..... }
                        </Swiper>
                    </View>
6reactions
itinancecommented, Sep 30, 2016

@jorfermo sorry, we’ve gave up here and switched in the end with all projects to https://github.com/zbtang/React-Native-ViewPager, where everything works fine from scratch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adjust width and height of iframe to fit with content in it
The content inside the iframe is dynamic, so I had to readjust the width and height of the iframe itself. I use React...
Read more >
Overflowing content - Learn web development | MDN
This box has a height and a width. This means that if there is too much content to be displayed within the assigned...
Read more >
Setting Height And Width On Images Is Important Again
To prevent layout shifts and improve performance scores, we need to always set width and height attributes on our images.
Read more >
CSS- Div- Be Careful When You Size Your Divs
It makes sense: both DIVs and tables can be nested, have HEIGHT and WIDTH attributes set, contain borders, etc. However, there is one...
Read more >
How do you change the size of an embedded Google Doc?
Can you get at the HTML? You need to put a width and height on the <iframe>. <iframe width=600 height=500 src=.
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