Cordova iPhone X safe area after layout/orientation changes.










1















I'm using the CSS variable safe-area-inset-top in my Cordova app to handle iPhone X safe area:



body 
padding-top: env(safe-area-inset-top);



Works as expected when the app boots up. However, when I enter and exit a full screen (forced landscape) AVPlayer via a custom plugin, and return to the portrait app, the padding is gone and my app is partially cut off.



I'm currently using this in my AVPlayerViewController class within the plugin on iOS.



LandscapeVideo.m



- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
return UIInterfaceOrientationLandscapeRight; // or LandscapeLeft


- (UIInterfaceOrientationMask)supportedInterfaceOrientations
return UIInterfaceOrientationMaskLandscape;



Thanks in advance for any help / ideas!










share|improve this question






















  • I have the exact same problem in an empty project so it should not be related to the AVPlayer. It's looking fine at start-up but after I change the orientation of the iphone X emulator, the padding is reduced to 8px (rendering my content behind the notch). Rotating it back to portrait keeps the padding at 8px (which is wrong).

    – pascalzon
    Nov 28 '18 at 12:49















1















I'm using the CSS variable safe-area-inset-top in my Cordova app to handle iPhone X safe area:



body 
padding-top: env(safe-area-inset-top);



Works as expected when the app boots up. However, when I enter and exit a full screen (forced landscape) AVPlayer via a custom plugin, and return to the portrait app, the padding is gone and my app is partially cut off.



I'm currently using this in my AVPlayerViewController class within the plugin on iOS.



LandscapeVideo.m



- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
return UIInterfaceOrientationLandscapeRight; // or LandscapeLeft


- (UIInterfaceOrientationMask)supportedInterfaceOrientations
return UIInterfaceOrientationMaskLandscape;



Thanks in advance for any help / ideas!










share|improve this question






















  • I have the exact same problem in an empty project so it should not be related to the AVPlayer. It's looking fine at start-up but after I change the orientation of the iphone X emulator, the padding is reduced to 8px (rendering my content behind the notch). Rotating it back to portrait keeps the padding at 8px (which is wrong).

    – pascalzon
    Nov 28 '18 at 12:49













1












1








1


0






I'm using the CSS variable safe-area-inset-top in my Cordova app to handle iPhone X safe area:



body 
padding-top: env(safe-area-inset-top);



Works as expected when the app boots up. However, when I enter and exit a full screen (forced landscape) AVPlayer via a custom plugin, and return to the portrait app, the padding is gone and my app is partially cut off.



I'm currently using this in my AVPlayerViewController class within the plugin on iOS.



LandscapeVideo.m



- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
return UIInterfaceOrientationLandscapeRight; // or LandscapeLeft


- (UIInterfaceOrientationMask)supportedInterfaceOrientations
return UIInterfaceOrientationMaskLandscape;



Thanks in advance for any help / ideas!










share|improve this question














I'm using the CSS variable safe-area-inset-top in my Cordova app to handle iPhone X safe area:



body 
padding-top: env(safe-area-inset-top);



Works as expected when the app boots up. However, when I enter and exit a full screen (forced landscape) AVPlayer via a custom plugin, and return to the portrait app, the padding is gone and my app is partially cut off.



I'm currently using this in my AVPlayerViewController class within the plugin on iOS.



LandscapeVideo.m



- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
return UIInterfaceOrientationLandscapeRight; // or LandscapeLeft


- (UIInterfaceOrientationMask)supportedInterfaceOrientations
return UIInterfaceOrientationMaskLandscape;



Thanks in advance for any help / ideas!







ios cordova layout






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 22:02









ndmwebndmweb

1,28462236




1,28462236












  • I have the exact same problem in an empty project so it should not be related to the AVPlayer. It's looking fine at start-up but after I change the orientation of the iphone X emulator, the padding is reduced to 8px (rendering my content behind the notch). Rotating it back to portrait keeps the padding at 8px (which is wrong).

    – pascalzon
    Nov 28 '18 at 12:49

















  • I have the exact same problem in an empty project so it should not be related to the AVPlayer. It's looking fine at start-up but after I change the orientation of the iphone X emulator, the padding is reduced to 8px (rendering my content behind the notch). Rotating it back to portrait keeps the padding at 8px (which is wrong).

    – pascalzon
    Nov 28 '18 at 12:49
















