iPhone X support



Just wanted to share a quick tip because I figured out how to do this today.

Don’t target iPhone X specifically
Make sure you don’t specifically optimize for iPhone X (based on its screen size), but rather for the so-called “safe insets” that Apple is now imposing on us (the poor designers and developers that have to cope with this nonsense). Why? Because the next iPad may very well have the same issue (a swipe-indicator instead of a home button… and perhaps even worse: also a notch.).

My approach
I’m using Angular, so non-Angular users may need to ‘transpile’ this approach a bit.

The example I’d like to use here is a button that’s positioned at the bottom of the screen. All those buttons in my app have the same css class button-bottom-nav (note that you can of course add a new class like bottom-inset, but that’s not the point here). The point is: we’re going to alter that css class a bit at runtime in case we’re running on an iPhone X (click the image if you don’t see the green button at the bottom):

The ‘Betalen’ (‘Pay now’) label is almost obscured by the swipe indicator.

NativeScript native access to the rescue
Let’s use the new UIWindow.safeAreaInsets which has a .top and .bottom property. On non-iPhone X devices those insets are 0, but on iPhone X those are 44 and 34 respectively (IIRC).

In app.component.ts I have a ngOnInit which of course runs only once during the app’s lifetime, so that’s an excellent spot to add some iOS tweaks:

export class AppComponent implements OnInit {
  ngOnInit(): void {
    if (isIOS && application.ios.window.safeAreaInsets) {
      const bottomSafeArea: number = application.ios.window.safeAreaInsets.bottom;
      if (bottomSafeArea > 0) {
            Button.button-bottom-nav { padding-bottom: ${bottomSafeArea} !important }

Now the button looks awesome on iPhone X - and no changes were applied to any other device:

One more thing
Is your app hiding the ActionBar and have a fullscreen background? Then also allow the background to span underneath the statusbar. Otherwise you’ll have a white area where the statusbar sits:

this.page.actionBarHidden = true;
this.page.backgroundSpanUnderStatusBar = true; // add this


Thanks @Eddy
Here’s @davecoffin’s way of handling it,
in NS Core


Ah noice! Excellent blog! Seems like Dave’s using the screen dimensions which I wouldn’t advocate though. :kissing_heart:


@eddy Yea I like your approach way better! Mine I threw together days after xcode 9 came out. I’ll update my blog.


Great! This is something we’re almost always gonna need in every iOS app, we should get something like this in the core & docs


@sitefinitysteve I totally agree with you on that


I borrowed from @NathanaelA for my implementation. In my app, all our main views have the same wrapping elements, and their components extend our PageComponent class. So I just setup a boolean to be checked in the constructor:

checkIsiPhoneX(): boolean  {
        if (!isIOS) {
            return false;

        // See: https://github.com/NativeScript/ios-runtime/issues/698
        const _SYS_NAMELEN: number = 256;

        /* tslint:disable-next-line: no-any */
        const buffer: any = interop.alloc(5 * _SYS_NAMELEN);
        let name: string = NSString.stringWithUTF8String(buffer.add(_SYS_NAMELEN * 4)).toString();

        // Get machine name for Simulator
        if (name === 'x86_64' || name === 'i386') {
            name = NSProcessInfo.processInfo.environment.objectForKey('SIMULATOR_MODEL_IDENTIFIER');

        return name.indexOf('iPhone10') === 0;

That’s a reduced version of what I found in the nativescript-platform-css plugin.

Once you have that, you use that boolean to set a class (like “iphonex”) on the topmost wrapping element you have access too. If you’re in an angular app, then you just use the /deep/ rule to add rules specifically for it!

/deep/ .iphonex & {
    margin-top: 30;


Or you could wait until this PR is merged into master branch :slight_smile:

There you will get safeAreas for iOS11, layoutGuides for iOS<11 and many more goodies (and changes)


I just upgraded to NS 3.3 and Xcode 9. My splash (launch) screen has white space at the bottom of iPhone X.

I tried creating a default ng app to cross check whether it is just with my app, it was same white space at the bottom even there. Any idea how to fix that, do I need a bigger image at LaunchScreen.AspectFill.imageset, may @3x?