This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
Expo GlassEffect
使用 iOS 原生 UIVisualEffectView 呈现液态玻璃效果的 React 组件。
重要
GlassView仅适用于 iOS 26 及以上版本。在不支持的平台上,它会回退为普通的View。
使用 UIVisualEffectView 渲染原生 iOS 液态玻璃效果的 React 组件。支持可自定义的玻璃样式和色调颜色。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
GlassView
GlassView 组件会渲染原生 iOS 玻璃效果。它支持不同的玻璃效果样式,并且可以通过色调颜色进行自定义,以满足各种审美需求。
GlassContainer
GlassContainer 组件允许你将多个玻璃视图组合成一个整体效果。
玻璃效果样式动画
glassEffectStyle 属性接受一个包含 animate 和 animationDuration 属性的配置对象,用于在不同玻璃样式之间进行原生动画过渡。这是无需修改 opacity 就能淡入/淡出玻璃效果的推荐方式。
透明度动画解决方案
Apple 不建议在 GlassView 或其父视图上使用小于 1 的 opacity 值,具体说明请参阅设置正确的 alpha 值。当透明度非常低时,玻璃效果不会渲染。若仍要为透明度添加动画,可使用 Reanimated 为包装视图的透明度添加动画,同时在所需样式与 'none' 之间切换 glassEffectStyle。
isLiquidGlassAvailable
isLiquidGlassAvailable 函数可用于检查编译后的应用中是否可用 Liquid Glass 效果。
它会验证系统和编译器版本,以及 Info.plist 设置。
import { Text } from 'react-native'; import { isLiquidGlassAvailable } from 'expo-glass-effect'; export default function CheckLiquidGlass() { return ( <Text> {isLiquidGlassAvailable() ? 'Liquid Glass 效果可用' : 'Liquid Glass 效果不可用'} </Text> ); }
isGlassEffectAPIAvailable
isGlassEffectAPIAvailable 函数用于检查设备在运行时是否可用 Liquid Glass API。
警告 添加此 API 的原因是某些 iOS 26 测试版中没有提供 Liquid Glass API,这可能导致崩溃。在你的应用中使用
GlassView之前,应先进行检查以确保兼容性。更多信息请参阅 GitHub issue #40911。
import { Text } from 'react-native'; import { isGlassEffectAPIAvailable } from 'expo-glass-effect'; export default function CheckGlassEffectAPI() { return ( <Text> {isGlassEffectAPIAvailable() ? 'Glass Effect API 可用' : 'Glass Effect API 不可用'} </Text> ); }
API
import { GlassView, GlassContainer, isLiquidGlassAvailable, isGlassEffectAPIAvailable, } from 'expo-glass-effect';
Components
Type: React.Element<GlassContainerProps>
Type: React.Element<GlassViewProps>
GlassColorScheme • Default: 'auto'The color scheme for the glass effect appearance. Use this to override the system appearance when your app has its own theme toggle.
union • Default: 'regular'Glass effect style to apply to the view. Can be a simple string ('clear', 'regular', 'none') or a config object for controlling animation behavior.
Acceptable values are: GlassStyle | GlassEffectStyleConfig
boolean • Default: falseWhether the glass effect should be interactive.
Ref<View>Methods
Checks whether the Liquid Glass API is available at runtime on the device.
This method was added because some iOS 26 beta versions do not have this API available, which can
lead to crashes. You should check this before using GlassView and GlassContainer in your app to ensure compatibility.
booleanIndicates whether the app is using the Liquid Glass design. The value will be true when the
Liquid Glass components are available in the app.
This only checks for component availability. The value may also be true if the user has enabled
accessibility settings that limit the Liquid Glass effect.
To check if the user has disabled the Liquid Glass effect via accessibility settings, use
AccessibilityInfo.isReduceTransparencyEnabled().
boolean