Repository navigation
feat: Card MD3 Expressive improvements #5116
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
Open
pawelkata
wants to merge
52
commits into
callstack:main
Choose a base branch
from
pawelkata:expressive-card
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,904
−1,049
Open
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
fd2950c
refactor(card): make layout helpers parent-independent
0e406b0
feat(card)!: introduce slot-first filled card
2ccea63
feat(card): add Material variant token contract
7eb601f
feat(card): modernize responsive cover media
3ef1c01
feat(card)!: expose one actionable target
4a135e5
feat(card): add actionable state feedback
aaaf1ce
feat(card): complete state and motion behavior
941dbea
fix(card): fix worklet related complaints
daaec2d
feat(card): add expressive example gallery
f6cca6b
docs(card): publish v6 contract and migration
f5bfef1
fix(docs): correct card migration examples
6cc782b
refactor(card): drop derived testID's + fix tests
e0ae8ea
fix(card): disabled card color
075ef2f
docs(card): add card.actions migration info
8fc70f7
refactor(card): adapt to main and use the shared focus ring
Stoneski93 681070b
fix(card): add aspectRatio prop to Card.Cover
Stoneski93 289db5b
chore(example): remove the Card render count example
Stoneski93 5e8f98d
fix(card): drive state feedback with React state
Stoneski93 0e0d921
fix(card): draw the pressed state layer once
Stoneski93 75e27b6
fix(card): draw the state layer over the slot content
Stoneski93 238a6fe
fix(card): dim the content of a disabled Card
Stoneski93 f2bd9c2
feat(card): restore the borderColor prop for outlined Cards
Stoneski93 a595769
docs(card): merge the Card migration notes into one section
Stoneski93 38527e8
docs(card): render the title once in the navigation theming example
Stoneski93 ac76d73
test(card): assert Card visuals directly instead of whole-tree snapshots
Stoneski93 0cded7e
fix(card): let aspectRatio size a Card.Cover from a static source
Stoneski93 cde12fb
docs(example): rebuild the Card example around a variant switcher
Stoneski93 1084cb2
docs: document Surface from its own component again
Stoneski93 d4c2f45
fix(docs): merge prop types only across union branches
Stoneski93 12f4453
fix(card): annotate the resolveCardVisuals return type
Stoneski93 7790ad2
docs(card): drop removed Button props from the Card examples
Stoneski93 93f2398
fix(card): skip the actions warning when the actions slot is empty
Stoneski93 7b26329
docs(example): show every Card state in each variant
Stoneski93 5be064b
fix(card): pad Card.Actions 16dp at the sides
Stoneski93 810a30f
docs(card): note the single-pointer alternative to dragging
Stoneski93 05dac82
fix(card): keep Card.Title visible in a row-laid-out Card
Stoneski93 3ae511e
fix(card): accept a union variant on a Card without a header
Stoneski93 c726750
fix(card): drop theme.animation.scale, removed on main
Stoneski93 4f037c5
fix(card): clear state feedback when a Card stops being actionable
Stoneski93 da245d6
fix(card): ignore focus that bubbles up from a descendant
Stoneski93 44ee5b6
fix(card): restore main's 194dp default cover height
Stoneski93 3eeb9cf
fix(card): show the focused outline color over a custom borderColor
Stoneski93 4520268
docs(card): note that Card.Cover style now applies to the image
Stoneski93 b32ff75
test(card): query the nested Button by role in the focus ring test
Stoneski93 1627c0d
docs(card): explain the aria-disabled pass-through and the actions check
Stoneski93 e81af86
refactor(card): move resolveCardVisuals to utils.ts
Stoneski93 2e2ce5f
refactor(card): name the layout helpers' spacing in tokens
Stoneski93 dacff8e
docs(card): record the November recheck of the Card tokens
Stoneski93 3bf751a
perf(card): drop the Card layers that draw nothing
Stoneski93 2e7a5bf
fix(card): space Card regions as on main
Stoneski93 2156bbd
fix(card): round all four corners of Card.Cover again
Stoneski93 03e81bc
docs(example): stop spreading Card title props onto IconButton
Stoneski93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,14 +31,15 @@ So you can use Reanimated's `useSharedValue` and `useAnimatedStyle` to animate t | |
|
|
||
| ```tsx | ||
| import { useAnimatedStyle, useSharedValue } from 'react-native-reanimated'; | ||
| import { Card, Text } from 'react-native-paper'; | ||
|
|
||
| const MyComponent = () => { | ||
| const opacity = useSharedValue(1); | ||
| const animatedStyle = useAnimatedStyle(() => ({ | ||
| opacity: opacity.value, | ||
| })); | ||
|
|
||
| return <Card style={animatedStyle}>Button</Card>; | ||
| return <Card content={<Text>Animated Card</Text>} style={animatedStyle} />; | ||
| }; | ||
| ``` | ||
|
|
||
|
|
@@ -75,7 +76,7 @@ To follow the same preference in your own components, use the `useReduceMotion() | |
| The `elevation` prop no longer accepts a React Native `Animated.Value` in the following components: | ||
|
|
||
| - `Banner` | ||
| - `Card` | ||
| - `Card` (`variant="elevated"` only) | ||
| - `Searchbar` | ||
| - `Snackbar` | ||
| - `Surface` | ||
|
|
@@ -558,6 +559,176 @@ e.g.: | |
| + </View> | ||
| ``` | ||
|
|
||
| ### Card | ||
|
|
||
| Paper 6 replaces the Card's `mode` and arbitrary-children interfaces with Material 3 variants and explicit slots. These interfaces were removed; they are not deprecated APIs. Migrate each Card directly to the new contract. | ||
|
|
||
| #### Variants and default | ||
|
|
||
| Replace `mode` with `variant`: | ||
|
|
||
| | Paper 5 | Paper 6 | | ||
| | ------------------ | -------------------- | | ||
| | `mode="contained"` | `variant="filled"` | | ||
| | `mode="elevated"` | `variant="elevated"` | | ||
| | `mode="outlined"` | `variant="outlined"` | | ||
|
|
||
| The default also changed. A Paper 5 Card without `mode` was elevated; a Paper 6 Card without `variant` is filled and has no resting shadow. Add `variant="elevated"` if you need to preserve the old default emphasis. The `elevation` prop is accepted only with `variant="elevated"`. | ||
|
|
||
| #### Replace nested composition with slots | ||
|
|
||
| Arbitrary Card children were removed. Paper 6 renders the explicit regions in the deterministic order `media`, header, `content`, and `actions`, regardless of the order in which props are written. Arrays, fragments, conditional values, and custom wrappers can be passed inside a slot without changing region placement. | ||
|
|
||
| For the common header form, move `Card.Title` values to `title`, `subtitle`, `leading`, and `trailing`. Move the remaining regions to their corresponding slots: | ||
|
|
||
| ```tsx | ||
| // Before (v5) | ||
| <Card mode="contained" onPress={openDetails}> | ||
| <Card.Cover source={{ uri: coverUri }} /> | ||
| <Card.Title title="Weekend trip" subtitle="2 days" /> | ||
| <Card.Content> | ||
| <Text variant="bodyMedium">View the itinerary.</Text> | ||
| </Card.Content> | ||
| </Card> | ||
|
|
||
| // After (v6) | ||
| <Card | ||
| accessibilityLabel="Open weekend trip details" | ||
| onPress={openDetails} | ||
| media={<Card.Cover source={{ uri: coverUri }} />} | ||
| title="Weekend trip" | ||
| subtitle="2 days" | ||
| content={ | ||
| <Card.Content> | ||
| <Text variant="bodyMedium">View the itinerary.</Text> | ||
| </Card.Content> | ||
| } | ||
| /> | ||
| ``` | ||
|
|
||
| Use `header` when the complete header is custom. It is mutually exclusive with `title`, `subtitle`, `leading`, and `trailing`: | ||
|
|
||
| ```tsx | ||
| <Card | ||
| variant="outlined" | ||
| header={<TripHeader trip={trip} />} | ||
| content={ | ||
| <Card.Content> | ||
| <Text>{trip.summary}</Text> | ||
| </Card.Content> | ||
| } | ||
| /> | ||
| ``` | ||
|
|
||
| `Card.Content`, `Card.Cover`, `Card.Title`, and `Card.Actions` remain available as layout helpers inside the new slots. They are not arbitrary Card children. | ||
|
|
||
| #### `Card.Content` padding | ||
|
|
||
| `Card.Content` no longer changes its padding based on its neighbors. In Paper 5 it added top padding only when it came first and bottom padding only when it came last. Now each region pads its own top and sides with `16dp`, and the Card adds `16dp` below its last region. An action row instead ends `8dp` below its buttons. `Card.Title` no longer has a minimum height: it sizes from its content. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same Paper 5 mention here |
||
|
|
||
| Used outside a Card, `Card.Content` has no bottom padding. Add it with the `style` prop: | ||
|
|
||
| ```tsx | ||
| <Card.Content style={{ paddingBottom: 16 }}> | ||
| <Text>Shown outside a Card</Text> | ||
| </Card.Content> | ||
| ``` | ||
|
|
||
| #### Horizontal layout | ||
|
|
||
| To place the regions in a row, set `flexDirection` in `contentStyle`, which styles the wrapper around the slots. Also set `paddingBottom: 0`, so the media in the row reaches the Card's bottom edge instead of sitting above the `16dp` the Card adds below its last region: | ||
|
|
||
| ```tsx | ||
| <Card | ||
| contentStyle={{ flexDirection: 'row', paddingBottom: 0 }} | ||
| media={<Card.Cover source={cover} style={{ width: 72, height: 72 }} />} | ||
| title="Card title" | ||
| /> | ||
| ``` | ||
|
|
||
| #### Outline color | ||
|
|
||
| The `borderColor` in `style` no longer changes the outline color of an outlined Card. Use the `borderColor` prop instead. It is accepted only with `variant="outlined"`: | ||
|
|
||
| ```diff | ||
| <Card | ||
| - mode="outlined" | ||
| - style={{ borderColor: 'red' }} | ||
| + variant="outlined" | ||
| + borderColor="red" | ||
| title="Card title" | ||
| /> | ||
| ``` | ||
|
|
||
| #### `Card.Cover` | ||
|
|
||
| Use the `aspectRatio` prop to size a cover responsively. It replaces the default height of `194`: | ||
|
|
||
| ```tsx | ||
| <Card media={<Card.Cover source={cover} aspectRatio={16 / 9} />} /> | ||
| ``` | ||
|
|
||
| `Card.Cover` rounds all four corners with the theme's `corner.medium`, as in Paper 5, and the Card also clips its media to the Card's shape. Pass `borderRadius` in the cover's `style` to change the rounding. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
|
||
| `Card.Cover` no longer wraps its image in a `View`. Its `style` is now typed as `ImageStyle` and applies to the `Image` itself instead of a wrapper `View`. To style the area around the cover, wrap the cover in your own `View`: | ||
|
|
||
| ```diff | ||
| - <Card.Cover source={cover} style={{ padding: 8 }} /> | ||
| + <View style={{ padding: 8 }}> | ||
| + <Card.Cover source={cover} /> | ||
| + </View> | ||
| ``` | ||
|
|
||
| #### `Card.Actions` no longer styles its buttons | ||
|
|
||
| `Card.Actions` no longer assigns `mode="outlined"` to its first button, `mode="contained"` (now `mode="filled"`) to the rest, or `compact` to any of them. It only lays its children out in a row; set each `Button`'s `mode` explicitly to keep the old look. `compact` was removed from `Button`; see [`Button`](#button) for its `size` replacement: | ||
|
|
||
| ```tsx | ||
| // Before (v5) — Card.Actions styled the buttons automatically | ||
| <Card.Actions> | ||
| <Button onPress={discard}>Discard</Button> | ||
| <Button onPress={save}>Save</Button> | ||
| </Card.Actions> | ||
|
|
||
| // After (v6) — set mode explicitly | ||
| <Card.Actions> | ||
| <Button mode="outlined" onPress={discard}>Discard</Button> | ||
| <Button mode="filled" onPress={save}>Save</Button> | ||
| </Card.Actions> | ||
| ``` | ||
|
|
||
| `Card.Actions` also has **16dp** of padding at the start and end, the Material Design 3 Card padding, instead of 8dp, and 8dp above and below. To keep the 5.x spacing, pass `style={{ paddingHorizontal: 8, paddingTop: 0 }}`. | ||
|
|
||
| #### Choose one interaction model | ||
|
|
||
| Give the Card an interaction handler when the whole Card represents one action. It becomes one accessibility target with button semantics by default, so do not place independent controls in its `actions` slot. | ||
|
|
||
| When buttons or other controls perform independent actions, keep the Card itself neutral and put those controls in `actions`: | ||
|
|
||
| ```tsx | ||
| <Card | ||
| variant="elevated" | ||
| title="Draft itinerary" | ||
| content={ | ||
| <Card.Content> | ||
| <Text>Review before saving.</Text> | ||
| </Card.Content> | ||
| } | ||
| actions={ | ||
| <Card.Actions> | ||
| <Button onPress={discard}>Discard</Button> | ||
| <Button mode="filled" onPress={save}> | ||
| Save | ||
| </Button> | ||
| </Card.Actions> | ||
| } | ||
| /> | ||
| ``` | ||
|
|
||
| Paper 6 warns in development if whole-Card interaction handlers and a populated `actions` slot are combined. A neutral Card remains a grouping container unless you provide accessibility semantics explicitly. The `dragged` prop controls the Material dragged presentation only; drag gestures and lifecycle remain application responsibilities. | ||
|
|
||
| Card refs and test IDs now target documented nodes: `ref` targets the outer shell, `touchableRef` targets the actionable interaction node, and `testID` targets the interaction node for actionable Cards or the slot-content node for neutral Cards. | ||
|
|
||
| ### Surface | ||
|
|
||
| - The `elevation` prop no longer accepts a React Native `Animated.Value`. Any `elevation` changes are animated automatically. | ||
|
|
@@ -1330,125 +1501,6 @@ These need no code change, but the rendering differs: | |
| `elevated` and `outlined`, and **12dp** for `text` (**16dp** with an icon). | ||
| Existing buttons change width. | ||
|
|
||
| ### Card | ||
|
|
||
| #### `Card` layout | ||
|
|
||
| `Card` and its related components have been reworked. Instead of injecting padding to its children, the `Card` component now adds a padding (`16dp`) around its content as well as a gap (`16dp`) between its children. | ||
|
|
||
| For the related components: | ||
|
|
||
| - `Card.Cover` and `Card.Actions` now apply negative margins to extend into the Card's edges: | ||
| - `Card.Cover` applies top, left and right margins for vertical cards and left, top, and bottom margins for horizontal cards. | ||
| - `Card.Actions` applies bottom, left, and right margins for vertical cards and left, bottom, and right margins for horizontal cards. | ||
| - `Card.Title` and `Card.Content` no longer apply padding around them. | ||
|
|
||
| This means, in a typical card layout, the Card will automatically apply the necessary spacing between these sections: | ||
|
|
||
| ```tsx | ||
| <Card> | ||
| <Card.Cover source={cover} /> | ||
| <Card.Title title="Card title" /> | ||
| <Card.Content> | ||
| <Text>Card content</Text> | ||
| </Card.Content> | ||
| <Card.Actions> | ||
| <Button mode="filled">Action</Button> | ||
| <Button mode="outlined">Another Action</Button> | ||
| </Card.Actions> | ||
| </Card> | ||
| ``` | ||
|
|
||
| So your existing layouts with the following structure will continue to work as before: | ||
|
|
||
| - `Card` without `Card.Cover` or `Card.Actions`. | ||
| - `Card` with `Card.Cover` at the top and/or `Card.Actions` at the bottom. | ||
|
|
||
| If you have `Card.Cover` or `Card.Actions` in positions other than the top and bottom respectively, you will need to adjust their margins. For example, for a `Card.Cover` in the middle of the Card, you would need to set its top and bottom margins to zero: | ||
|
|
||
| ```tsx | ||
| <Card> | ||
| <Card.Title title="Card title" /> | ||
| <Card.Cover source={cover} style={{ marginTop: 0, marginBottom: 0 }} /> | ||
| <Card.Content> | ||
| <Text>Card content</Text> | ||
| </Card.Content> | ||
| </Card> | ||
| ``` | ||
|
|
||
| We have also added a `direction` prop to the `Card` component, which lets you arrange its items horizontally instead of the default vertical layout. So if you have custom `flexDirection` styles on the Card, you should replace them with the `direction` prop. | ||
|
|
||
| ```tsx | ||
| // Before (v5) | ||
| <Card style={{ flexDirection: 'row' }}> | ||
| <Card.Cover source={cover} style={{ width: 72, height: 72 }} /> | ||
| <Card.Title title="Card title" /> | ||
| <Card.Content> | ||
| <Text>Card content</Text> | ||
| </Card.Content> | ||
| <Card.Actions> | ||
| <Button mode="contained">Action</Button> | ||
| <Button mode="outlined">Another Action</Button> | ||
| </Card.Actions> | ||
| </Card> | ||
|
|
||
| // After (v6) | ||
| <Card direction="horizontal"> | ||
| <Card.Cover source={cover} style={{ width: 72, height: 72 }} /> | ||
| <Card.Title title="Card title" /> | ||
| <Card.Content> | ||
| <Text>Card content</Text> | ||
| </Card.Content> | ||
| <Card.Actions> | ||
| <Button mode="filled">Action</Button> | ||
| <Button mode="outlined">Another Action</Button> | ||
| </Card.Actions> | ||
| </Card> | ||
| ``` | ||
|
|
||
| #### Outline color | ||
|
|
||
| The `borderColor` in `style` no longer changes the outline color in `outlined` mode. Use the `borderColor` prop instead: | ||
|
|
||
| ```diff | ||
| <Card | ||
| mode="outlined" | ||
| - style={{ borderColor: 'red' }} | ||
| + borderColor="red" | ||
| > | ||
| <Card.Content>...</Card.Content> | ||
| </Card> | ||
| ``` | ||
|
|
||
| #### `Card.Cover` | ||
|
|
||
| The `style` prop of `Card.Cover` is now typed as a `View` style. Image style properties such as `resizeMode` or `tintColor` were never applied, so pass them as `Image` props instead: | ||
|
|
||
| ```diff | ||
| - <Card.Cover source={cover} style={{ resizeMode: 'contain' }} /> | ||
| + <Card.Cover source={cover} resizeMode="contain" /> | ||
| ``` | ||
|
|
||
| `Card.Cover` no longer applies the border radius from `style` to the image directly. The image is clipped by the container, so any border radius passed in `style` still applies. | ||
|
|
||
| #### `Card.Actions` | ||
|
|
||
| `Card.Actions` no longer injects `mode` on the buttons. To keep the previous behavior, you need to set `mode="outlined"` on the first button and `mode="filled"` (formerly `contained`) on the rest: | ||
|
|
||
| ```tsx | ||
| // Before (v5) | ||
| <Card.Actions> | ||
| <Button>Cancel</Button> | ||
| <Button>Ok</Button> | ||
| </Card.Actions> | ||
|
|
||
| // After (v6) | ||
| <Card.Actions> | ||
| <Button mode="outlined">Cancel</Button> | ||
| <Button mode="filled">Ok</Button> | ||
| </Card.Actions> | ||
| ``` | ||
|
|
||
| ### List | ||
|
|
||
| #### `List.Accordion` | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's redundant to mention Paper 5 behavior in a migration guide. It should state the current behavior and only mention before vs after in direct examples. Please remove
Paper 5 Card without 'mode' was elevatedsentence here.