@react-native-community/blur在一加Android 12设备应用后台/非活跃状态下失效问题求助
@react-native-community/blur在一加Android 12设备应用后台/非活跃状态下失效问题求助
大家好,我在React Native项目(v0.75.3)里用了@react-native-community/blur(v4.4.1),用来在应用进入后台时覆盖整个UI做隐私模糊,现在碰到了一个设备特定的问题,想请教下社区的朋友们有没有类似经验或者解决思路?
我测试下来的情况是:
- 模糊效果在这些设备上正常工作:Android 11 设备、Android 13 设备
- 但在一加Android 12设备上,当应用进入后台或非活跃状态时,这个模糊完全不生效
我做这个的目的是防止别人从最近应用列表里看到App内的敏感内容,这个逻辑在大部分设备上都跑通了,唯独卡在一加Android 12上。
相关依赖版本
- @react-native-community/blur: 4.4.1
- react-native: 0.75.3
我实现的代码逻辑
下面是处理后台状态模糊的组件代码,通过监听AppState的blur/focus事件来控制模糊层的显示:
import React, { useEffect, useState } from 'react'; import { AppState, Platform, StyleSheet } from 'react-native'; import { BlurView } from '@react-native-community/blur'; const BackgroundStateAndroidBlur = () => { const [isBlurred, setIsBlurred] = useState(false); useEffect(() => { if (Platform.OS === 'android') { /** * /!\ * Be aware that this event will be triggered also when a modal is opened * so be careful where you use this component */ const blurEventListener = AppState.addEventListener('blur', () => { setIsBlurred(true); }); const focusEventListener = AppState.addEventListener('focus', () => { setIsBlurred(false); }); return () => { blurEventListener.remove(); focusEventListener.remove(); }; } }, []); return ( isBlurred && ( <BlurView style={styles.absolute} blurType="light" blurAmount={10} reducedTransparencyFallbackColor="white" /> ) ); }; const styles = StyleSheet.create({ absolute: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, }, }); export default BackgroundStateAndroidBlur;
想请教的问题
- 有没有人在一加Android 12设备上遇到过同样的@react-native-community/blur失效问题?
- 有没有已知的解决方案或者临时 workaround?
- 会不会是一加设备的特定系统设置(比如隐私、显示相关)影响了模糊效果的渲染?
非常感谢大家的任何见解和建议!
内容来源于stack exchange
相关产品推荐
相关产品推荐

