You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7b8e4d1
Browse filesBrowse the repository at this point in the historyBrowse files
feat: compat.native variable resolver and inheritedTextStyle
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>
);
}
```
0 commit comments