One of the elements that shipped with React 0.50 is <SafeAreaView />
. It’s a component which you can use to prevent your content from creeping below The Notch and Home Indicator on iPhone X.
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: '#ddd'
}
})
For the best result give the <SafeAreaView />
the same backgroundColor
as your <App />
component, or use the <SafeAreaView />
within your <App />
component where needed.
Projects like react-navigation
use <SafeAreaView />
to properly layout their StackNavigator
.
Do note that the version that ships with RN itself differs from the version maintained by the React Community.
Using SafeAreaView with iPhone X and React Native →
React Native & iPhone X →
Why is this even possible in the first place? 😅
What do you mean with “this”? The fact that content can go below “the notch”? Don’t get it 😬
Sorry, I wasn’t clear. Yes, the example on the left iPhone in the image. I can see why it makes sense to allow content to go underneath the bar at the bottom of the screen, but not at the top of the screen, since it contains a the status bar that is already full, so there’s no room for the app’s content anyway.
Must say I do see some use cases. Here’s a screenshot of an app I made. If the map were to be cut off that’d be a whole different effect.
it looks way better without cutting 😛
It seems that SafeAreaView crops the top. How did you manage to spread the map under the status bar? 🤔
@Igor: You only need to use
SafeAreaView
if you want to prevent stuff from creeping underneath The Notch (TM).In my example I have placed the Map outside the
SafeAreaView
, so that it fills all the available space it can take.Thanks for the reply. I managed to use SafeAreaView with forceInset={{ top: ‘never’ }} to make it aware only of the bottom.
I have a clarification. Here the withSafeArea has a space in it’s header. Is this is a correct behaviour.