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

前端 未结 9 1803
一生所求
一生所求 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

    Instead of using Platform API, you can use expo constants.

    npm i expo-constants
    

    then import it in your component as

    import Constants from "expo-constants"
    

    and then in the styles you can use it like this

    const styles = StyleSheet.create({
    container: {
    paddingTop: Constants.statusBarHeight
    } });
    

    To see all the properties of Constants console log it you will find some more useful things.

提交回复
热议问题