-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Inline style flex properties are ignored by React #798
Comments
I can obviously also set the flex props using a <div style={{ flexGrow: 0, flexBasis: '33.333%', }} /> ... but I want to use |
This is an issue in |
That React issue has been open since 2014, so I'm not expecting a quick fix. Is there any way of avoiding using |
Yes, I can see how long that issue has been open and I'm currently looking into this. |
Upstream PR facebook/react#12181 |
Thanks for having a look at this! It would be nice to see it fixed in React :) |
Updates the 'setValueForStyle' implementation to support style values that contain "!important". This allows the 'flex{Basis,Grow,Shrink}' values created by the style resolver to be applied. They currently use the important priority as a work-around for browser-inconsistencies in the 'flex' shorthand. Upstream fix: facebook/react#12181 Ref #798
Updates the 'setValueForStyle' implementation to support style values that contain "!important". This allows the 'flex{Basis,Grow,Shrink}' values created by the style resolver to be applied. They currently use the important priority as a work-around for browser-inconsistencies in the 'flex' shorthand. Upstream fix: facebook/react#12181 Ref #798
Updates the 'setValueForStyle' implementation to support style values that contain "!important". This allows the 'flex{Basis,Grow,Shrink}' values created by the style resolver to be applied. They currently use the important priority as a work-around for browser-inconsistencies in the 'flex' shorthand. Upstream fix: facebook/react#12181 Ref #798 Close #813
Looks like React won't accept a bugfix for this until React 17. Avoid setting inline flex styles in the meantime. |
Yeah I can kind of understand that they don't want to take the risk of something breaking because some existing code relying on React to ignore
Unfortunately I can't really do that if I want to create a responsive layout with flexbox for both web and native. As a workaround I have created an extra wrapping component that uses |
Do you really need to dynamically calculate a new value for |
I have a few breakpoints, e.g. |
Ok that makes it easy for you to define the styles ahead of time (which also improves render perf) and avoid this issue. |
Sorry, I don't quite get what you mean. Is there a way for me to avoid setting inline styles (e.g. using StyleSheet)? I already have the styles defined for each breakpoint, and then when the window size hits a breakpoint, I use |
You don't need inline styles. Conditionally apply the flex style as needed
There's more about how to work with styles in the docs |
I was also thinking that it would look something like that. The reason why I chose to use inline styles is that the code is a bit easier to read that way. In this case it makes sense to use |
@necolas what about adding a mention to the FAQ to not use flex props with inline styles, but to use StyleSheet instead? https://github.com/necolas/react-native-web/blob/master/website/guides/style.md#faqs |
This will be fixed in the next release. There are also warnings thrown when And |
Do you want to request a feature or report a bug?
a bug.
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce
Currently setting any flex-box props with
style
property<View style={{ flexGrow: 0, flexBasis: '33.333%', }} />
will result in!important
to be added to the properties, which means that the properties get ignored by React.Setting flex props with style prop works just fine in React Native.
My use case is that I want to do a responsive layout where
flex-basis
gets changed based on the viewport width. That is why I need to use thestyle
property.What is the expected behavior?
react-native-web
should match the behavior in React native and support setting flex props using inline styles.Environment (include versions). Did this work in previous versions?
The text was updated successfully, but these errors were encountered: