react-native - 不起作用(视图位于通知选项卡上方)
问题描述
由于某种原因,safeAreaView 在我的代码中不起作用,视图位于通知选项卡上方。我已经尝试了几件事,但不能。我尝试采用 safeAreaView 的样式并在 safeAreaView 下方创建一个包含所有代码的视图,然后在该视图中放置该样式,但它也不起作用!
import React from 'react';
import { SafeAreaView, StyleSheet, View, Image, Text } from 'react-native';
export default function Menu({ navigation }){
return <SafeAreaView style={styles.container}>
<View style={styles.profile}>
<Image source={{uri: 'https://elysator.com/wp-content/uploads/blank-profile-picture-973460_1280-e1523978675847.png'}} style={styles.imageProfile} />
<Text style={styles.name}>StackOverFlow</Text>
</View>
</SafeAreaView>
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
profile: {
flexDirection: 'row',
backgroundColor: '#EEE',
},
imageProfile: {
width: 34,
marginBottom: 5,
marginTop: 5,
borderRadius: 44/2,
marginLeft: 10,
height: 34
},
name: {
alignSelf: 'center',
marginLeft: 10,
fontSize: 16
}
});
解决方案
根据 react-native 文档:
SafeAreaView 的目的是在设备的安全区域边界内呈现内容。目前仅适用于 iOS 版本 11 或更高版本的 iOS 设备。
我建议您不要只遵循 safeAreaView 功能。而是更好地提取状态栏高度并为整个容器提供一个marginTop,使其始终位于状态栏下方。请参阅下面的代码以及工作博览会小吃解决方案:
import React from 'react';
import { SafeAreaView, StyleSheet, View, Image, Text,StatusBar } from 'react-native';
export default function Menu({ navigation }){
return <SafeAreaView style={styles.container}>
<View style={styles.profile}>
<Image source={{uri: 'https://elysator.com/wp-content/uploads/blank-profile-picture-973460_1280-e1523978675847.png'}} style={styles.imageProfile} />
<Text style={styles.name}>StackOverFlow</Text>
</View>
</SafeAreaView>
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop:StatusBar.currentHeight
},
profile: {
flexDirection: 'row',
backgroundColor: '#EEE',
},
imageProfile: {
width: 34,
marginBottom: 5,
marginTop: 5,
borderRadius: 44/2,
marginLeft: 10,
height: 34
},
name: {
alignSelf: 'center',
marginLeft: 10,
fontSize: 16
}
});
世博链接:expo-snack
希望能帮助到你。随时怀疑
推荐阅读
- oop - Clojurescript:制作弹跳球的实用方法
- firebase - 在 Firebase Unity SDK 中发现错误,我该怎么办?
- html - Bootstrap css主容器div低于侧导航栏
- c++ - 我不能使用带有 unique_ptrs 的“填充”std::vector 构造函数
- angularjs - AngularJS UI-Router 不会显示所有组件(只有一些)
- javascript - Jquery FileReader 在缩略图中输入多个图像显示
- javascript - 在 React Native 中更新 id 元素
- apache-spark - 火花错误 - 安装错误
- regex - 只输出匹配的正则表达式模式
- vba - 比较基于常见“id”字段的不常见单元格的两个 excelsheets(C 列)