This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo GlassEffect
使用 iOS 原生 UIVisualEffectView 渲染液态玻璃效果的 React 组件。
重要
GlassView仅在 iOS 26 及更高版本中可用。在不受支持的平台上,它将回退为常规View。
使用 UIVisualEffectView 渲染原生 iOS 液态玻璃效果的 React 组件。支持自定义玻璃样式和色调颜色。
已知问题
- 将
GlassView或其任意父视图的opacity设为0会导致玻璃效果完全无法渲染。若要淡入或淡出玻璃效果,请使用glassEffectStyle中内置的animate和animationDuration属性,而不是更改opacity。如果仍想使用opacity,请参阅透明度动画变通方案示例。更多详情请参阅 Apple 的文档和 GitHub issue #41024。
安装
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 的情况下淡入或淡出玻璃效果的推荐方式。
透明度动画变通方案
由于将 GlassView 或其父视图的 opacity 设为 0 会导致玻璃效果完全无法渲染,因此你可以使用 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 effect is available' : 'Liquid Glass effect is not available'} </Text> ); }
isGlassEffectAPIAvailable
isGlassEffectAPIAvailable 函数用于检查设备在运行时是否提供 Liquid Glass API。
警告 添加此 API 是因为某些 iOS 26 beta 版本不提供 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 is available' : 'Glass Effect API is not available'} </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