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.

Full width image using flexbox?

See original GitHub issue

I’m attempting to make an image full-width and came across a few stackoverflow questions related where the top upvoted answer was to use flexbox similarly to how i’m using it below. Although it doesn’t seem to display the image unless i set static widths on my styles property. Any ideas?

var styles = StyleSheet.create({
  canvasContainer: {
    flex:1,
    alignItems: 'stretch'
  },
  canvas: {
    flex:1
   // width: 200,
   // height: 200
  }
});
render: function() {
    return (
      <View style={styles.container}>
        <View style={styles.canvasContainer}>
          <Image
            source={{uri: 'http://imgs.steps.dragoart.com/how-to-draw-a-pony-step-7_1_000000053055_5.jpg'}}
            style={styles.canvas} />
        </View>
        <ScrollView
          style={styles.scrollView}
          scrollEventThrottle={200}
          contentInset={{top: 0}}
          >
          {this.state.messages.map(m => {
            return <Text style={styles.message}>Josh: {m}</Text>
          })}
        </ScrollView>
      </View>
    )
  }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:33 (1 by maintainers)

github_iconTop GitHub Comments

198reactions
yashvekariacommented, Apr 16, 2016

I have done according to this, Hope this code snippet might help you.

<Image style={styles.bgContainer} resizeMode='cover' source={require('./img/bg.png')} />

const styles = StyleSheet.create({ bgContainer: { flex:1, width: null, height: null } });

71reactions
clinyongcommented, May 18, 2016

I have done without flex.

local image

<View>
  <Image
    style={{height: 100, width: null}}
    source={require('./ad.png')}
  />
</View>

network image

<View>
  <Image
    style={{height: 100}}
    source={{uri: 'http://xxx.com/ad.png'}}
  />
</View>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Stretching an image inside a flex item to full width
I am playing around with CSS Flexbox and media ...
Read more >
Stretching an image inside a flex item to full width - CodePen
Answer to Stack Overflow question: http://stackoverflow.com/questions/35384232/stretching-an-image-inside-a-flex-item-to-full-width/35385309#35385309...
Read more >
Adaptive Photo Layout with Flexbox - CSS-Tricks
Flexbox is great for filling up rows by determining cell width based on cell content. This meant the images (landscape or portrait) all...
Read more >
How to Build a Full-Screen Responsive Page With Flexbox
In this tutorial, we'll learn how to build a full-screen responsive page with flexbox. Our page will include a full-screen background image, ...
Read more >
Full-width pinned layouts with flexbox - Zoe Mickley Gillenwater
Full -width pinned layouts with flexbox. Learn how to use flexbox to pin two things to opposite ends of the viewport with a...
Read more >

github_iconTop Related Medium Post

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