This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 符号 iconExpo 符号

允许访问原生符号的库。

Android
iOS
tvOS
Web
Included in Expo Go
Recommended version:
~57.0.0

重要 这个库当前处于测试版,可能会发生破坏性更改。

expo-symbols 提供跨平台的本地符号库访问。在 iOS 和 tvOS 上,它使用 SF Symbols。在 Android 和网页上,它使用 Material Symbols

安装

🌐 Installation

Terminal
npx expo install expo-symbols

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

🌐 Usage

跨平台符号

🌐 Cross-platform symbols

传递一个带有每个平台符号名称的对象,以在所有平台上渲染符号。在 Apple SF Symbols 应用 中浏览可用的 iOS 符号,在 Google Material Symbols 中浏览 Android/网页符号。

🌐 Pass an object with per-platform symbol names to render symbols on all platforms. Browse available iOS symbols in the Apple SF Symbols app and Android/web symbols at Google Material Symbols.

App.js
import { SymbolView } from 'expo-symbols'; import { StyleSheet, View } from 'react-native'; export default function App() { return ( <View style={styles.container}> <SymbolView name={{ ios: 'info.circle', android: 'info', web: 'info' }} tintColor="#007AFF" size={35} /> <SymbolView name={{ ios: 'pencil.tip.crop.circle.badge.plus', android: 'home_and_garden', web: 'home_and_garden', }} style={styles.symbol} /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, symbol: { width: 35, height: 35, margin: 5, }, });

如果你只传入一个字符串,它会被视为 SF 符号名称,并且仅在 iOS 上渲染。在 Android 和网页上,除非你提供 fallback,否则不会渲染任何内容:

🌐 If you only pass a string, it is treated as an SF Symbol name and renders only on iOS. On Android and web, nothing will be rendered unless you provide a fallback:

{ /* iOS-only: pass an SF Symbol name directly */ } <SymbolView name="airpods.chargingcase" style={styles.symbol} type="hierarchical" />; { /* Use fallback for platforms where the symbol is not defined */ } <SymbolView name={{}} fallback={<Text>?</Text>} />;

重量

🌐 Weights

在 iOS 上,直接传递一个权重字符串。在 Android 上,从 expo-symbols/androidWeights 导入一个权重对象:

🌐 On iOS, pass a weight string directly. On Android, import a weight object from expo-symbols/androidWeights:

import bold from 'expo-symbols/androidWeights/bold'; <SymbolView name={{ ios: 'star.fill', android: 'star', web: 'star' }} weight={{ ios: 'bold', android: bold }} tintColor="gold" size={35} />;

可用的重量导入:boldsemiBoldmediumregularlightextraLightthin

🌐 Available weight imports: bold, semiBold, medium, regular, light, extraLight, thin.

应用接口

🌐 API

import { SymbolView } from 'expo-symbols';

Component

SymbolView

Type: React.Element<SymbolViewProps>

SymbolViewProps

animationSpec

Only for:
iOS

Optional • Type: AnimationSpec

The animation configuration to apply to the symbol.

colors

Only for:
iOS

Optional • Literal type: union

An array of colors to use when the SymbolType is palette.

Acceptable values are: ColorValue | ColorValue[]

fallback

Optional • Type: React.ReactNode

Fallback to render when a symbol for the given platform is not defined.

name

Literal type: union

The name of the symbol. iOS Symbols can be viewed in the Apple SF Symbols app.

Acceptable values are: SFSymbol | { android: AndroidSymbol, ios: SFSymbol, web: AndroidSymbol }

resizeMode

Only for:
iOS

Optional • Type: ContentMode • Default: 'scaleAspectFit'

Determines how the image should be resized to fit its container.

scale

Only for:
iOS

Optional • Type: SymbolScale • Default: 'unspecified'

The scale of the symbol to render.

size

Optional • Type: number • Default: 24

The size of the symbol.

tintColor

