(React native) How to use SafeAreaView for Android notch devices?

前端 未结 9 1759
一生所求
一生所求 2020-12-24 06:45

I\'m actually developing an app with react native and i\'m testing with my one plus 6 and it has a notch. The SafeAreaView is a solution for the iPhone X but for Android, it

9条回答
  •  生来不讨喜
    2020-12-24 07:41

    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 (
          
              //More controls and such
          
        );
      }
    }
    

    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.

提交回复
热议问题