Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Notices showing anywhere but the bottom on iPad devices #11345

Merged
merged 5 commits into from
Mar 27, 2019

Conversation

shiki
Copy link
Member

@shiki shiki commented Mar 27, 2019

Fixes #11325.

The bug seems to consistently happen when you launch the app, show a Notice, and then rotate the device.

Starting Orientation After Rotating
develop-before-rotate develop-after-rotate

The Problem

Based on my tests, the UntouchableViewController.view never gets automatically resized when the device is rotated. The first orientation that the app is launched in will determine the size of the view.

This only happens on iPad devices. For iPhone, the view seems to be rotated correctly.

The Solution

Based on @nheagy's advice, this is a regression. We hunted for the cause and found that this started happening in 4cac38f. It looks like the auto-resizing gets disabled when the window is not visible after it is initialized. This PR restores that. It will still be hidden but on the next UI loop.

The MaskView got affected with the fix so the MaskView frame update had to be fixed as well.

Testing

To reproduce the bug:

  1. iPad only: Start the app on landscape
  2. Go to Site → Pages
  3. Turn off the internet connection
  4. The offline error Notice will be shown.
  5. Rotate the device.
  6. Pull to refresh the page.
  7. The offline error Notice is not shown.

Please also play around with showing the Notice while on portrait.

This regression happened in 4cac38f. The `UntouchableWindow` rotation is fixed but this causes a bug in `MaskView` which will be fixed in a later commit.
The window.isHidden is enough to keep the auto-resize on iPads.
@shiki shiki requested a review from nheagy March 27, 2019 15:21
@shiki shiki self-assigned this Mar 27, 2019
@shiki shiki added this to the 12.2 milestone Mar 27, 2019
Copy link
Contributor

@nheagy nheagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work on finding the root cause of this one!

I made two suggestions. I think the comment change is important, but the other one is just a suggestion—ignore it if you like 😀

@@ -70,6 +70,14 @@ class NoticePresenter: NSObject {

super.init()

// Keep the window visible but hide it on the next run loop. If we hide it immediately,
// the window is not automatically resized when the device is rotated. This issue
// only happens on iPad devices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this comment to mention that the problem appears to be only in the simulator?

That way we can revisit it in the future if this code gets refactored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

// Update the `frame` on the next run loop. When this Notification event handler is
// called, the `self.parentView` still has the frame from the previous orientation.
// Running this routine after the current run loop ensures we have the correct frame.
DispatchQueue.main.async { [weak self] in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a suggestion but, what if we wrapped the DispatchQueue.main.async call in a method with a name that explained what was going on, such as

waitALoopSoRotationWorksOnSimulator() {
    self.frame = MaskView.calculateFrame(parent: self.parentView, untouchableVC: self.untouchableVC)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. 😬I think it's already well contained in this method. Perhaps I can add a comment in line 73 to re-evaluate this method if the iPad simulator issue ever gets fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What made me think of it is that we're calling DispatchQueue.main.async twice, with the only hint that they're related being the comments. I like good comments, but I fear that they're fragile, ya know?

Anyway, still up to you 👍

We tested on both iOS 11 and 12 simulators. We tested on an iPad device with iOS 12 and this bug does not happen.
@shiki shiki requested a review from nheagy March 27, 2019 21:59
@shiki
Copy link
Member Author

shiki commented Mar 27, 2019

@nheagy Thank you for the thorough testing and review.

I updated just the comment for now. 🙂 Please let me know if the comment is good enough.

Copy link
Contributor

@nheagy nheagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @shiki!

I trust your judgement on the second suggestion 😀

:shipit: !

@shiki shiki merged commit 4032c72 into develop Mar 27, 2019
@shiki shiki deleted the issue/11325-notice-ipad-v2 branch March 27, 2019 22:11
@shiki shiki moved this from Done to Done (Pull Requests) in Offline Support: Messaging Apr 10, 2019
megmil added a commit to megmil/WordPress-iOS that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Offline Support: Messaging
  
Done (Pull Requests)
Development

Successfully merging this pull request may close these issues.

iPad: Notices are not shown after rotating the device
2 participants