I have the exact same problem in an empty project so it should not be related to the AVPlayer. It's looking fine at start-up but after I change the orientation of the iphone X emulator, the padding is reduced to 8px (rendering my content behind the notch). Rotating it back to portrait keeps the padding at 8px (which is wrong).

– pascalzon
Nov 28 '18 at 12:49





I have the exact same problem in an empty project so it should not be related to the AVPlayer. It's looking fine at start-up but after I change the orientation of the iphone X emulator, the padding is reduced to 8px (rendering my content behind the notch). Rotating it back to portrait keeps the padding at 8px (which is wrong).

– pascalzon
Nov 28 '18 at 12:49












2 Answers
2






active

oldest

votes


















1














Fix for iPhone X/XS screen rotation issue



On iPhone X/XS, a screen rotation will cause the header bar height to use an incorrect value, because the calculation of safe-area-inset-* was not reflecting the new values in time for UI refresh. This bug exists in UIWebView even in the latest iOS 12. A workaround is inserting a 1px top margin and then quickly reversing it, which will trigger safe-area-inset-* to be re-calculated immediately. A somewhat ugly fix but it works if you have to stay with UIWebView for one reason or another.






window.addEventListener("orientationchange", function() 
var originalMarginTop = document.body.style.marginTop;
document.body.style.marginTop = "1px";
setTimeout(function ()
document.body.style.marginTop = originalMarginTop;
, 100);
, false);





The purpose of the code is to cause the document.body.style.marginTop to change slightly and then reverse it. It doesn't necessarily have to be "1px". You can pick a value that doesn't cause your UI to flicker but achieves its purpose.






