cordova-ios
cordova-ios copied to clipboard
fix: alerts could freeze the application
Platforms affected
iOS
Motivation and Context
Closes GH-1120. Closes GH-1121. Closes GH-1429.
Description
In cases where the system was presenting something on the screen (such as a permission prompt, or an undo dialog) or in cases where the CDVViewController was not the root view controller (such as in a tabbed navigator), trying to show any dialogs triggered from the WebView would attempt to create an alert on the root view controller and get the view hierarchy into a bad state.
Now, we only try to display alerts on the CDVViewController that owns the WebView. This means that alerts can potentially end up behind other system dialogs, but the view controller no longer freezes.
(As an aside, having access to the CDVViewController here will be helpful for some future things too...)
Testing
Tested manually by triggering an alert while a permission prompt was being displayed and confirmed that the app continued working as expected.
Checklist
- [x] I've run the tests to see all new and existing tests pass
- [x] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 80.22%. Comparing base (
8e59e52) to head (9cb8f8d).
Additional details and impacted files
@@ Coverage Diff @@
## master #1437 +/- ##
=======================================
Coverage 80.22% 80.22%
=======================================
Files 16 16
Lines 1871 1871
=======================================
Hits 1501 1501
Misses 370 370
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This will still cause issues like not allowing to stack multiple alerts or not showing them if a view controller is present (i.e. InAppBrowser or Camera). In Dialogs plugin we have a helper function that gets the top view controller, but not sure if it could cause the freezing issue mentioned here. https://github.com/apache/cordova-plugin-dialogs/blob/master/src/ios/CDVNotification.m#L151-L161
I did some testing of alert dialogs with this PR while the camera and file pickers were open, and it seemed to work as expected with no freezes.