-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Styles with percentage values #364
Comments
// In render:
return (
<View>
// The width will be split evenly between the two views.
<View style={{flex: 1}}/>
<View style={{flex: 1}}/>
</View>
)
// Or:
return (
<View>
// The second view will be double the width of the first.
<View style={{flex: 0.5}}/>
<View style={{flex: 1}}/>
</View>
) |
It just seems weird to me to substitute |
I agree with you, having percentage will help a lot on styling the components |
Also this won't work for images. |
+1 |
+1 this would really make styling components so much easier. |
Send a PR to https://github.com/facebook/css-layout, which is the layout engine that React Native uses. |
This is a good way to get 100%. If you add |
This would definitely be nice to have for images as @despairblue mentioned. +1 |
Sounds reasonable @tommcgurl - check out facebook/css-layout and create an issue there, maybe someone will be up for implementing it 😄 |
Thanks @brentvatne, I'll definitely check that out 👍 |
Until this is supported natively you can try https://github.com/vitalets/react-native-extended-stylesheet that supports percentage in styles for single orientation layout. |
Why not just write flex like this if you want %
just add a empty view as the spacer and you'r of to the races |
Has this been changed recently? I have working code, that uses '100%' in width and height. I also came across Yellobox.js in the RN repo that uses percentages (https://github.com/facebook/react-native/blob/9f33fe258312987f490cc0f3a71c0c4f93494e7f/Libraries/ReactNative/YellowBox.js). However, I can't find any mention of this in the documentation Is this unintended or is the documentation lacking? |
Percentage value is not supported for transform yet, I guess. |
How to add condition landscape in hide some section. using react-native. |
When using a property with the type of
number
, it's not possible to use percentage-based values.It would be nice to support this, so you don't have to calculate the value to
px
yourself. Using astring
would also allow other units to be used — If usingnumber
type, it would still bepx
-based value.This would also make it easy to make things responsive.
The text was updated successfully, but these errors were encountered: