[英]How do I set the color of the notch on iPhone X in React Native
您可以簡單地使用react-native新版本51中的SafeAreaView。
import {
...
SafeAreaView
} from 'react-native';
class Main extends React.Component {
render() {
return (
<SafeAreaView style={styles.safeArea}>
<App />
</SafeAreaView>
)
}
}
const styles = StyleSheet.create({
...,
safeArea: {
flex: 1,
backgroundColor: '#FF5236'
}
})
請參閱: 如何在React Native中設置iOS狀態欄背景顏色?
import DeviceInfo from 'react-native-device-info';
// getModel: iPhone X // getDeviceId: iPhone10,3 const ModelIphoneX = 'iPhone X';
// StatusBarHeight is where Carrier info and date display at top // iPhone X has a cut-out in top of dispaly where sensor package is located. // For iPhone X increase height so cut-out does not hide text const StatusBarHeightIos = DeviceInfo.getModel() === ModelIphoneX ? 30 : 20; const StatusBarHeight = Platform.OS === 'ios' ? StatusBarHeightIos : 0;
屏幕截圖:左側是iPhone X.
通過使用XCode將應用程序啟動屏幕從圖像資源更改為故事板,可以解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.