apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 986 forks source link

refactor(template)!: Update app template to Swift & storyboards #1457

Closed dpogue closed 3 months ago

dpogue commented 3 months ago

To Do

Platforms affected

iOS

Motivation and Context

Closes https://github.com/apache/cordova-ios/issues/674. Closes https://github.com/apache/cordova-ios/issues/904.

Description

Replace the existing template project with one that uses modern Swift classes, storyboards, and customizes the CDVViewController using storyboard properties rather than relying on specifically-named colour variables being globally available.

This is one step that should make it easier and much more pleasant for people wanting to embed CDVViewController instances within their existing iOS apps.

Testing

Built to a simulator. All existing tests pass.

Checklist

codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 78.30%. Comparing base (fb8eeab) to head (d4e26bc).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1457 +/- ## ========================================== - Coverage 78.35% 78.30% -0.06% ========================================== Files 16 16 Lines 1825 1825 ========================================== - Hits 1430 1429 -1 - Misses 395 396 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dpogue commented 3 months ago

Current feedback is that some plugins are (unsafely!) trying to add category extensions to the template's AppDelegate class. This was never really a safe thing to do, since people can consume CordovaLib as a framework in their own projects with whatever class names they want.

The correct way for plugins to add behaviour to the app delegate is by extensions of the CDVAppDelegate base class.

The same issue probably exists with the view controller class as well.


For the sake of compatibility though, I'm looking at wrapping the AppDelegate and ViewController Swift classes in @objc and create empty header files for them with deprecation warnings.

// AppDelegate.h
#import <Cordova/Cordova.h>

#warning It is unsafe to rely on the AppDelegate class as an extension point. \
         Update your code to extend CDVAppDelegate instead -- \
         This code will stop working in Cordova iOS 9!

@interface AppDelegate : CDVAppDelegate
@end
// AppDelegate.swift
import Cordova;

@objc class AppDelegate : CDVAppDelegate
{
}

The downside of this method is that we're stuck with these compatibility hacks for at least one major version.

We also have to alias the ViewController class as MainViewController in ObjC for compatibility.