Extra bottom and top space in iPhone X in Xamarin form

I have solved this issue.

Here is a Answer.

  1. PCL create a interface to consume in IOS Native App.

    public interface IDeviceInfo
    {
        bool IsIphoneXDevice();
    }
    
  2. Implement this Interface in IOS Native App.

    [assembly: Dependency(typeof(DeviceInfoService))]
    namespace POC.iOS.DependencyServices
    {
        public class DeviceInfoService:IDeviceInfo
        {
            public DeviceInfoService() { }
    
            public bool IsIphoneXDevice()
            {
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    if ((UIScreen.MainScreen.Bounds.Height * UIScreen.MainScreen.Scale) == 2436)
                    {
                        return true;
                    }
                }
                return false;
            }
        }
    }
    
  3. Call this method in Xamarin form using dependency Service.And write logic for IPhone X layout.

    public partial class Page : ContentPage
    {
        public Page()
        {
            InitializeComponent();
    
            var isDeviceIphone = DependencyService.Get<IDeviceInfo>().IsIphoneXDevice();
            if (isDeviceIphone)
            {
                var safeInsets = On<Xamarin.Forms.PlatformConfiguration.iOS>().SafeAreaInsets();
                safeInsets.Bottom =20;
                safeInsets.Top = 20;
                this.Padding = safeInsets;
            }
        }
    }
    

The way I got the proper screen size to work on iOS, was by simply adding the proper splash screen images.

For example, in my iOS project I added into my Resources folder, an image named [email protected], and the dimensions of the image were 1125x2436.

And then in my Info.plist file, I added the following code under the UILaunchImages key:

<key>UILaunchImages</key>
    <array>
        <dict>
            <key>UILaunchImageMinimumOSVersion</key>
            <string>8.0</string>
            <key>UILaunchImageName</key>
            <string>Default-812h</string>
            <key>UILaunchImageOrientation</key>
            <string>Portrait</string>
            <key>UILaunchImageSize</key>
            <string>{375, 812}</string>
        </dict>
        ... other launch images ...
    </array>

I recently had the same issue. What I found out was that iOS determines if your app can handle iPhone X by the splash screen. There were no splash screen images that would work. I had to create a storyboard and use that for my splash screen. This link should help you out: https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_images/launch-screens/