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

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

Merged
merged 5 commits into from
Aug 20, 2024

Conversation

dpogue
Copy link
Member

@dpogue dpogue commented Aug 14, 2024

To Do

  • Confirm the template Xcode project has all the right files (I think it might be missing the Staging folder, and maybe one of the build.xcconfig files)

Platforms affected

iOS

Motivation and Context

Closes #674.
Closes #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

  • I've run the tests to see all new and existing tests pass
  • 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)

@dpogue dpogue added this to the 8.0.0 milestone Aug 14, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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     

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

@dpogue dpogue force-pushed the refactor2-template branch 4 times, most recently from 96e7b91 to 6a7084c Compare August 15, 2024 07:46
@dpogue
Copy link
Member Author

dpogue commented Aug 15, 2024

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.

The template's storyboard should handle the initialization of the view
controller, rather than constructing it manually here.
Bump min iOS version for template app to 13.0 (due to UISceneDelegate)
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.

Though the PR is currently in Draft, I think it LGTM.

I tested:

  • Building the Cordova sample app with Xcode 16 Beta 5.
  • Building and running against all Apache Cordova default plugins.
  • Running on iOS 18 beta 5 Simulator
  • Tested against a plugin that uses CocoaPods

When testing a plugin that uses CocoaPods, warning: Stale file may print out in the build output. These are only warnings and the build still succeeded. These type of warnings are not uncommon and believe to be an issue with Xcode.

@dpogue dpogue marked this pull request as ready for review August 17, 2024 06:56
@dpogue dpogue merged commit 68aa80e into apache:master Aug 20, 2024
10 checks passed
@dpogue dpogue deleted the refactor2-template branch August 20, 2024 08:03
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.

MainViewController.m omit empty viewDidLoad to avoid warnings Any ideas to supports multiple windows?
3 participants