Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native Detect Screen Notch

I am using nativebase.io as the UI framework for my app.

My issue

when I input a header for an IOS device, if the iPhone simulator is simulating iPhone X, (where there is a notch on the top of the screen), the Header element automatically detects this and moves the Header element lower on the screen.

some android devices also have a similar notch at the top of the screen, but when I use a nativebase.io Header element, it doesn't detect the notch and the Header overlaps the notch.

My question

is there a way on react-native or nativebase.io to detect if the display has a notch? this way I could dynamically offset the Header.

like image 635
X0r0N Avatar asked Aug 15 '18 12:08

X0r0N


People also ask

How does react-native identify notch?

Android notches​ Install react-native-device-info. Check if the device has a notch with DeviceInfo. hasNotch() - this compares the device brand and model to a list of devices with notches - a crude but effective workaround.

What is hasNotch in react-native?

React Native device info provide hasNotch() function to check device have notch or not it will return only true or false . hasNotch() function work in ios, android, and windows.

How do you stop notch in react-native?

One approach is to use SafeAreaView component available in React Native. 1import { SafeAreaView } from 'react-native'; It can be used in the place of the top-level View component. It renders content within the safe area boundaries around the nested content and automatically applies padding.

What is the use of SafeAreaView in react-native?

The purpose of SafeAreaView is to render content within the safe area boundaries of a device. It is currently only applicable to iOS devices with iOS version 11 or later.


1 Answers

Since the problem is on android, maybe you should try looking into StatusBar.currentHeight. Since the notch generally is part of the status bar, adding a padding on top of the header the size of the status bar should probably do it.

like image 178
Filipe Avatar answered Sep 17 '22 14:09

Filipe