andreamazz / AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
MIT License
6.05k stars 634 forks source link

Web view's content behind navigation bar when returning from safari view controller #366

Open Cordavi opened 5 years ago

Cordavi commented 5 years ago

Describe the bug When presenting a SFSafariViewController on top of a view controller that uses a ScrollingNavigationController and returning to the app, the web view content will be behind the navigation bar when scrolling to the top. Upon inspecting various older version, this behavior was not apparent in version 4.1.0 and before.

To Reproduce Steps to reproduce the behavior:

  1. Setup a view controller with a scrolling navigation bar and a web view
  2. Tap a link in the web content and open a safari view controller
  3. Return to the app and scroll to the top, the content will be behind the navigation bar.

Expected behavior The web view's content is not behind the navigation bar.

Screenshots

Jul-24-2019 17-26-25 Simulator Screen Shot - iPhone X - 2019-07-24 at 17 26 47

Cordavi commented 5 years ago

@andreamazz Do you have any insight into what may be causing this? I was trying to pinpoint it to put up a PR for it but having a hard time tracking it down.

Cordavi commented 5 years ago

Some additional investigation has shown that if I set shouldUpdateContentInset = false the placement issue gets resolved. Having said that, even though the placement is fixed with it off, the buttons on the navigation bar become unresponsive and can not be tapped. If you hiding and show the bar again, they become tappable again.

Cordavi commented 5 years ago

Further investigation shows me that when scrolling down on an iPhone X the contentInset top is being set to -44 which is the height of the navigation bar. This is normally reset to 0 when a user scrolls up after scrolling down.

When you scroll down and leave the application (in my case open a safari view controller), the content inset will get stuck at -44 even when scrolling up. If you repeatedly leave and come back, the inset will continue to grow more negative -44 + the previous times.

This is also an issue if the user starts the swipe to go back gesture but does not complete it. It will cause the contentInset to get stuck at -44.

Cordavi commented 5 years ago

Having said that, even though the placement is fixed with it off, the buttons on the navigation bar become unresponsive and can not be tapped. If you hiding and show the bar again, they become tappable again.

It seems that the navigationBar.isUserInteractionEnabled get stuck as false when having shouldUpdateContentInset = false set tapping a link to go to safari, coming back and tapping to scroll to the top. The code that would enable it when showing the navigation bar never gets called in this situation.

andreamazz commented 5 years ago

Hey @Cordavi Thanks for all the detective work, If that is the case it should be fairly easy to pinpoint the cause. Can you concoct a quick sample project showing the issue to help me debug this?

Cordavi commented 5 years ago

Here you go @andreamazz. To reproduce, I scroll to the bottom and click the link in the bio and then close the controller and scroll to the top. If you do that repeatedly, the amount will grow. example-AMScrollingNavBarBug.zip

andreamazz commented 5 years ago

I'm testing your sample, setting shouldUpdateContentInset to false seems to fix the issue (with hindsight I should have this default to false anyway). I tried adding a bar button to the navigation bar and it seems to be working fine though, the user interaction is always restored. I'm testing with iOS12 though, I can't test against 13 now, maybe that's the issue?

Cordavi commented 5 years ago

@andreamazz Here is an updated project that should reproduce the interaction issue hopefully. It does for me on an iOS 12 device iPhone 7 Plus. Hope that helps 😃 example-AMScrollingNavBarBug.zip

I am going into the article. Scrolling to the bottom and tapping the link in the bio. Coming back to the page and then tapping the status bar to scroll to the top of the page and then trying to take the back button.