Spawning a UI Window from Plugin Method Causes Unpredictable results
See original GitHub issueIf you spawn a ViewController from a plugin on iOS, the following warning appears in the console:
Main Thread Checker: UI API called on a background thread
And
[Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.
Which is certainly true. I’ve experienced weird rendering bugs, where certain things in a scene won’t render in the proper order - unpredictably each launch. Sometimes it works fine, sometimes labels will be moved under other elements.
I’ve tested this out by removing the dispatchQueue.async
call here: https://github.com/ionic-team/capacitor/blob/master/ios/Capacitor/Capacitor/CAPBridge.swift#L385
With the Async wrapper removed, the UIView runs great.
It’d be nice if there was a way to tell Capacitor that I specifically want a method to run in the foreground because I’ll be launching UI elements to skirt around this whole issue.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
You need to execute any UI operations on the main thread, for example: https://github.com/ionic-team/capacitor/blob/master/ios/Capacitor/Capacitor/Plugins/Modals.swift#L20
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.