react-native - SafeAreaView 放在背景上后不占用整个屏幕
问题描述
我正在使用 RN 0.59。每次我将应用程序放在后台然后立即重新打开它时,SafeAreaView 不会占用整个屏幕。
但是,如果我将应用程序放在后台并在一段时间后(大约 3 秒)重新打开它,它工作正常。
这是我在 SafeAreaView 上的片段
...
const SafeAreaViewUI = ({children}) => {
return (
<SafeAreaView style={styles.container}>
<View style={styles.content}>
{ children }
</View>
</SafeAreaView>
);
};
...
export default SafeAreaViewUI;
对于我的造型
container: {
flex: 1,
backgroundColor: Platform.OS === 'android' ? blurple : null,
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,
},
content: {
flexGrow: 1,
color: text,
backgroundColor: white,
}
对此有任何见解吗?
解决方案
这对我有用。
const SafeAreaViewUI = ({children}) => {
const [ height, setHeight ] = useState(0)
return (
<SafeAreaView
onLayout={() => {
if (Platform.OS === 'android') {
setHeight(StatusBar.currentHeight || 0);
}
}}
style={[styles.container, { paddingTop: height }]}>
<View style={styles.content}>
{ children }
</View>
</SafeAreaView>
);
如果还有其他可能的答案。请张贴在这里。谢谢!
推荐阅读
- plsql - 使用插入调用另一个过程(DML 命令)
- python - python中3D数据的线性插值
- reactjs - 使用 YUP 验证文件大小和格式
- c# - WPF 强制 UI 更新
- asp.net-core - 我如何在 linq2db 中管理多个数据库
- python - 如何在 Turtle Graphics Python 3 中设置绘图点
- plantuml - 如何混合不同的植物图类型元素?
- asp.net-mvc - Redis 缓存不适用于 Asp.net 核心
- php - 如果我从 PDF 复制文本并使用 ckeditor 粘贴,双引号将变为破折号。为什么角色会变?
- web - 如何使用 Web 组件触发 React 点击事件