This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
形状 用于绘制几何形状的 Jetpack Compose 形状组件。
Recommended version:
~58.0.15
Expo UI Shape 与官方 Jetpack Compose Shapes API 相匹配,并提供了一组用于绘制几何形状的子组件,例如星形、圆形、矩形、胶囊形和多边形。
🌐 Expo UI Shape matches the official Jetpack Compose Shapes API and provides a set of sub-components for drawing geometric shapes such as stars, circles, rectangles, pills, and polygons.
安装
🌐 Installation
- npx expo install @expo/ui
- yarn expo install @expo/ui
- pnpm expo install @expo/ui
- bun expo install @expo/ui
If you are installing this in an existing React Native app , make sure to install expo in your project.
用法
🌐 Usage
基本形状
🌐 Basic shapes
使用 Shape 子组件渲染常见形状。
🌐 Render common shapes using the Shape sub-components.
import { Host , Shape , Row } from '@expo/ui/jetpack-compose' ;
import { size } from '@expo/ui/jetpack-compose/modifiers' ;
export default function BasicShapesExample ( ) {
return (
< Host
matchContents = { { vertical: true } }
style = { { width: '100%' } } >
< Row
horizontalArrangement = { { spacedBy: 16 } }
verticalAlignment = " center" >
< Shape.Star
radius = { 1 }
innerRadius = { 0.5 }
color = " #FFD700"
modifiers = { [ size ( 80 , 80 ) ] }
/>
< Shape.Circle
radius = { 1 }
color = " #4285F4"
modifiers = { [ size ( 80 , 80 ) ] }
/>
< Shape.Rectangle
color = " #34A853"
modifiers = { [ size ( 80 , 80 ) ] }
/>
< Shape.Pill color = " #EA4335" modifiers = { [ size ( 100 , 50 ) ] } />
</ Row >
</ Host >
) ;
}
圆角形状
🌐 Shapes with rounded corners
使用 cornerRounding 和 smoothing 来自定义形状的外观。
🌐 Use cornerRounding and smoothing to customize the appearance of shapes.
import { Host , Shape , Row } from '@expo/ui/jetpack-compose' ;
import { size } from '@expo/ui/jetpack-compose/modifiers' ;
export default function RoundedShapesExample ( ) {
return (
< Host
matchContents = { { vertical: true } }
style = { { width: '100%' } } >
< Row
horizontalArrangement = { { spacedBy: 16 } }
verticalAlignment = " center" >
< Shape.Rectangle
cornerRounding = { 0.2 }
smoothing = { 0.5 }
color = " #9C27B0"
modifiers = { [ size ( 100 , 80 ) ] }
/>
< Shape.RoundedCorner
cornerRadii = { {
topStart: 20 ,
topEnd: 20 ,
bottomStart: 0 ,
bottomEnd: 0 ,
} }
color = " #FF5722"
modifiers = { [ size ( 100 , 80 ) ] }
/>
</ Row >
</ Host >
) ;
}
多边形和星形变体
🌐 Polygon and star variants
使用 verticesCount 和 innerRadius 来控制形状几何。
🌐 Use verticesCount and innerRadius to control the shape geometry.
import { Host , Shape , Row } from '@expo/ui/jetpack-compose' ;
import { size } from '@expo/ui/jetpack-compose/modifiers' ;
export default function PolygonShapesExample ( ) {
return (
< Host
matchContents = { { vertical: true } }
style = { { width: '100%' } } >
< Row
horizontalArrangement = { { spacedBy: 16 } }
verticalAlignment = " center" >
< Shape.Polygon
verticesCount = { 6 }
cornerRounding = { 0.05 }
color = " #00BCD4"
modifiers = { [ size ( 80 , 80 ) ] }
/>
< Shape.Star
verticesCount = { 8 }
radius = { 1 }
innerRadius = { 0.4 }
cornerRounding = { 0.025 }
color = " #FF9800"
modifiers = { [ size ( 80 , 80 ) ] }
/>
< Shape.PillStar
verticesCount = { 6 }
innerRadius = { 0.5 }
color = " #E91E63"
modifiers = { [ size ( 80 , 80 ) ] }
/>
</ Row >
</ Host >
) ;
}
应用接口
🌐 API
import { Shape } from '@expo/ui/jetpack-compose' ;
No API data file found, sorry!