I'm developing an app with React Native and I'm testing with my OnePlus 6 and it has a notch. The SafeAreaView is a solution for the iPhone X but for Android, it seems there is no solution.
How to solve this kind of issue?
The SafeAreaView is a solution for the iPhone X but for Android, it seems there is no solution.
The purpose of SafeAreaView is to render content within the safe area boundaries of a device. It is currently only applicable to iOS devices with iOS version 11 or later.
You have to only use when any screen has headerMode:none or it out side of the navigation. If you are using full screen modal then you should use <SafeAreaView> . I don't thing having navigation handles it. For android it might but for iOS with swipe gesture to go to home on bottom, one must use safeareview.
import { SafeAreaView } from 'react-native'; You just use it in place of the top-level View component. It makes sure content within the safe area boundaries is properly rendered around the nested content and applies padding automatically.
Do something like
import { StyleSheet, Platform, StatusBar } from "react-native"; export default StyleSheet.create({ AndroidSafeArea: { flex: 1, backgroundColor: "white", paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0 } });
And then In your App.js
import SafeViewAndroid from "./components/SafeViewAndroid"; <SafeAreaView style={SafeViewAndroid.AndroidSafeArea}> <Layout screenProps={{ navigation: this.props.navigation }} /> //OR whatever you want to render </SafeAreaView>
This should work good as get height will take care of the knotch in android device by calculating the statusBar height and it will arrange accordingly.
A work around I had to use recently:
GlobalStyles.js:
import { StyleSheet, Platform } from 'react-native'; export default StyleSheet.create({ droidSafeArea: { flex: 1, backgroundColor: npLBlue, paddingTop: Platform.OS === 'android' ? 25 : 0 }, });
It is applied like so:
App.js
import GlobalStyles from './GlobalStyles'; import { SafeAreaView } from "react-native"; render() { return ( <SafeAreaView style={GlobalStyles.droidSafeArea}> //More controls and such </SafeAreaView> ); } }
You'll probably need to adjust it a bit to fit whatever screen you're working on, but this got my header just below the icon strip at the top.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With