I would like to integrate screen notch support for my cordova application. However a couple months ago the iPhone X is was the only smartphone with a screen notch so the detection and solution for it was pretty easy:
(function(){
// Really basic check for the ios platform
// https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
// Get the device pixel ratio
var ratio = window.devicePixelRatio || 1;
// Define the users device screen dimensions
var screen = {
width : window.screen.width * ratio,
height : window.screen.height * ratio
};
// iPhone X Detection
if (iOS && screen.width == 1125 && screen.height === 2436) {
alert('iPhoneX Detected!');
}
})();
I could then, with javascript, apply a top-offset of 20px so the screen notch support is complete.
However as more and more phones start using this screen notch the detection gets a lot more complicated and I don't know where to start. Does anyone have a good idea on how one would settle this problem?
As you can see below a lot of smartphone companies are starting to use the screen notch and a good app should support all devices right?
Phones with screen notch:
- Huawei P20 series
- Asus ZenFone 5 and 5Z
- Huawei Honor 10
- Oppo R15 and R15 Pro
- Oppo F7
- Vivo V9
- Vivo X21 and X21 UD
- OnePlus 6
- LG G7 ThinQ
- Leagoo S9
- Oukitel U18
- Sharp Aquos S3
- ...