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(compat): Set the app delegate viewController for plugins #1493

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

dpogue
Copy link
Member

@dpogue dpogue commented Oct 4, 2024

Platforms affected

iOS

Motivation and Context

Some plugins expect to be able to access the applications's CDVViewController via the AppDelegate. While previously we guaranteed that the viewController property was set to a non-nil CDVViewController, there was never any guarantee that it was set to the CDVViewController that is actually displaying the app (particularly in cases such as apps using CordovaLib only for a few pages as part of a larger app).

We've attempted to deprecate the property here, but some plugins still rely on the assumption that it will be non-nil, so we are trying to maintain compatibility in the common case here by assigning to it when a CDVViewController is loaded. This means there are still times in the app lifecycle where the viewController property is nil, but the deprecation warning will hopefully spur plugin developers to move away from that pattern.

Note

CDVPlugin always has a non-nil viewController property of its own, which is set to the CDVViewController instance the plugin was loaded into. This is almost always the better choice for plugins to use.

Testing

Existing unit tests pass.

Checklist

  • I've run the tests to see all new and existing tests pass

@dpogue dpogue added this to the 8.0.0 milestone Oct 4, 2024
Some plugins expect to be able to access the applications's
CDVViewController via the AppDelegate. While previously we guaranteed
that the `viewController` property was set to a non-nil
CDVViewController, there was never any guarantee that it was set to the
CDVViewController that is actually displaying the app (particularly in
cases such as apps using CordovaLib only for a few pages as part of a
larger app).

We've attempted to deprecate the property here, but some plugins still
rely on the assumption that it will be non-nil, so we are trying to
maintain compatibility in the common case here by assigning to it when a
CDVViewController is loaded. This means there are still times in the app
lifecycle where the `viewController` property is nil, but the
deprecation warning will hopefully spur plugin developers to move away
from that pattern.

Note: CDVPlugin always has a non-nil viewController property of its own,
which is set to the CDVViewController instance the plugin was loaded
into. This is almost always the better choice for plugins to use.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.56%. Comparing base (98a3bcd) to head (1ca5bcb).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1493   +/-   ##
=======================================
  Coverage   81.56%   81.56%           
=======================================
  Files          16       16           
  Lines        1888     1888           
=======================================
  Hits         1540     1540           
  Misses        348      348           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

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

LGTM

@dpogue dpogue merged commit 92df3b7 into apache:master Oct 8, 2024
10 checks passed
@dpogue dpogue deleted the delegate-vc branch October 8, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants