I want to style a component in my interface. The component must have a width of at least 200, but I want to let it grow with screen width to up to 600. But, sometimes people use tablets or huge phones. And I don't want the component to be able to grow with the screen forever. I want it to have a maximum width of 600.
And I know maxWidth is a thing that is, at least for now, not a part of the flexbox implementation in React Native... so, is there a reasonable way to do this today?
There is no such thing as "maxWidth" in React Native. You may want to style your component at run-time. Try playing with Dimensions . You can get screen width and screen height of the device and adjust width of your component accordingly.
To set the minimum width or height in React Native, we can set the minWidth and minHeight properties. to set the min width with minWidth and min height with minHeight . We can also set the max width with maxWidth and max height with maxHeight .
You can use the maxWidth
, maxHeight
, minWidth
, minHeight
layout properties supported by React Native.
Document here React Native layout props.
Example:
StyleSheet.create({
container: {
maxWidth: '80%', // <-- Max width is 80%
minHeight: 20, // <-- Min height is 20
},
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With