-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Merging styles onto children props #1048
Comments
@JohnyDays - you can get the actual backing stylesheet from the |
Great way to fix my use case thanks! |
@JohnyDays - good point. I believe it is put in the stylesheet registry for perf reasons. If you want to submit a PR with docs that would be awesome! 🚀 |
As a general rule, you don't want to mutate anything, what you want is to make a new object that has the old and new. In your case you can do var style = [child.props.style, { opacity: 0 }];
React.cloneElement(child, {style}) |
👍 to @vjeux's comment, should have pointed that out myself |
Also, looking up the registry is not going to do what you expect. If the style is an array, then it is going to crash. The proper way to extract information is to use flattenStyle, BUT there are very few reasons to ever use it. Please ask me if you think you need it, there is probably a better way |
My use case is the following, I am constructing a waterfall view, for which i need to:
Is there a better way to do that? On a sidenote, I attempted to use the solution provided in the other thread, but I cannot for the life of me figure out how to import StyleSheetRegistry, I have tried both from the React object and the StyleSheet object, do I have to use the absolute js path? Edit: My apologies I seem to have missed your first comment @vjeux, I will try it that way. Leaving this for posterity |
Right now there isn't a better way unfortunately right now. One thing you can do is to do setTimeout(0) instead of requestAnimationFrame in order to avoid skiping an entire frame |
I tried, the items did not have a width or height upon completing measure(). |
Ohh, you are right, nevermind me :( |
Hey thanks for the help! I have managed to complete the view, I will publish the component to npm once I am satisfied, but incase you were curious, this was how I was able to make it work(still a very small bug to be fixed, but it lays out the views perfectly) |
@JohnyDays - nice 😄 looking forward to seeing the module |
how is @JohnyDays doing? and @brentvatne cats are smarter than dogs :p |
(not my actual use case, just a sample of the problem)
Given the view
I need to iterate through the children, attributing to each of them the style {opacity:0}, and merging with any existing styles, however the content of child.props.style is an int instead of an object that can be merged.
Given this, my only option is to accept styles through a prop on the parent object, and map them to the children with their keys, this is obviously not a desirable solution. Am I missing something, or is this use case not intended to be supported?
For the record, my use case is a waterfall view, where i need to render the elements and then rearrange them after I know their sizes, but i imagine this applies to more use cases
The text was updated successfully, but these errors were encountered: