From 49cb61e1e54f6c8eb1253d2ffff1b858fdf69088 Mon Sep 17 00:00:00 2001 From: James Treanor Date: Fri, 5 Apr 2019 09:53:52 +0100 Subject: [PATCH] Add storyboards and xibs to the resource_bundle --- WordPressAuthenticator.podspec | 8 ++--- .../WordPressAuthenticator.swift | 35 +++++++++---------- .../Extensions/UIImage+Assets.swift | 2 +- .../NUX/NUXButtonViewController.swift | 2 +- .../Signin/LoginEmailViewController.swift | 2 +- .../LoginProloguePromoViewController.swift | 2 +- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/WordPressAuthenticator.podspec b/WordPressAuthenticator.podspec index 1b9ce244b..fe7c42e8e 100644 --- a/WordPressAuthenticator.podspec +++ b/WordPressAuthenticator.podspec @@ -19,14 +19,12 @@ Pod::Spec.new do |s| s.source_files = 'WordPressAuthenticator/**/*.{h,m,swift}' s.private_header_files = "WordPressAuthenticator/Private/*.h" s.resource_bundles = { - 'WordPressAuthenticatorResources': [ + 'WordPressAuthenticator': [ 'WordPressAuthenticator/Resources/Assets.xcassets', - 'WordPressAuthenticator/Resources/Animations/*.json' + 'WordPressAuthenticator/Resources/Animations/*.json', + 'WordPressAuthenticator/**/*.{storyboard,xib}' ] } - s.resources = [ - 'WordPressAuthenticator/**/*.{storyboard,xib}' - ] s.requires_arc = true s.static_framework = true # This is needed because GoogleSignIn vendors a static framework s.header_dir = 'WordPressAuthenticator' diff --git a/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift b/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift index b53d83a58..1bfbf2091 100644 --- a/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift +++ b/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift @@ -133,7 +133,7 @@ import WordPressUI trackOpenedLogin() } - let storyboard = UIStoryboard(name: "Login", bundle: mainBundle) + let storyboard = UIStoryboard(name: "Login", bundle: bundle) if let controller = storyboard.instantiateInitialViewController() { if let childController = controller.children.first as? LoginPrologueViewController { childController.loginFields.restrictToWPCom = restrictToWPCom @@ -149,7 +149,7 @@ import WordPressUI trackOpenedLogin() } - let storyboard = UIStoryboard(name: "Login", bundle: mainBundle) + let storyboard = UIStoryboard(name: "Login", bundle: bundle) guard let controller = storyboard.instantiateViewController(withIdentifier: "emailEntry") as? LoginEmailViewController else { return } @@ -183,7 +183,7 @@ import WordPressUI /// Returns an instance of LoginSiteAddressViewController: allows the user to log into a WordPress.org website. /// @objc public class func signinForWPOrg() -> UIViewController { - let storyboard = UIStoryboard(name: "Login", bundle: mainBundle) + let storyboard = UIStoryboard(name: "Login", bundle: bundle) guard let controller = storyboard.instantiateViewController(withIdentifier: "siteAddress") as? LoginSiteAddressViewController else { fatalError("unable to create wpcom password screen") } @@ -199,7 +199,7 @@ import WordPressUI loginFields.emailAddress = dotcomEmailAddress ?? String() loginFields.username = dotcomUsername ?? String() - let storyboard = UIStoryboard(name: "Login", bundle: mainBundle) + let storyboard = UIStoryboard(name: "Login", bundle: bundle) guard let controller = storyboard.instantiateViewController(withIdentifier: "LoginWPcomPassword") as? LoginWPComViewController else { fatalError("unable to create wpcom password screen") } @@ -215,7 +215,7 @@ import WordPressUI /// it's features. /// public class func signinForWPCom() -> LoginEmailViewController { - let storyboard = UIStoryboard(name: "Login", bundle: mainBundle) + let storyboard = UIStoryboard(name: "Login", bundle: bundle) guard let controller = storyboard.instantiateViewController(withIdentifier: "emailEntry") as? LoginEmailViewController else { fatalError() } @@ -256,7 +256,7 @@ import WordPressUI return false } - let storyboard = UIStoryboard(name: "EmailMagicLink", bundle: mainBundle) + let storyboard = UIStoryboard(name: "EmailMagicLink", bundle: bundle) guard let loginController = storyboard.instantiateViewController(withIdentifier: "LinkAuthView") as? NUXLinkAuthViewController else { DDLogInfo("App opened with authentication link but couldn't create login screen.") return false @@ -416,22 +416,19 @@ import WordPressUI UIApplication.shared.open(forgotPasswordURL) } - /// Returns the WordPressAuthenticator main bundle + /// Returns the WordPressAuthenticator Bundle + /// If installed via CocoaPods, this will be WordPressAuthenticator.bundle, + /// otherwise it will be the framework bundle. /// - class var mainBundle: Bundle { - return Bundle(for: WordPressAuthenticator.self) - } - - /// Returns the WordPressAuthenticatorResouces.bundle - /// - class var resourcesBundle: Bundle { - // If installed with CocoaPods, resources will be in WordPressAuthenticatorResources.bundle - if let bundleURL = mainBundle.resourceURL, - let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("WordPressAuthenticatorResources.bundle")) { + class var bundle: Bundle { + let defaultBundle = Bundle(for: WordPressAuthenticator.self) + // If installed with CocoaPods, resources will be in WordPressAuthenticator.bundle + if let bundleURL = defaultBundle.resourceURL, + let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("WordPressAuthenticator.bundle")) { return resourceBundle } - // Otherwise, the main bundle is used for resources - return mainBundle + // Otherwise, the default bundle is used for resources + return defaultBundle } // MARK: - 1Password Helper diff --git a/WordPressAuthenticator/Extensions/UIImage+Assets.swift b/WordPressAuthenticator/Extensions/UIImage+Assets.swift index 7a633a8c0..3f60f727b 100644 --- a/WordPressAuthenticator/Extensions/UIImage+Assets.swift +++ b/WordPressAuthenticator/Extensions/UIImage+Assets.swift @@ -29,6 +29,6 @@ extension UIImage { /// Returns WordPressAuthenticator's Bundle /// private static var bundle: Bundle { - return WordPressAuthenticator.resourcesBundle + return WordPressAuthenticator.bundle } } diff --git a/WordPressAuthenticator/NUX/NUXButtonViewController.swift b/WordPressAuthenticator/NUX/NUXButtonViewController.swift index 555c9e638..bce062d80 100644 --- a/WordPressAuthenticator/NUX/NUXButtonViewController.swift +++ b/WordPressAuthenticator/NUX/NUXButtonViewController.swift @@ -169,7 +169,7 @@ extension NUXButtonViewController { /// Returns a new NUXButtonViewController Instance /// public class func instance() -> NUXButtonViewController { - let storyboard = UIStoryboard(name: "NUXButtonView", bundle: WordPressAuthenticator.mainBundle) + let storyboard = UIStoryboard(name: "NUXButtonView", bundle: WordPressAuthenticator.bundle) guard let buttonViewController = storyboard.instantiateViewController(withIdentifier: "ButtonView") as? NUXButtonViewController else { fatalError() } diff --git a/WordPressAuthenticator/Signin/LoginEmailViewController.swift b/WordPressAuthenticator/Signin/LoginEmailViewController.swift index fca8f2f2d..db4c00bfb 100644 --- a/WordPressAuthenticator/Signin/LoginEmailViewController.swift +++ b/WordPressAuthenticator/Signin/LoginEmailViewController.swift @@ -607,7 +607,7 @@ extension LoginEmailViewController: LoginSocialErrorViewControllerDelegate { cleanupAfterSocialErrors() - let storyboard = UIStoryboard(name: "Signup", bundle: WordPressAuthenticator.mainBundle) + let storyboard = UIStoryboard(name: "Signup", bundle: WordPressAuthenticator.bundle) if let controller = storyboard.instantiateViewController(withIdentifier: "emailEntry") as? SignupEmailViewController { controller.loginFields = loginFields navigationController?.pushViewController(controller, animated: true) diff --git a/WordPressAuthenticator/Signin/LoginProloguePromoViewController.swift b/WordPressAuthenticator/Signin/LoginProloguePromoViewController.swift index e3c521f02..bfefb4aa8 100644 --- a/WordPressAuthenticator/Signin/LoginProloguePromoViewController.swift +++ b/WordPressAuthenticator/Signin/LoginProloguePromoViewController.swift @@ -61,7 +61,7 @@ class LoginProloguePromoViewController: UIViewController { headingLabel = UILabel() animationHolder = UIView() - let bundle = WordPressAuthenticator.resourcesBundle + let bundle = WordPressAuthenticator.bundle animationView = LOTAnimationView(name: type.animationKey, bundle: bundle) super.init(nibName: nil, bundle: nil)