Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with safeAreaView + React Navigation?

enter image description here

First screenshot was without applying SafeAreaView and second screenshot is applying SafeAreaView

enter image description here

As shown clearly that Stack header seems bulky as compare to previously. Is there anyway where we can apply SafeAreaView to only bottom part?

like image 774
Isaac Avatar asked Nov 26 '18 07:11

Isaac


People also ask

How do I stop going back to react navigation?

To make this work, you need to: Disable the swipe gesture for the screen ( gestureEnabled: false ). Override the native back button in the header with a custom back button ( headerLeft: (props) => <CustomBackButton {... props} /> ).

Where do I put SafeAreaView?

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.

How do I keep my layout from overlapping with iOS status bar?

I found out that all layout starts loading from top of screen instead of below of the status bar. This causes most layouts to overlap with the status bar. I can fix this by adding a padding to the view when loading them.

Is SafeAreaView scrollable?

SafeAreaView is dynamic, if the first element on a screen is a ScrollView , and has children SafeAreaView s, when the user scrolls down, the SafeAreaView reduces in height because it's not touching the safe area anymore, which in contrast scrolls the content back up.


1 Answers

For React Navigation v5, there is no SafeAreaView exported. The recommended way is to use react-native-safe-area-context.

Read more: React Navigation v5.x - Supporting safe areas.

Example

import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';

function Demo() {
  return (
    <SafeAreaView
      style={{ flex: 1, justifyContent: 'space-between', alignItems: 'center' }}
    >
      <Text>This is top text.</Text>
      <Text>This is bottom text.</Text>
    </SafeAreaView>
  );
}

export default function App() {
  return (
    <SafeAreaProvider>
      <NavigationContainer>{/*(...) */}</NavigationContainer>
    </SafeAreaProvider>
  );
}
like image 152
wobsoriano Avatar answered Oct 11 '22 23:10

wobsoriano