share|improve this answer
































    0














    As seen in the notes about device orientation of this answer:
    https://stackoverflow.com/a/46232813/1085272



    There is a safe-area-inset-xxx issue after some orientation changes when using uiWebView (which is default).



    Switching to WKWebView (e.g. by using cordova-plugin-wkwebview-engine) fixed the issue for me.






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290178%2fcordova-iphone-x-safe-area-after-layout-orientation-changes%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Fix for iPhone X/XS screen rotation issue



      On iPhone X/XS, a screen rotation will cause the header bar height to use an incorrect value, because the calculation of safe-area-inset-* was not reflecting the new values in time for UI refresh. This bug exists in UIWebView even in the latest iOS 12. A workaround is inserting a 1px top margin and then quickly reversing it, which will trigger safe-area-inset-* to be re-calculated immediately. A somewhat ugly fix but it works if you have to stay with UIWebView for one reason or another.






      window.addEventListener("orientationchange", function() 
      var originalMarginTop = document.body.style.marginTop;
      document.body.style.marginTop = "1px";
      setTimeout(function ()
      document.body.style.marginTop = originalMarginTop;
      , 100);
      , false);





      The purpose of the code is to cause the document.body.style.marginTop to change slightly and then reverse it. It doesn't necessarily have to be "1px". You can pick a value that doesn't cause your UI to flicker but achieves its purpose.






      share|improve this answer





























        1














        Fix for iPhone X/XS screen rotation issue



        On iPhone X/XS, a screen rotation will cause the header bar height to use an incorrect value, because the calculation of safe-area-inset-* was not reflecting the new values in time for UI refresh. This bug exists in UIWebView even in the latest iOS 12. A workaround is inserting a 1px top margin and then quickly reversing it, which will trigger safe-area-inset-* to be re-calculated immediately. A somewhat ugly fix but it works if you have to stay with UIWebView for one reason or another.






        window.addEventListener("orientationchange", function() 
        var originalMarginTop = document.body.style.marginTop;
        document.body.style.marginTop = "1px";
        setTimeout(function ()
        document.body.style.marginTop = originalMarginTop;
        , 100);
        , false);





        The purpose of the code is to cause the document.body.style.marginTop to change slightly and then reverse it. It doesn't necessarily have to be "1px". You can pick a value that doesn't cause your UI to flicker but achieves its purpose.






        share|improve this answer



























          1












          1








          1







          Fix for iPhone X/XS screen rotation issue



          On iPhone X/XS, a screen rotation will cause the header bar height to use an incorrect value, because the calculation of safe-area-inset-* was not reflecting the new values in time for UI refresh. This bug exists in UIWebView even in the latest iOS 12. A workaround is inserting a 1px top margin and then quickly reversing it, which will trigger safe-area-inset-* to be re-calculated immediately. A somewhat ugly fix but it works if you have to stay with UIWebView for one reason or another.






          window.addEventListener("orientationchange", function() 
          var originalMarginTop = document.body.style.marginTop;
          document.body.style.marginTop = "1px";
          setTimeout(function ()
          document.body.style.marginTop = originalMarginTop;
          , 100);
          , false);





          The purpose of the code is to cause the document.body.style.marginTop to change slightly and then reverse it. It doesn't necessarily have to be "1px". You can pick a value that doesn't cause your UI to flicker but achieves its purpose.






          share|improve this answer















          Fix for iPhone X/XS screen rotation issue



          On iPhone X/XS, a screen rotation will cause the header bar height to use an incorrect value, because the calculation of safe-area-inset-* was not reflecting the new values in time for UI refresh. This bug exists in UIWebView even in the latest iOS 12. A workaround is inserting a 1px top margin and then quickly reversing it, which will trigger safe-area-inset-* to be re-calculated immediately. A somewhat ugly fix but it works if you have to stay with UIWebView for one reason or another.






          window.addEventListener("orientationchange", function() 
          var originalMarginTop = document.body.style.marginTop;
          document.body.style.marginTop = "1px";
          setTimeout(function ()
          document.body.style.marginTop = originalMarginTop;
          , 100);
          , false);





          The purpose of the code is to cause the document.body.style.marginTop to change slightly and then reverse it. It doesn't necessarily have to be "1px". You can pick a value that doesn't cause your UI to flicker but achieves its purpose.






          window.addEventListener("orientationchange", function() 
          var originalMarginTop = document.body.style.marginTop;
          document.body.style.marginTop = "1px";
          setTimeout(function ()
          document.body.style.marginTop = originalMarginTop;
          , 100);
          , false);





          window.addEventListener("orientationchange", function() 
          var originalMarginTop = document.body.style.marginTop;
          document.body.style.marginTop = "1px";
          setTimeout(function ()
          document.body.style.marginTop = originalMarginTop;
          , 100);
          , false);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 10 at 1:46

























          answered Jan 10 at 1:35









          YYLYYL

          44645




          44645























              0














              As seen in the notes about device orientation of this answer:
              https://stackoverflow.com/a/46232813/1085272



              There is a safe-area-inset-xxx issue after some orientation changes when using uiWebView (which is default).



              Switching to WKWebView (e.g. by using cordova-plugin-wkwebview-engine) fixed the issue for me.






              share|improve this answer



























                0














                As seen in the notes about device orientation of this answer:
                https://stackoverflow.com/a/46232813/1085272



                There is a safe-area-inset-xxx issue after some orientation changes when using uiWebView (which is default).



                Switching to WKWebView (e.g. by using cordova-plugin-wkwebview-engine) fixed the issue for me.






                share|improve this answer

























                  0












                  0








                  0







                  As seen in the notes about device orientation of this answer:
                  https://stackoverflow.com/a/46232813/1085272



                  There is a safe-area-inset-xxx issue after some orientation changes when using uiWebView (which is default).



                  Switching to WKWebView (e.g. by using cordova-plugin-wkwebview-engine) fixed the issue for me.






                  share|improve this answer













                  As seen in the notes about device orientation of this answer:
                  https://stackoverflow.com/a/46232813/1085272



                  There is a safe-area-inset-xxx issue after some orientation changes when using uiWebView (which is default).



                  Switching to WKWebView (e.g. by using cordova-plugin-wkwebview-engine) fixed the issue for me.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 28 '18 at 15:46









                  pascalzonpascalzon

                  687




                  687



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290178%2fcordova-iphone-x-safe-area-after-layout-orientation-changes%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                      Museum of Modern and Contemporary Art of Trento and Rovereto