Bug 157431 - WKActionSheet tries to present on wrong view controller
Summary: WKActionSheet tries to present on wrong view controller
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Safari 9
Hardware: iPhone / iPad iOS 9.3
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-06 14:14 PDT by Kevin Ballard
Modified: 2016-05-06 14:17 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Ballard 2016-05-06 14:14:29 PDT
When WKActionSheet is presented, it uses `[[_sheetDelegate hostViewForSheet].window rootViewController]` as the view controller to present from. But this doesn't work if the webview is actually inside a modally-presented view controller. This results in the sheet never showing and the following logged to the console:

Warning: Attempt to present <WKActionSheet: 0x7fbdac077a00> on <RootViewController: 0x7fbda8d7b340> whose view is not in the window hierarchy!

I imagine there's also issues with the rotation behavior, since it looks like it's supposed to dismiss itself and re-present after rotation.

The correct fix is to replace -hostViewForSheet with a method that returns the host UIViewController instead, but if that's problematic a quick fix would be to walk the presentedViewController chain to find the leaf controller and present on that (but this approach will have issues with view controllers that aren't fullscreen).
Comment 1 Kevin Ballard 2016-05-06 14:17:23 PDT
Another possible fix is instead of getting the window of the host view, it could instead walk the nextResponder chain until it finds a UIViewController and present on that. This is probably a better solution than walking the presentedViewController chain (and probably what the hypothetical `[_sheetDelegate hostViewControllerForSheet]` would have to do anyway since WKWebView doesn't know what view controller it's inside of).