I'm implementing a <SafeAreaView>
on my React Native app. Most of my screens are in a ScrollView. When I add the <SafeAreaView>
, it obstructs the content. While I want this bottom area to be "safe", I'd like the user to be able to see the content behind it, otherwise, the space is wasted.
How do I implement a "transparent" safe area?
Simplified example:
class ExampleScreen extends Component {
render() {
return (
<SafeAreaView>
<Scrollview>
<Text>Example</Text>
<Text>Example</Text>
<Text>Example</Text>
(etc)
</Scrollview>
</SafeAreaView>
);
}
}
Output:
Desired Output:
In React native, the main goal of SafeAreaView component is to render content within the safe area boundaries of a device. All smartphones nowadays come with an edge-to-edge display. But smartphones must have some space left for the front cameras. Therefore all smartphones come with a notch or punch hole on the screen to fit the camera inside.
But SafeAreaView component takes away that headache from you and makes sure everything works fine on a device. Every component you write in SafeAreaView will render within the safe area boundaries of a device.
In simple words, it is the area where you don’t have to draw your imagination and have to keep it safe for native use. By default when you make a React Native App you have seen that it renders the content on the status bar too
For those who have no idea about the safe area, In iOS 7 Apple introduced the top layout guide and bottom layout guide properties which describes a screen area that isn’t covered by any content (status bar, navigation bar, toolbar, tab bar, etc.) but In iOS 11 Apple has deprecated these properties and introduced the safe area.
In most you do not want to have your ScrollView/FlatList
have as a descendant of a SafeAreaView
. Instead you only want to wrap your Header
and TabBar
into a SafeAreaView
. Some examples:
Instead of this (WRONG EXAMPLE)
<SafeAreaView>
<Header />
<ScrollView>
<Content />
</ScrollView>
</SafeAreaView>
you only wrap the header
<View>
<SafeAreaView>
<Header />
</SafeAreaView>
<ScrollView>
<Content />
</ScrollView>
</View>
Also even if you do not really have a Header, you only want to avoid drawing behind the status bar, you can use the SafeAreaView
as padding.
<View>
<SafeAreaView /> // <- Now anything after this gonna be rendered after the safe zone
<Content />
</View>
Maybe this late answer but you can easily use
class ExampleScreen extends Component {
render() {
return (
<SafeAreaView edges={['right', 'left', 'top']} >
<Scrollview>
<Text>Example</Text>
<Text>Example</Text>
<Text>Example</Text>
(etc)
</Scrollview>
</SafeAreaView>
);
}
}
You could try react-navigation's SafeAreaView. Just set it's forceInset
prop to { bottom: 'never' }
and you'll see it behaves as your expectation.
Example: https://github.com/react-navigation/react-navigation/blob/master/examples/SafeAreaExample/App.js
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