This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
图片 用于显示 SF 符号的 SwiftUI 图片组件。
Recommended version:
~58.0.15
信息 有关跨平台使用,请参阅通用 Icon —— 它会根据平台呈现相应的原生组件。
Expo UI 图片使用 SwiftUI Image API 显示 SF 符号。SF 符号是苹果提供的一个可配置符号库。
🌐 Expo UI Image displays SF Symbols using the SwiftUI Image API . SF Symbols are a library of configurable symbols provided by Apple.
安装
🌐 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
基本 SF 符号
🌐 Basic SF Symbol
import { Host , Image } from '@expo/ui/swift-ui' ;
export default function BasicImageExample ( ) {
return (
< Host style = { { flex: 1 } } >
< Image systemName = " star.fill" />
</ Host >
) ;
}
自定义 SF 符号
🌐 Custom SF Symbol
使用 assetName 属性来显示作为符号集导入到应用资源目录中的自定义 SF 符号。
🌐 Use the assetName prop to display a custom SF Symbol imported into the app asset catalog as a symbol set.
import { Host , Image } from '@expo/ui/swift-ui' ;
export default function CustomImageExample ( ) {
return (
< Host matchContents >
< Image assetName = " acme.mark" />
</ Host >
) ;
}
按尺寸和颜色
🌐 With size and color
ImageSizeColorExample.tsx import { Host , HStack , Image } from '@expo/ui/swift-ui' ;
export default function ImageSizeColorExample ( ) {
return (
< Host matchContents >
< HStack spacing = { 16 } >
< Image systemName = " heart.fill" size = { 24 } color = " red" />
< Image systemName = " star.fill" size = { 32 } color = " orange" />
< Image systemName = " bell.fill" size = { 40 } color = " blue" />
</ HStack >
</ Host >
) ;
}
带有变量值
🌐 With variable value
某些 SF 符号会根据变量值改变其外观。使用 variableValue 属性,取值范围在 0.0 到 1.0 之间,以控制渲染的符号。需要 iOS 16.0 及以上版本和 SF Symbols 4.0 及以上版本。
🌐 Some SF Symbols alter their appearance based on a variable value. Use the variableValue prop with a value between 0.0 and 1.0 to control the rendered symbol. Requires iOS 16.0+ and SF Symbols 4.0+.
import { Host , HStack , Image } from '@expo/ui/swift-ui' ;
export default function ImageVariableExample ( ) {
return (
< Host style = { { flex: 1 } } >
< HStack spacing = { 16 } >
< Image
systemName = " chart.bar.fill"
size = { 32 }
variableValue = { 0.3 }
/>
< Image
systemName = " chart.bar.fill"
size = { 32 }
variableValue = { 0.6 }
/>
< Image
systemName = " chart.bar.fill"
size = { 32 }
variableValue = { 1.0 }
/>
</ HStack >
</ Host >
) ;
}
带符号效果
🌐 With symbol effect
通过从 @expo/ui/swift-ui/modifiers 传递 symbolEffect 修饰符,为 SF 符号应用动画效果。默认情况下,此效果会连续运行。你也可以传递 value 来触发离散事件,每次更改时触发一次,或者传递 isActive 作为布尔切换,在 true 为真时运行此效果。需要 iOS 17.0 及更高版本。
🌐 Apply an SF Symbol effect to animate the symbol by passing a symbolEffect modifier from @expo/ui/swift-ui/modifiers. This effect runs continuously by default. You can also pass value for a discrete trigger that fires once per change, or isActive for a boolean toggle that runs the effect while true. Requires iOS 17.0 and later.
ImageSymbolEffectExample.tsx import { Host , Image } from '@expo/ui/swift-ui' ;
import { symbolEffect } from '@expo/ui/swift-ui/modifiers' ;
export default function ImageSymbolEffectExample ( ) {
return (
< Host style = { { flex: 1 } } >
< Image
systemName = " wifi"
size = { 48 }
color = " blue"
modifiers = { [
symbolEffect ( {
effect: 'variableColor' ,
fillStyle: 'iterative' ,
playbackStyle: 'reversing' ,
} ) ,
] }
/>
</ Host >
) ;
}
以下示例使用 value 在每次按下按钮时播放 bounce。从 worklet(或通过 scheduleOnUI )写入 state.value 以触发效果。
🌐 The following example uses value to play bounce on each button press. Write to state.value from a worklet (or via scheduleOnUI ) to trigger the effect.
ImageSymbolEffectValueExample.tsx import {
Button ,
Host ,
Image ,
useNativeState,
VStack ,
} from '@expo/ui/swift-ui' ;
import { symbolEffect } from '@expo/ui/swift-ui/modifiers' ;
import { scheduleOnUI } from 'react-native-worklets' ;
export default function ImageSymbolEffectValueExample ( ) {
const trigger = useNativeState ( 0 ) ;
return (
< Host matchContents >
< VStack spacing = { 16 } >
< Image
systemName = " bell.fill"
size = { 48 }
color = " orange"
modifiers = { [
symbolEffect (
{ effect: 'bounce' , direction: 'up' } ,
{ value: trigger }
) ,
] }
/>
< Button
label = " Bounce"
onPress = { ( ) =>
scheduleOnUI ( ( ) => {
'worklet' ;
trigger. value = trigger. value + 1 ;
} )
}
/>
</ VStack >
</ Host >
) ;
}
以下示例使用 isActive 来切换连续的 breathe 动画。
🌐 The following example uses isActive to toggle a continuous breathe animation.
ImageSymbolEffectIsActiveExample.tsx import {
Host ,
Image ,
SyncToggle ,
useNativeState,
VStack ,
} from '@expo/ui/swift-ui' ;
import { symbolEffect } from '@expo/ui/swift-ui/modifiers' ;
export default function ImageSymbolEffectIsActiveExample ( ) {
const isActive = useNativeState ( true ) ;
return (
< Host style = { { flex: 1 } } >
< VStack spacing = { 16 } >
< Image
systemName = " cloud.fill"
size = { 48 }
color = " cyan"
modifiers = { [
symbolEffect ( { effect: 'breathe' } , { isActive } ) ,
] }
/>
< SyncToggle label = " Breathe" isOn = { isActive} />
</ VStack >
</ Host >
) ;
}
应用接口
🌐 API
import { Image } from '@expo/ui/swift-ui' ;
No API data file found, sorry!