Alright, I've discovered a solution for handling this issue:
First and foremost, you must detect if the device is an iPhoneX by following these steps:
In your app.component, initialize a variable that you save in a new or existing service responsible for managing global settings, like so:
export class MyApp {
//...
constructor (
//...
private settingsService: SettingService
) {
//...
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window['MSStream'];
// Get the device pixel ratio
const ratio = window.devicePixelRatio || 1;
// Define the user's device screen dimensions
const screen = {
width : window.screen.width * ratio,
height : window.screen.height * ratio
};
// Detect iPhone X
if (iOS && screen.width == 1125 && screen.height === 2436) {
// Set a global variable indicating that the device is iPhone X
this.settingsService.isIphoneX = true;
}
}
}
The code above does not belong to me, and I couldn't find the original source. The rightful owner will know it's theirs.
Once you have implemented this code, you can include the following within the page where you want to display content within the safe area.
To start, define a CSS class structure in the variables.scss file
*.display-in-safe-area-iphonex{
.scroll-content{
margin-bottom:30px;
margin-top: 40px;
}
}
Next, inject the settingService into the desired page and add the ngClass attribute within the ion-content tag of your page as shown below:
<ion-content [ngClass]="{'display-in-safe-area-iphonex': settingService.isIphoneX}">
<!-- content -->
</ion-content>
In my experience, using 40px for the top notch and 30px for the bottom bar has worked well.