卡片
一个用于在样式化容器中显示内容的 Jetpack Compose 卡片组件。
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
Expo UI Card 与官方 Jetpack Compose Card API 保持一致,并在带样式的表面容器中显示内容,可选支持阴影高度和边框。Card 组件渲染的是 填充卡片,而 ElevatedCard 和 OutlinedCard 分别提供带抬升效果和带边框的变体。

安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础卡片
import { Host, Card, Text } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function BasicCardExample() { return ( <Host matchContents> <Card> <Text modifiers={[paddingAll(16)]}>这是一个具有默认样式的基础卡片。</Text> </Card> </Host> ); }
卡片类型
使用 Card(填充)、ElevatedCard 或 OutlinedCard 来呈现不同样式。
import { Host, Card, ElevatedCard, OutlinedCard, Text, Column } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function CardTypesExample() { return ( <Host matchContents> <Column verticalArrangement={{ spacedBy: 12 }}> <Card> <Text modifiers={[paddingAll(16)]}>填充卡片</Text> </Card> <ElevatedCard> <Text modifiers={[paddingAll(16)]}>抬升卡片</Text> </ElevatedCard> <OutlinedCard> <Text modifiers={[paddingAll(16)]}>描边卡片</Text> </OutlinedCard> </Column> </Host> ); }
自定义阴影高度
使用 elevation 属性(单位为 dp)来控制阴影深度。阴影高度在 ElevatedCard 上最有意义,因为它使用的是阴影高度。填充型 Card 默认使用色调阴影高度,因此变化可能会比较细微。
import { Host, ElevatedCard, Text } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function ElevatedCardExample() { return ( <Host matchContents> <ElevatedCard elevation={8}> <Text modifiers={[paddingAll(16)]}>具有 8dp 阴影高度的卡片</Text> </ElevatedCard> </Host> ); }
自定义边框
Card 和 OutlinedCard 接受 border 属性,用于自定义描边宽度和颜色。
import { Host, OutlinedCard, Text } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function OutlinedCardExample() { return ( <Host matchContents> <OutlinedCard border={{ width: 2, color: '#6200EE' }}> <Text modifiers={[paddingAll(16)]}>带自定义紫色边框的卡片</Text> </OutlinedCard> </Host> ); }
API
import { Card, ElevatedCard, OutlinedCard } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<ComponentType<CardProps>>
A card component that renders a filled card surface for content.
Type: React.Element<ComponentType<ElevatedCardProps>>
An elevated card component that provides a raised surface for content.
Type: React.Element<ComponentType<OutlinedCardProps>>
An outlined card component that provides a bordered surface for content.
Types
Border configuration for cards.
| Property | Type | Description |
|---|---|---|
| color(optional) | ColorValue | Border color. |
| width(optional) | number | Border width in dp. Default: 1 |
Colors for card's core elements.
| Property | Type | Description |
|---|---|---|
| containerColor(optional) | ColorValue | - |
| contentColor(optional) | ColorValue | - |