Optional • Type: ColorValue

The tint color to apply to the symbol.

type

Only for:
iOS

Optional • Type: SymbolType • Default: 'monochrome'

Determines the symbol variant to use.

weight

Optional • Literal type: union • Default: 'unspecified'

The weight of the symbol to render. On Android and web import from expo-symbols/androidWeights/{weight}.

Acceptable values are: SymbolWeight | { android: AndroidSymbolWeight, ios: SymbolWeight }

Inherited Props

Methods

Symbol.unstable_getMaterialSymbolSourceAsync(symbol, size, color)

Only for:
Android

ParameterType
symbolSee description for available values.
sizenumber
colorstring

Renders a Material Symbol to an image source. Useful for APIs that require an ImageSourcePropType instead of a component, such as tab bar icons.

Types

AnimationEffect

PropertyTypeDescription
direction(optional)'up' | 'down'

The direction of the animation.

typeAnimationType

The type of animation to apply to the symbol.

wholeSymbol(optional)boolean

Whether the entire symbol should animate or just the individual layers.

Default:false

AnimationSpec

The animation configuration to apply to the symbol.

PropertyTypeDescription
effect(optional)AnimationEffect

The effect to apply to the symbol.

repeatCount(optional)number

The number of times the animation should repeat.

repeating(optional)boolean

If the animation should repeat.

speed(optional)number

The duration of the animation in seconds.

variableAnimationSpec(optional)VariableAnimationSpec

An object that specifies how the symbol’s layers should animate.

AnimationType

Literal Type: string

The type of animation to apply to the symbol.

Acceptable values are: 'bounce' | 'pulse' | 'scale'

ContentMode

Literal Type: string

Determines how the image should be resized to fit its container.

Acceptable values are: 'scaleToFill' | 'scaleAspectFit' | 'scaleAspectFill' | 'redraw' | 'center' | 'top' | 'bottom' | 'left' | 'right' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'

SymbolScale

Literal Type: string

The scale of the symbol to render.

Acceptable values are: 'default' | 'unspecified' | 'small' | 'medium' | 'large'

SymbolType

Literal Type: string

Determines the symbol variant to use.

  • 'monochrome' - Creates a color configuration that specifies that the symbol image uses its monochrome variant.

  • 'hierarchical' - Creates a color configuration with a color scheme that originates from one color.

  • 'palette' - Creates a color configuration with a color scheme from a palette of multiple colors.

  • 'multicolor' - Creates a color configuration that specifies that the symbol image uses its multicolor variant, if one exists.

Acceptable values are: 'monochrome' | 'hierarchical' | 'palette' | 'multicolor'

SymbolWeight

Literal Type: string

The weight of the symbol to render.

Acceptable values are: 'unspecified' | 'ultraLight' | 'thin' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'heavy' | 'black'

VariableAnimationSpec

A variable color animation draws attention to a symbol by changing the opacity of the symbol’s layers. You can choose to apply the effect to layers either cumulatively or iteratively. For cumulative animations, each layer’s opacity remains changed until the end of the animation cycle. For iterative animations, each layer’s opacity changes briefly before returning to its original state. These effects are compounding, each value set to true will add an additional effect.

PropertyTypeDescription
cumulative(optional)boolean

This effect enables each successive variable layer, and the layer remains enabled until the end of the animation cycle. This effect cancels the iterative variant.

dimInactiveLayers(optional)boolean

An effect that dims inactive layers of a symbol. This effect draws inactive layers with reduced, but nonzero, opacity.

hideInactiveLayers(optional)boolean

An effect that hides inactive layers of a symbol. This effect hides inactive layers completely, rather than drawing them with reduced, but nonzero, opacity.

iterative(optional)boolean

An effect that momentarily enables each layer of a symbol in sequence.

nonReversing(optional)boolean

An effect that doesn’t reverse each time it repeats.

reversing(optional)boolean

An effect that reverses each time it repeats.