Skip to content

Commit feacf77

Browse files
committed
docs(native): v7 changesets + rn-css compatibility matrix + rn-web parity rule
26 changesets covering the v7 native surface (engine + polyfills + selectors). Each one describes user-observable behavior in consumer-facing terms (no internal API names or mechanism details), with code examples for selector and field-sizing features. Two earlier drafts were dropped during review because later changesets in the same release superseded them. AGENTS.md picks up the new "rn-web parity rule" section recording the invariants every polyfill must satisfy when targeting react-native-web (browser features pass through, RN-only prop lifts stay gated, sentinel intermediates short-circuit before the rn-web branch). docs/rn-css-compatibility.md updates compatibility rows for sibling combinators, :nth-child, :has, and field-sizing.
1 parent dfcfd7f commit feacf77

27 files changed

Lines changed: 291 additions & 13 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
`aspect-ratio` on React Native now accepts the spec's full grammar: a bare ratio (`16 / 9`), the keyword `auto`, or the two-value form `auto <ratio>` / `<ratio> auto`. The two-value form emits the ratio and logs a one-time dev warning that the `auto` half only honors intrinsic dimensions on replaced elements (styled `<Image>` and similar); for other styled views, drop the `auto` keyword to suppress the warning.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'styled-components': minor
3+
---
4+
5+
React Native: `:not(<simple-selector>)` now applies. Simple arguments like `:not(:hover)`, `:not(:focus)`, `:not([disabled])`, and `:not([data-state='loading'])` invert the inner predicate, so the rule fires when the inner selector does NOT match. Complex or multi-argument forms (`:not(:hover, :focus)`, descendant combinators inside `:not`) still warn and drop.

‎.changeset/native-attribute-selectors.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ const Toggle = styled.Pressable`
1515
<Toggle aria-pressed={true} /> // yellow background
1616
```
1717

18-
The same CSS works on web and native. This is most useful for `aria-*` selectors since React Native forwards those to platform accessibility services. The presence-only form `&[attr]` matches whenever the prop is defined. The exact-match forms `&[attr=value]`, `&[attr='value']`, and `&[attr="value"]` compare as strings, with boolean coercion so `aria-pressed={true}` and `aria-pressed="true"` both apply the rule. Other operators (`~=`, `^=`, `$=`, `*=`, `|=`) are not supported on native.
18+
The same CSS works on web and native. This is most useful for `aria-*` selectors since React Native forwards those to platform accessibility services. The presence-only form `&[attr]` matches whenever the prop is defined. The exact-match forms `&[attr=value]`, `&[attr='value']`, and `&[attr="value"]` compare as strings, with boolean coercion so `aria-pressed={true}` and `aria-pressed="true"` both apply the rule. The full CSS Selectors 4 operator set (`~=`, `|=`, `^=`, `$=`, `*=`) plus the case-sensitivity flag (`[attr='val' i]`) are also supported.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
`background-size: cover` and `background-size: contain` on React Native no longer crash the app when applied to gradient backgrounds. The native side now receives `auto` (the spec-correct fold for an image with no intrinsic dimensions), so gradients paint across the full element area as expected. `react-native-web` still receives the original keyword and resolves it against the image type natively.
6+
7+
`background-position` two-axis forms like `0 0`, `50% 50%`, or `top left` no longer trigger `react-native-web`'s validator warning. The native side receives the full two-axis value; the standard property name is omitted on web for multi-token forms (which the browser was already discarding silently after the warning).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
`background` shorthand now expands on React Native: a single declaration sets `background-image`, `background-position`, `background-size`, `background-repeat`, `background-attachment`, `background-origin`, `background-clip`, and `background-color` per CSS Backgrounds 3 §2.10. Multi-layer (comma-separated), position/size split by `/`, and color on the final layer all work. Native dev warnings fire for surfaces RN doesn't expose (`background-attachment: fixed`, non-default `background-origin` / `background-clip`); `react-native-web` honors the full shorthand through the browser.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'styled-components': minor
3+
---
4+
5+
`em`, `lh`, and `rlh` font-relative length units now work on React Native. `padding: 1em`, `gap: 0.5lh`, `min(10px, 5em)` and similar resolve at render time against the inherited cascade just like in the browser, so designs that bake their rhythm in font-multiples (typography systems, content blocks, body-text padding) port across to native without rewriting to px.
6+
7+
`text-align: start`, `text-align: end`, and `text-align: match-parent` now resolve correctly under both left-to-right and right-to-left writing directions on React Native. Authors get the same direction-aware behavior they get on the web; the previous fall-back-to-`auto` warning is removed.
8+
9+
Components whose CSS declares `font-size`, `line-height`, or `direction` automatically publish the resolved value to descendants, so a single `<Text style="font-size: 18px">` at the top of a card propagates as the `em` / `lh` anchor for everything inside.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
"styled-components": minor
3+
---
4+
5+
React Native: descendant and child combinator selectors now work across styled components.
6+
7+
```jsx
8+
const Card = styled.View`
9+
padding: 16px;
10+
`;
11+
const Title = styled.Text`
12+
font-size: 14px;
13+
${Card} & {
14+
font-size: 18px;
15+
}
16+
`;
17+
18+
<Card>
19+
<Title>Bigger inside a Card</Title>
20+
</Card>
21+
<Title>Default size when standalone</Title>
22+
```
23+
24+
The descendant form `${Card} &` matches whenever the styled-component reference appears anywhere up the parent chain. The child form `${Card} > &` only matches when the reference is the immediate styled-component parent. Plain wrappers (`View`, `Text`, host components) between the ancestor and the matched component are transparent to the chain; a styled component in between becomes the new immediate parent, so the child combinator stops firing while descendant still matches.
25+
26+
The same selectors also work on web. As a bonus, a long-standing case where `${Component} { … }` rules placed after another declaration silently dropped the component prefix on the web has been fixed; those rules now correctly target descendants.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
`direction: ltr | rtl` now lands on React Native styles. Logical edges (`margin-inline-start` / `padding-inline-end` / etc.) flip sides under `rtl`, so a single declaration steers bidi-aware layout on iOS, Android, and the web.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"styled-components": minor
3+
---
4+
5+
React Native: `field-sizing: content` makes a `TextInput` autosize to its content.
6+
7+
```jsx
8+
const Note = styled.TextInput`
9+
field-sizing: content;
10+
min-height: 44px;
11+
padding: 8px 12px;
12+
border: 1px solid #ddd;
13+
`;
14+
15+
<Note placeholder="Start typing…" />
16+
```
17+
18+
The field grows in height as the user types, no controlled height state, no `onContentSizeChange` wiring. Pass `multiline={false}` explicitly to keep a fixed single-line field (a dev-time message points out that autosize is off in that case).
19+
20+
On `react-native-web` the declaration is handed straight to the browser, which has supported `field-sizing` natively since Chrome 123.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
`font-style: oblique` now maps to `italic` on React Native; an optional `<angle>` after `oblique` (e.g. `oblique 14deg`) is dropped on native with a one-time dev warning, and `react-native-web` passes the declaration through so the browser handles slant-axis variable fonts natively.
6+
7+
`line-height` percentage values and non-px length units (`em`, `rem`) silently drop on React Native (RN accepts only unitless multipliers and px lengths). A one-time dev warning now surfaces both cases with the specific value involved and a concrete migration path.
8+
9+
`letter-spacing` with em / rem / percentage units silently drops on React Native; a one-time dev warning explains and points at the px / unitless equivalents.

0 commit comments

Comments
 (0)