0

Here is my scenario Using component i am displaying the images.

var ImageRender = React.createClass({
    render : function(){
       return (<View style={{marginLeft:15,marginRight:15}}>
                   <Image source={uri} style={{height:220}}/>
               </View>)
    }
});

here if i specify width for image then i opened this component in another type of resolution that image width is not suitable.how to achieve this image widt dynamically

1 Answer 1

1

first get the device dimensions...

var Dimensions = require('Dimensions');
var {
  width,
  height
} = Dimensions.get('window');

then use them...

var ImageRender = React.createClass({ render : function(){ return (<View style={{marginLeft:15,marginRight:15}}> <Image source={uri} style={{height:220, width:width}}/> </View>) } });
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer.It's worked but i am getting one error i.e JSON value '{width=375} of type NSDictionary cannot be converted to NSNumber.How to convert json object to number using react native
maybe I didn't need to wrap the value in its own curly brackets. try without

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.