RFC: Improvements to compat.native to support resolving vars correctly and access to the inherited text style#501
Open
martinbooth wants to merge 1 commit into
Open
RFC: Improvements to compat.native to support resolving vars correctly and access to the inherited text style#501martinbooth wants to merge 1 commit into
martinbooth wants to merge 1 commit into
Conversation
workflow: benchmarks/perf (native)Comparison of performance test results, measured in operations per second. Larger is better.
|
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
Summary:
Add a second argument to the react.compat callback which exposes StrictReactNativeMetaProps
StrictReactNativeMetaProps has:
# resolveStyleValue
A function that will resolve variables to their concrete values
```
resolveStyleValue('red') // → 'red' (no var → returned unchanged)
resolveStyleValue('10px') // → '10px' (no var → unchanged)
resolveStyleValue(vars.brand) // → 'magenta' (token resolved through the theme cascade)
resolveStyleValue('var(--brand)') // → 'magenta' (explicit var() resolved)
resolveStyleValue('var(--missing)') // → null (unresolvable reference)
```
- Ancestor/ingerited theme tokens correctly resolve using this function
- Light/dark tokens resolve correctly
- Correctly resolves fallbacks, nested vars, non color vars, etc
- Avoid exposing any private internals
# inheritedTextStyle
Provides access to the text style that would be inherrited by child component
Importantly, it provide access to the color which is used on things like `svg` elements
# A more real world example:
```
import { compat } from 'react-strict-dom';
import { Path as RNPath } from 'react-native-svg';
function Path({ style, fill, stroke, ...rest }) {
return (
<compat.native style={style}>
{(nativeProps, { inheritedTextStyle, resolveStyleValue }) => (
<RNPath
{...rest}
// RSD doesn't know about SVG paint props, so resolve var()/tokens yourself:
fill={fill != null ? resolveStyleValue(fill) : undefined}
stroke={stroke != null ? resolveStyleValue(stroke) : undefined}
// wire CSS `color` inheritance so `currentColor` works:
color={inheritedTextStyle.color}
/>
)}
</compat.native>
);
}
```
7b8e4d1 to
7e156de
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a second argument to the react.compat callback which exposes StrictReactNativeMetaProps
StrictReactNativeMetaProps has:
resolveStyleValue
A function that will resolve variables to their concrete values
inheritedTextStyle
Provides access to the text style that would be inherrited by child component
Importantly, it provide access to the color which is used on things like
svgelementsA more real world example: