How to prevent layout from overlapping with iOS status bar

前端 未结 8 2104
礼貌的吻别
礼貌的吻别 2020-12-24 04:45

I am working on tutorial for React Native navigation. I found out that all layout starts loading from top of screen instead of below of the status bar. This causes most layo

8条回答
  •  粉色の甜心
    2020-12-24 04:47

    The react-navigation docs have a great solution for this. First off, they recommend not to use the SafeAreaView included with React Native because:

    While React Native exports a SafeAreaView component, it has some inherent issues, i.e. if a screen containing safe area is animating, it causes jumpy behavior. In addition, this component only supports iOS 10+ with no support for older iOS versions or Android. We recommend to use the react-native-safe-area-context library to handle safe areas in a more reliable way.

    Instead, they recommend react-native-safe-area-context - with which it would look like this:

    import React, { Component } from 'react';
    import { View, Text, Navigator } from 'react-native';
    import { useSafeArea } from 'react-native-safe-area-context';
    
    export default function MyScene({title = 'MyScene'}) {
        const insets = useSafeArea();
    
        return (
            
                Hi! My name is {title}.
             
        )   
    }
    

    I would like to note that it's probably a better idea to use the SafeAreaView that this library offers though, since phones these days may also have elements at the bottom that can overlap UI elements. It all depends on your app of course. (For more detail on that, see the react-navigation docs I linked to in the beginning.)

提交回复
热议问题