表面
用于样式化内容容器的 Jetpack Compose Surface 组件。
Expo UI Surface 与官方 Jetpack Compose Surface API 相匹配,并提供一个容器,应用 Material Design 表面样式,包括颜色、层次和内容颜色。
🌐 Expo UI Surface matches the official Jetpack Compose Surface API and provides a container that applies Material Design surface styling including color, elevation, and content color.
安装
🌐 Installation
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
基本表面
🌐 Basic surface
import { Host, Surface, Text } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function BasicSurfaceExample() { return ( <Host matchContents> <Surface modifiers={[paddingAll(16)]}> <Text>Content on a surface</Text> </Surface> </Host> ); }
有高程的表面
🌐 Surface with elevation
使用 tonalElevation 和 shadowElevation 来控制表面的视觉深度。
🌐 Use tonalElevation and shadowElevation to control the visual depth of the surface.
import { Host, Surface, Column, Text } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function SurfaceElevationExample() { return ( <Host matchContents> <Column modifiers={[paddingAll(16)]}> <Surface tonalElevation={1} shadowElevation={2} modifiers={[paddingAll(16)]}> <Text>Low elevation</Text> </Surface> <Surface tonalElevation={4} shadowElevation={8} modifiers={[paddingAll(16)]}> <Text>High elevation</Text> </Surface> </Column> </Host> ); }
带有自定义颜色的表面
🌐 Surface with custom colors
使用 color 和 contentColor 属性来覆盖默认的 Material 主题颜色。
🌐 Use the color and contentColor props to override the default Material theme colors.
import { Host, Surface, Text } from '@expo/ui/jetpack-compose'; import { paddingAll } from '@expo/ui/jetpack-compose/modifiers'; export default function SurfaceCustomColorsExample() { return ( <Host matchContents> <Surface color="#1E3A5F" contentColor="#FFFFFF" tonalElevation={2} modifiers={[paddingAll(16)]}> <Text color="#FFFFFF">Custom colored surface</Text> </Surface> </Host> ); }
应用接口
🌐 API
import { Surface } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<SurfaceProps>
A Material Design surface container. Surface is responsible for:
- Clipping content to the shape
- Applying background color based on tonal elevation
- Providing content color to its children
ColorValueThe background color of the surface.
Defaults to MaterialTheme.colorScheme.surface.
ColorValueThe color of the content inside the surface.
Defaults to contentColorFor(color).
number • Default: 0The shadow elevation of the surface. Value in dp.