Waleed Arshad Waleed Arshad - 1 year ago 361
React JSX Question

Dynamic inilne style with default StyleSheet React Native

I need to give dynamic inline style with static default stylesheet style. How can I achieve this

<View
style={[styles.card,{{width:width, height: height}}]}>
<View style={styles.card}>
<Text>
<Image
source={{uri: this.props.media.image_url}}
style={{width:width, height: this.props.media.height}}/>
</Text>
</View>
</View>


Above code is not working for me.

Answer Source

Nope, the problem isn't the order, you haven't passed the dynamic(inline styles) properly. You wrapped them in additional curly braces

Change this:

style={[styles.card,{{width:width,  height: height}}]}

to:

style={[styles.card,{width:width,  height: height}]}

You have actually done the same thing in your answer above.