Conversation
| REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ | ||
| position, setPosition, yoga::Edge::All, "inset"); | ||
|
|
||
| #define APPLY_CALC_COMMON(fieldName, setPoints, setPercent, setDynamic) \ |
There was a problem hiding this comment.
nit: why does this need to be a macro?
There was a problem hiding this comment.
It does not - I wrote it as macros because this file already achieve similar functionality using macros (REBUILD_FIELD_YG_* stuff) and I got the feeling it would be more consistent.
Would you like me to rewrite it using template functions?
| /* | ||
| * Viewport size is size of the React Native's root view. | ||
| */ | ||
| Size viewportSize{}; |
There was a problem hiding this comment.
Ooh, this may be helpful in more places in the future 👍. If you had a PR for just the plumbing for e.g. this part of the change, would be quick to import and accept.
There was a problem hiding this comment.
I extracted it to the separated PR: #56209
| } | ||
|
|
||
| TEST(CSSCalc, simple_pixel_value) { | ||
| auto result = parseCalc("calc(10px)"); |
There was a problem hiding this comment.
I'm trying to figure out how CSSCalc works, more generically.
Ideally, any place where we use a specific CSS type, valid calc expression should work. So e.g. if we are parsing the result of a box-shadow, which expects a <length> in the middle, that length should be able to be some arbitrary calc() expression.
Like 0 calc(16px - 2px) should be valid, for reading something that requires two lengths.
Can we make that sort of scenario work? If we can do this sort of more generic substitution, it also gives us a way later to introduce variables.
| auto opResult = | ||
| parser.syntaxParser().consumeComponentValue<std::optional<char>>( | ||
| CSSDelimiter::None, [](const CSSPreservedToken &token) { | ||
| if (token.type() == CSSTokenType::Delim) { | ||
| auto sv = token.stringValue(); | ||
| if (!sv.empty() && (sv[0] == '+' || sv[0] == '-')) { | ||
| return std::optional<char>{sv[0]}; | ||
| } | ||
| } | ||
| return std::optional<char>{}; | ||
| }); |
There was a problem hiding this comment.
IIRC these aren't actually Delim tokens in the spec, but CSSTokenizer, didn't add any of the tokens for calc(), calc-constants, etc. This change will need to update tokenizer layer a bit. Adding tokenizer awareness of calc tokens, could be its own change, that would be easy to merge independently.
There was a problem hiding this comment.
Please take a look at my attempt to do that: #56234
I am just getting familiar with CSS spec, so let me know if things should land in different files or shape, I was a little confused. I explored a few potential solution and thought that this would be the most correct - but I am happy to revisit and adjust it.
Summary: Add viewport size to `LayoutContext` and wire it through Android and iOS layout setup so viewport dimensions are available during layout. This was extracted from the larger `calc()` work in PR #56162. ## Changelog: [GENERAL] [ADDED] - Add viewport size to LayoutContext Pull Request resolved: #56209 Test Plan: - This change is limited to internal layout plumbing in React Native core and does not alter external behavior on its own. - Validation for the actual `calc()` use cases will be covered in the follow-up work that consumes this plumbing. Reviewed By: christophpurrer Differential Revision: D98004758 Pulled By: NickGerleman fbshipit-source-id: 3fd6257b2c280442a41308af3e6eff30b51a3397
Why?
calc()is a core CSS primitive and a common expectation for developers. Adding it to React Native enables more expressive and maintainable styles without JS-side manual calculations. It improves parity across web and native worlds, reducing friction when switching from another platform.My tweet about this potential feature in React Native was really well received and many people expressed excitement about it.
Yoga PR link
Summary:
Bring Yoga dynamic value resolution into React Native and wire
calc()-driven values.Yoga resolves dynamic values during layout by calling back into React Native with layout context and dynamic id, allowing mixed-unit expressions to be evaluated just-in-time.
Changelog:
[GENERAL] [ADDED] - CSS calc() support
This PR includes RN-side integration needed to make Yoga dynamic values usable in renderer layout paths.
vw/vh-based expressions.Missing:
To keep this PR focused, some areas are intentionally out of scope and will follow in separate work.
Test Plan:
Added focused C++ tests for calc parsing/evaluation.
Broader platform and API-level testing will be expanded in follow-up PRs.
cc @NickGerleman