diff --git a/Podfile b/Podfile index e77e57816..1a7fbdfe8 100644 --- a/Podfile +++ b/Podfile @@ -9,21 +9,22 @@ def wordpress_authenticator_pods ## Automattic libraries ## ==================== ## - pod 'Gridicons', '~> 0.15' - pod 'WordPressUI', '~> 1.4-beta.1' - pod 'WordPressKit', '~> 4.5.9-beta' - # pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => 'issue/apple_2fa_auth' - pod 'WordPressShared', '~> 1.8.13' + pod 'Gridicons', '~> 1.0' + pod 'WordPressUI', '~> 1.5.2' + pod 'WordPressKit', '~> 4.6.0' + #pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => '' + #pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :commit => '' + pod 'WordPressShared', '~> 1.8.16' ## Third party libraries ## ===================== ## - pod '1PasswordExtension', '1.8.5' + pod '1PasswordExtension', '1.8.6' pod 'Alamofire', '4.8' pod 'CocoaLumberjack', '3.5.2' pod 'GoogleSignIn', '4.4.0' - pod 'lottie-ios', '2.5.2' - pod 'NSURL+IDN', '0.3' + pod 'lottie-ios', '3.1.6' + pod 'NSURL+IDN', '0.4' pod 'SVProgressHUD', '2.2.5' end diff --git a/Podfile.lock b/Podfile.lock index 39d448c38..e936f6971 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - 1PasswordExtension (1.8.5) + - 1PasswordExtension (1.8.6) - Alamofire (4.8.0) - CocoaLumberjack (3.5.2): - CocoaLumberjack/Core (= 3.5.2) @@ -12,20 +12,20 @@ PODS: - "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)" - "GoogleToolboxForMac/NSString+URLArguments (~> 2.1)" - GTMSessionFetcher/Core (~> 1.1) - - GoogleToolboxForMac/DebugUtils (2.2.1): - - GoogleToolboxForMac/Defines (= 2.2.1) - - GoogleToolboxForMac/Defines (2.2.1) - - "GoogleToolboxForMac/NSDictionary+URLArguments (2.2.1)": - - GoogleToolboxForMac/DebugUtils (= 2.2.1) - - GoogleToolboxForMac/Defines (= 2.2.1) - - "GoogleToolboxForMac/NSString+URLArguments (= 2.2.1)" - - "GoogleToolboxForMac/NSString+URLArguments (2.2.1)" - - Gridicons (0.19) - - GTMSessionFetcher/Core (1.2.2) - - lottie-ios (2.5.2) - - NSObject-SafeExpectations (0.0.3) - - "NSURL+IDN (0.3)" - - OCMock (3.4.3) + - GoogleToolboxForMac/DebugUtils (2.2.2): + - GoogleToolboxForMac/Defines (= 2.2.2) + - GoogleToolboxForMac/Defines (2.2.2) + - "GoogleToolboxForMac/NSDictionary+URLArguments (2.2.2)": + - GoogleToolboxForMac/DebugUtils (= 2.2.2) + - GoogleToolboxForMac/Defines (= 2.2.2) + - "GoogleToolboxForMac/NSString+URLArguments (= 2.2.2)" + - "GoogleToolboxForMac/NSString+URLArguments (2.2.2)" + - Gridicons (1.0) + - GTMSessionFetcher/Core (1.3.1) + - lottie-ios (3.1.6) + - NSObject-SafeExpectations (0.0.4) + - "NSURL+IDN (0.4)" + - OCMock (3.6) - OHHTTPStubs (8.0.0): - OHHTTPStubs/Default (= 8.0.0) - OHHTTPStubs/Core (8.0.0) @@ -44,36 +44,36 @@ PODS: - Specta (1.0.7) - SVProgressHUD (2.2.5) - UIDeviceIdentifier (1.4.0) - - WordPressKit (4.5.9-beta.2): + - WordPressKit (4.6.0): - Alamofire (~> 4.8.0) - CocoaLumberjack (~> 3.4) - - NSObject-SafeExpectations (= 0.0.3) + - NSObject-SafeExpectations (= 0.0.4) - UIDeviceIdentifier (~> 1) - - WordPressShared (~> 1.8.13-beta) - - wpxmlrpc (= 0.8.4) - - WordPressShared (1.8.13): + - WordPressShared (~> 1.8.16) + - wpxmlrpc (= 0.8.5) + - WordPressShared (1.8.16): - CocoaLumberjack (~> 3.4) - FormatterKit/TimeIntervalFormatter (= 1.8.2) - - WordPressUI (1.4-beta.1) - - wpxmlrpc (0.8.4) + - WordPressUI (1.5.2) + - wpxmlrpc (0.8.5) DEPENDENCIES: - - 1PasswordExtension (= 1.8.5) + - 1PasswordExtension (= 1.8.6) - Alamofire (= 4.8) - CocoaLumberjack (= 3.5.2) - Expecta (= 1.0.6) - GoogleSignIn (= 4.4.0) - - Gridicons (~> 0.15) - - lottie-ios (= 2.5.2) - - "NSURL+IDN (= 0.3)" + - Gridicons (~> 1.0) + - lottie-ios (= 3.1.6) + - "NSURL+IDN (= 0.4)" - OCMock (~> 3.4) - OHHTTPStubs (= 8.0.0) - OHHTTPStubs/Swift (= 8.0.0) - Specta (= 1.0.7) - SVProgressHUD (= 2.2.5) - - WordPressKit (~> 4.5.9-beta) - - WordPressShared (~> 1.8.13) - - WordPressUI (~> 1.4-beta.1) + - WordPressKit (~> 4.6.0) + - WordPressShared (~> 1.8.16) + - WordPressUI (~> 1.5.2) SPEC REPOS: trunk: @@ -100,28 +100,28 @@ SPEC REPOS: - wpxmlrpc SPEC CHECKSUMS: - 1PasswordExtension: 0e95bdea64ec8ff2f4f693be5467a09fac42a83d + 1PasswordExtension: f97cc80ae58053c331b2b6dc8843ba7103b33794 Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844 CocoaLumberjack: 118bf4a820efc641f79fa487b75ed928dccfae23 Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5 FormatterKit: 4b8f29acc9b872d5d12a63efb560661e8f2e1b98 GoogleSignIn: 7ff245e1a7b26d379099d3243a562f5747e23d39 - GoogleToolboxForMac: b3553629623a3b1bff17f555e736cd5a6d95ad55 - Gridicons: dc92efbe5fd60111d2e8ea051d84a60cca552abc - GTMSessionFetcher: 61bb0f61a4cb560030f1222021178008a5727a23 - lottie-ios: 3fef45d3fabe63e3c7c2eb603dd64ddfffc73062 - NSObject-SafeExpectations: b989b68a8a9b7b9f2b264a8b52ba9d7aab8f3129 - "NSURL+IDN": 82355a0afd532fe1de08f6417c134b49b1a1c4b3 - OCMock: 43565190abc78977ad44a61c0d20d7f0784d35ab + GoogleToolboxForMac: 800648f8b3127618c1b59c7f97684427630c5ea3 + Gridicons: f032dbc3350f8648e0fabe3e531b72cf97d428a9 + GTMSessionFetcher: cea130bbfe5a7edc8d06d3f0d17288c32ffe9925 + lottie-ios: 85ce835dd8c53e02509f20729fc7d6a4e6645a0a + NSObject-SafeExpectations: ab8fe623d36b25aa1f150affa324e40a2f3c0374 + "NSURL+IDN": afc873e639c18138a1589697c3add197fe8679ca + OCMock: 5ea90566be239f179ba766fd9fbae5885040b992 OHHTTPStubs: 9cbce6364bec557cc3439aa6bb7514670d780881 Specta: 3e1bd89c3517421982dc4d1c992503e48bd5fe66 SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6 UIDeviceIdentifier: 44f805037d21b94394821828f4fcaba34b38c2d0 - WordPressKit: 54b1c041c59b871e91a331f24a2fb5d347e070b0 - WordPressShared: fde9523bd00696fc1dfa45ed5299e16de111ebcc - WordPressUI: 35b144885c8e5817ba6874b68accc200bda61ee1 - wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2 + WordPressKit: 767cc17ae08894f73f08c852fe124c865a62fb3d + WordPressShared: 1bc316ed162f42af4e0fa2869437e9e28b532b01 + WordPressUI: 70cc58a253c352330b23cd8fa6dd6a2021570e18 + wpxmlrpc: 6a9bdd6ab9d1b159b384b0df0f3f39de9af4fecf -PODFILE CHECKSUM: c8429d9d1b129c0d3f037b246b2a63567bf0f654 +PODFILE CHECKSUM: 0c5d1d0787a9afe633ecb5f3e47cde5666a6d0c7 COCOAPODS: 1.8.4 diff --git a/WordPressAuthenticator.podspec b/WordPressAuthenticator.podspec index 6db6ce552..b5e439ca1 100644 --- a/WordPressAuthenticator.podspec +++ b/WordPressAuthenticator.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressAuthenticator" - s.version = "1.10.9" + s.version = "1.11.0" s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps." s.description = <<-DESC @@ -30,16 +30,16 @@ Pod::Spec.new do |s| s.static_framework = true # This is needed because GoogleSignIn vendors a static framework s.header_dir = 'WordPressAuthenticator' - s.dependency '1PasswordExtension', '1.8.5' + s.dependency '1PasswordExtension', '1.8.6' s.dependency 'Alamofire', '4.8' s.dependency 'CocoaLumberjack', '~> 3.5' - s.dependency 'lottie-ios', '2.5.2' - s.dependency 'NSURL+IDN', '0.3' + s.dependency 'lottie-ios', '3.1.6' + s.dependency 'NSURL+IDN', '0.4' s.dependency 'SVProgressHUD', '2.2.5' - s.dependency 'Gridicons', '~> 0.15' + s.dependency 'Gridicons', '~> 1.0' s.dependency 'GoogleSignIn', '~> 4.4' - s.dependency 'WordPressUI', '~> 1.4-beta.1' - s.dependency 'WordPressKit', '~> 4.5.9-beta' - s.dependency 'WordPressShared', '~> 1.8.13-beta' + s.dependency 'WordPressUI', '~> 1.5.2' + s.dependency 'WordPressKit', '~> 4.6.0' + s.dependency 'WordPressShared', '~> 1.8.16' end diff --git a/WordPressAuthenticator.xcodeproj/project.pbxproj b/WordPressAuthenticator.xcodeproj/project.pbxproj index 1dde45a37..80f991899 100644 --- a/WordPressAuthenticator.xcodeproj/project.pbxproj +++ b/WordPressAuthenticator.xcodeproj/project.pbxproj @@ -116,6 +116,9 @@ CE30A2A722579F4100DF3CDA /* LoginUsernamePasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE30A2A622579F4100DF3CDA /* LoginUsernamePasswordViewController.swift */; }; CE30A2A92257C60500DF3CDA /* WordPressOrgCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE30A2A82257C60500DF3CDA /* WordPressOrgCredentials.swift */; }; CE30A2AD2257CECC00DF3CDA /* AuthenticatorCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE30A2AC2257CECC00DF3CDA /* AuthenticatorCredentials.swift */; }; + CEDE0D93242011E000CB3345 /* NSObject+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDE0D92242011E000CB3345 /* NSObject+Helpers.swift */; }; + CEDE0D952420121D00CB3345 /* UIStoryboard+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDE0D942420121D00CB3345 /* UIStoryboard+Helpers.swift */; }; + CEDE0D972420126900CB3345 /* UIViewController+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDE0D962420126900CB3345 /* UIViewController+Helpers.swift */; }; E8AF6B9EF50902F2117DFAF9 /* Pods_WordPressAuthenticatorTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A441EC80D2B8D2209C2E228 /* Pods_WordPressAuthenticatorTests.framework */; }; FF629D9622393500004C4106 /* WordPressAuthenticator.podspec in Resources */ = {isa = PBXBuildFile; fileRef = FF629D9522393500004C4106 /* WordPressAuthenticator.podspec */; }; /* End PBXBuildFile section */ @@ -270,6 +273,9 @@ CE30A2A622579F4100DF3CDA /* LoginUsernamePasswordViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginUsernamePasswordViewController.swift; sourceTree = ""; }; CE30A2A82257C60500DF3CDA /* WordPressOrgCredentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordPressOrgCredentials.swift; sourceTree = ""; }; CE30A2AC2257CECC00DF3CDA /* AuthenticatorCredentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticatorCredentials.swift; sourceTree = ""; }; + CEDE0D92242011E000CB3345 /* NSObject+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSObject+Helpers.swift"; sourceTree = ""; }; + CEDE0D942420121D00CB3345 /* UIStoryboard+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStoryboard+Helpers.swift"; sourceTree = ""; }; + CEDE0D962420126900CB3345 /* UIViewController+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Helpers.swift"; sourceTree = ""; }; E9414A95E29F3297555AC92B /* Pods-WordPressAuthenticator.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressAuthenticator.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WordPressAuthenticator/Pods-WordPressAuthenticator.debug.xcconfig"; sourceTree = ""; }; FF475C5056EB60A277696BA9 /* Pods-WordPressAuthenticatorTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressAuthenticatorTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-WordPressAuthenticatorTests/Pods-WordPressAuthenticatorTests.release.xcconfig"; sourceTree = ""; }; FF629D9522393500004C4106 /* WordPressAuthenticator.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WordPressAuthenticator.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; @@ -511,6 +517,9 @@ B56090EE208A527000399AE4 /* String+Underline.swift */, B56090EC208A527000399AE4 /* WPStyleGuide+Login.swift */, B5CDBED320B4714500BC1EF2 /* UIImage+Assets.swift */, + CEDE0D92242011E000CB3345 /* NSObject+Helpers.swift */, + CEDE0D942420121D00CB3345 /* UIStoryboard+Helpers.swift */, + CEDE0D962420126900CB3345 /* UIViewController+Helpers.swift */, ); path = Extensions; sourceTree = ""; @@ -918,10 +927,12 @@ B56090E2208A4F9D00399AE4 /* WPNUXSecondaryButton.m in Sources */, B56090E6208A4F9D00399AE4 /* WPNUXPrimaryButton.m in Sources */, B5609135208A563800399AE4 /* LoginWPComViewController.swift in Sources */, + CEDE0D972420126900CB3345 /* UIViewController+Helpers.swift in Sources */, B5609119208A555600399AE4 /* SiteInfoHeaderView.swift in Sources */, B560913E208A563800399AE4 /* SigninEditingState.swift in Sources */, B56090CF208A4F5400399AE4 /* NUXCollectionViewController.swift in Sources */, 1A21EE9822832BC300C940C6 /* WordPressComOAuthClientFacade+Swift.swift in Sources */, + CEDE0D952420121D00CB3345 /* UIStoryboard+Helpers.swift in Sources */, B5ED7920207E993E00A8FD8C /* WPAuthenticatorLogging.m in Sources */, B5609138208A563800399AE4 /* LoginSiteAddressViewController.swift in Sources */, B560910B208A54F800399AE4 /* LoginFacade.m in Sources */, @@ -931,6 +942,7 @@ 3F550D5323DA4AC6007E5897 /* URLHandler.swift in Sources */, 98C9195B2308E3DA00A90E12 /* AppleAuthenticator.swift in Sources */, B56090F9208A533200399AE4 /* WordPressAuthenticator+Events.swift in Sources */, + CEDE0D93242011E000CB3345 /* NSObject+Helpers.swift in Sources */, 020BE74A23B0BD2E007FE54C /* WordPressAuthenticatorDisplayImages.swift in Sources */, B560913A208A563800399AE4 /* LoginLinkRequestViewController.swift in Sources */, B560910C208A54F800399AE4 /* WordPressComOAuthClientFacade.m in Sources */, diff --git a/WordPressAuthenticator.xcodeproj/xcshareddata/xcschemes/WordPressAuthenticator.xcscheme b/WordPressAuthenticator.xcodeproj/xcshareddata/xcschemes/WordPressAuthenticator.xcscheme index 0182e3af4..3941b57e6 100644 --- a/WordPressAuthenticator.xcodeproj/xcshareddata/xcschemes/WordPressAuthenticator.xcscheme +++ b/WordPressAuthenticator.xcodeproj/xcshareddata/xcschemes/WordPressAuthenticator.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -39,17 +48,6 @@ - - - - - - - - LoginEmailViewController { - let storyboard = UIStoryboard(name: "Login", bundle: bundle) - guard let controller = storyboard.instantiateViewController(withIdentifier: "emailEntry") as? LoginEmailViewController else { + guard let controller = LoginEmailViewController.instantiate(from: .login) else { fatalError() } diff --git a/WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift b/WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift index 40db2cd96..f9d0edfd3 100644 --- a/WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift +++ b/WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift @@ -59,6 +59,9 @@ public struct WordPressAuthenticatorStyle { public let textFieldBackgroundColor: UIColor + // If not specified, falls back to viewControllerBackgroundColor. + public let buttonViewBackgroundColor: UIColor + /// Style: nav bar /// public let navBarImage: UIImage @@ -79,7 +82,7 @@ public struct WordPressAuthenticatorStyle { /// Designated initializer /// - public init(primaryNormalBackgroundColor: UIColor, primaryNormalBorderColor: UIColor?, primaryHighlightBackgroundColor: UIColor, primaryHighlightBorderColor: UIColor?, secondaryNormalBackgroundColor: UIColor, secondaryNormalBorderColor: UIColor, secondaryHighlightBackgroundColor: UIColor, secondaryHighlightBorderColor: UIColor, disabledBackgroundColor: UIColor, disabledBorderColor: UIColor, primaryTitleColor: UIColor, secondaryTitleColor: UIColor, disabledTitleColor: UIColor, textButtonColor: UIColor, textButtonHighlightColor: UIColor, instructionColor: UIColor, subheadlineColor: UIColor, placeholderColor: UIColor, viewControllerBackgroundColor: UIColor, textFieldBackgroundColor: UIColor, navBarImage: UIImage, navBarBadgeColor: UIColor, prologueBackgroundColor: UIColor = WPStyleGuide.wordPressBlue(), prologueTitleColor: UIColor = .white, statusBarStyle: UIStatusBarStyle = .lightContent) { + public init(primaryNormalBackgroundColor: UIColor, primaryNormalBorderColor: UIColor?, primaryHighlightBackgroundColor: UIColor, primaryHighlightBorderColor: UIColor?, secondaryNormalBackgroundColor: UIColor, secondaryNormalBorderColor: UIColor, secondaryHighlightBackgroundColor: UIColor, secondaryHighlightBorderColor: UIColor, disabledBackgroundColor: UIColor, disabledBorderColor: UIColor, primaryTitleColor: UIColor, secondaryTitleColor: UIColor, disabledTitleColor: UIColor, textButtonColor: UIColor, textButtonHighlightColor: UIColor, instructionColor: UIColor, subheadlineColor: UIColor, placeholderColor: UIColor, viewControllerBackgroundColor: UIColor, textFieldBackgroundColor: UIColor, buttonViewBackgroundColor: UIColor? = nil, navBarImage: UIImage, navBarBadgeColor: UIColor, prologueBackgroundColor: UIColor = WPStyleGuide.wordPressBlue(), prologueTitleColor: UIColor = .white, statusBarStyle: UIStatusBarStyle = .lightContent) { self.primaryNormalBackgroundColor = primaryNormalBackgroundColor self.primaryNormalBorderColor = primaryNormalBorderColor self.primaryHighlightBackgroundColor = primaryHighlightBackgroundColor @@ -100,6 +103,7 @@ public struct WordPressAuthenticatorStyle { self.placeholderColor = placeholderColor self.viewControllerBackgroundColor = viewControllerBackgroundColor self.textFieldBackgroundColor = textFieldBackgroundColor + self.buttonViewBackgroundColor = buttonViewBackgroundColor ?? viewControllerBackgroundColor self.navBarImage = navBarImage self.navBarBadgeColor = navBarBadgeColor self.prologueBackgroundColor = prologueBackgroundColor diff --git a/WordPressAuthenticator/Extensions/NSObject+Helpers.swift b/WordPressAuthenticator/Extensions/NSObject+Helpers.swift new file mode 100644 index 000000000..5c0bb9298 --- /dev/null +++ b/WordPressAuthenticator/Extensions/NSObject+Helpers.swift @@ -0,0 +1,14 @@ + +import Foundation + + +// MARK - NSObject Helper Methods +// +extension NSObject { + + /// Returns the receiver's classname as a string, not including the namespace. + /// + class var classNameWithoutNamespaces: String { + return String(describing: self) + } +} diff --git a/WordPressAuthenticator/Extensions/UIImage+Assets.swift b/WordPressAuthenticator/Extensions/UIImage+Assets.swift index 09450628d..7d15c785a 100644 --- a/WordPressAuthenticator/Extensions/UIImage+Assets.swift +++ b/WordPressAuthenticator/Extensions/UIImage+Assets.swift @@ -7,34 +7,49 @@ extension UIImage { /// Returns the Link Image. /// static var linkFieldImage: UIImage { - return UIImage(named: "icon-url-field", in: bundle, compatibleWith: nil)! + return UIImage(named: "icon-url-field", in: bundle, compatibleWith: nil) ?? UIImage() } /// Returns the Default Magic Link Image. /// static var magicLinkImage: UIImage { - return UIImage(named: "login-magic-link", in: bundle, compatibleWith: nil)! + return UIImage(named: "login-magic-link", in: bundle, compatibleWith: nil) ?? UIImage() } /// Returns the Default Site Icon Placeholder Image. /// @objc public static var siteAddressModalPlaceholder: UIImage { - return UIImage(named: "site-address", in: bundle, compatibleWith: nil)! + return UIImage(named: "site-address", in: bundle, compatibleWith: nil) ?? UIImage() } /// Returns the Default Gravatar Placeholder Image. /// @objc public static var onePasswordImage: UIImage { - return UIImage(named: "onepassword-button", in: bundle, compatibleWith: nil)! + return UIImage(named: "onepassword-button", in: bundle, compatibleWith: nil) ?? UIImage() } /// Returns the Link Image. /// @objc public static var googleIcon: UIImage { - return UIImage(named: "google", in: bundle, compatibleWith: nil)! + return UIImage(named: "google", in: bundle, compatibleWith: nil) ?? UIImage() + } + + /// Returns the Apple Logo Image. + /// + public static var appleIcon: UIImage { + + let imageName: String = { + if #available(iOS 13, *) { + return UITraitCollection.current.userInterfaceStyle == .dark ? "apple-white" : "apple-black" + } + + return "apple-black" + }() + + return UIImage(named: imageName, in: bundle, compatibleWith: nil) ?? UIImage() } /// Returns WordPressAuthenticator's Bundle diff --git a/WordPressAuthenticator/Extensions/UIStoryboard+Helpers.swift b/WordPressAuthenticator/Extensions/UIStoryboard+Helpers.swift new file mode 100644 index 000000000..bf17b5b1d --- /dev/null +++ b/WordPressAuthenticator/Extensions/UIStoryboard+Helpers.swift @@ -0,0 +1,20 @@ +import Foundation + + +// MARK - Storyboard enum +enum Storyboard: String { + case login + case signup + + var instance: UIStoryboard { + return UIStoryboard(name: self.rawValue.capitalized, bundle: WordPressAuthenticator.bundle) + } + + /// Returns a view controller from a Storyboard + /// assuming the identifier is the same as the class name. + /// + func instantiateViewController(ofClass classType: T.Type) -> T? { + let identifier = classType.classNameWithoutNamespaces + return instance.instantiateViewController(withIdentifier: identifier) as? T + } +} diff --git a/WordPressAuthenticator/Extensions/UIViewController+Helpers.swift b/WordPressAuthenticator/Extensions/UIViewController+Helpers.swift new file mode 100644 index 000000000..a8c0df46c --- /dev/null +++ b/WordPressAuthenticator/Extensions/UIViewController+Helpers.swift @@ -0,0 +1,12 @@ +import Foundation + + +// MARK - UIViewController Helpers +extension UIViewController { + + /// Convenience method to instantiate a view controller from a storyboard. + /// + static func instantiate(from storyboard: Storyboard) -> Self? { + return storyboard.instantiateViewController(ofClass: self) + } +} diff --git a/WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift b/WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift index 73e105674..cc3186f86 100644 --- a/WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift +++ b/WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift @@ -17,11 +17,10 @@ final class SubheadlineButton: UIButton { extension WPStyleGuide { private struct Constants { - // This matches the button height in NUXButtonView.storyboard - static let buttonMinHeight: CGFloat = 50.0 - static let textButtonMinHeight: CGFloat = 40.0 static let googleIconOffset: CGFloat = -1.0 + static let googleIconButtonSize: CGFloat = 15.0 + static let appleIconSizeModifier: CGFloat = 0.66 static let domainsIconPaddingToRemove: CGFloat = 2.0 static let domainsIconSize = CGSize(width: 18, height: 18) static let verticalLabelSpacing: CGFloat = 10.0 @@ -111,7 +110,7 @@ extension WPStyleGuide { // MARK: - Login Button Methods - /// Creates a button for Google Sign-in + /// Creates a button for Google Sign-in with hyperlink style. /// /// - Returns: A properly styled UIButton /// @@ -126,23 +125,62 @@ extension WPStyleGuide { return textButton(normal: attrStrNormal, highlighted: attrStrHighlight, font: font) } - /// Creates a button for Apple Sign-in + /// Creates an attributed string that includes the Google logo. /// - /// - Returns: A properly styled UIControl + /// - Parameters: + /// - forHyperlink: Indicates if the string will be displayed in a hyperlink. + /// Otherwise, it will be styled to be displayed on a NUXButton. + /// - Returns: A properly styled NSAttributedString /// - - class func appleLoginButton() -> UIControl { - if #available(iOS 13.0, *) { - let traits = UITraitCollection.current - let buttonStyle: ASAuthorizationAppleIDButton.Style = (traits.userInterfaceStyle == .dark) ? .white : .black - - let appleButton = ASAuthorizationAppleIDButton(authorizationButtonType: .continue, authorizationButtonStyle: buttonStyle) - appleButton.translatesAutoresizingMaskIntoConstraints = false - appleButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonMinHeight).isActive = true - return appleButton + class func formattedGoogleString(forHyperlink: Bool = false) -> NSAttributedString { + + let googleAttachment = NSTextAttachment() + let googleIcon = UIImage.googleIcon + googleAttachment.image = googleIcon + + if forHyperlink { + // Create an attributed string that contains the Google icon. + let font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) + googleAttachment.bounds = CGRect(x: 0, + y: font.descender + Constants.googleIconOffset, + width: googleIcon.size.width, + height: googleIcon.size.height) + + return NSAttributedString(attachment: googleAttachment) + } else { + // Create an attributed string that contains the Google icon + button text. + googleAttachment.bounds = CGRect(x: 0, y: (NUXButton.titleFont.capHeight - Constants.googleIconButtonSize) / 2, + width: Constants.googleIconButtonSize, height: Constants.googleIconButtonSize) + + let buttonString = NSMutableAttributedString(attachment: googleAttachment) + let googleTitle = NSLocalizedString(" Continue with Google", comment: "Button title. Tapping begins log in using Google. There are leading spaces to separate it from the Google logo.") + buttonString.append(NSAttributedString(string: googleTitle)) + + return buttonString } + } + + /// Creates an attributed string that includes the Apple logo. + /// + /// - Returns: A properly styled NSAttributedString to be displayed on a NUXButton. + /// + class func formattedAppleString() -> NSAttributedString { + + let appleAttachment = NSTextAttachment() + let appleIcon = UIImage.appleIcon + appleAttachment.image = appleIcon - return UIControl() + let imageSize = CGSize(width: appleIcon.size.width * Constants.appleIconSizeModifier, + height: appleIcon.size.height * Constants.appleIconSizeModifier) + + appleAttachment.bounds = CGRect(x: 0, y: floor((NUXButton.titleFont.capHeight - imageSize.height) / 2), + width: imageSize.width, height: imageSize.height) + + let buttonString = NSMutableAttributedString(attachment: appleAttachment) + let appleTitle = NSLocalizedString(" Continue with Apple", comment: "Button title. Tapping begins log in using Apple. There is a leading space to separate it from the Apple logo.") + buttonString.append(NSAttributedString(string: appleTitle)) + + return buttonString } /// Creates a button for Self-hosted Login @@ -184,10 +222,10 @@ extension WPStyleGuide { /// - Note: This button is only used during Jetpack setup, not the usual flows /// class func wpcomSignupButton() -> UIButton { + let style = WordPressAuthenticator.shared.style let baseString = NSLocalizedString("Don't have an account? _Sign up_", comment: "Label for button to log in using your site address. The underscores _..._ denote underline") - let attrStrNormal = baseString.underlined(color: WPStyleGuide.greyDarken20(), underlineColor: WPStyleGuide.wordPressBlue()) - let attrStrHighlight = baseString.underlined(color: WPStyleGuide.greyDarken20(), underlineColor: WPStyleGuide.lightBlue()) - + let attrStrNormal = baseString.underlined(color: style.subheadlineColor, underlineColor: style.textButtonColor) + let attrStrHighlight = baseString.underlined(color: style.subheadlineColor, underlineColor: style.textButtonHighlightColor) let font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) return textButton(normal: attrStrNormal, highlighted: attrStrHighlight, font: font) @@ -235,7 +273,6 @@ extension WPStyleGuide { private class func googleButtonString(_ baseString: String, linkColor: UIColor) -> NSAttributedString { let labelParts = baseString.components(separatedBy: "{G}") - let font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) let firstPart = labelParts[0] // 👇 don't want to crash when a translation lacks "{G}" @@ -244,12 +281,7 @@ extension WPStyleGuide { let labelString = NSMutableAttributedString(string: firstPart, attributes: [.foregroundColor: WPStyleGuide.greyDarken30()]) if lastPart != "" { - let googleIcon = UIImage.googleIcon - let googleAttachment = NSTextAttachment() - googleAttachment.image = googleIcon - googleAttachment.bounds = CGRect(x: 0.0, y: font.descender + Constants.googleIconOffset, width: googleIcon.size.width, height: googleIcon.size.height) - let iconString = NSAttributedString(attachment: googleAttachment) - labelString.append(iconString) + labelString.append(formattedGoogleString(forHyperlink: true)) } labelString.append(NSAttributedString(string: lastPart, attributes: [.foregroundColor: linkColor])) @@ -265,7 +297,7 @@ extension WPStyleGuide { let labelString = NSMutableAttributedString(string: "") - if let originalDomainsIcon = Gridicon.iconOfType(.domains).imageWithTintColor(WordPressAuthenticator.shared.style.placeholderColor) { + if let originalDomainsIcon = UIImage.gridicon(.domains).imageWithTintColor(WordPressAuthenticator.shared.style.placeholderColor) { var domainsIcon = originalDomainsIcon.cropping(to: CGRect(x: Constants.domainsIconPaddingToRemove, y: Constants.domainsIconPaddingToRemove, width: originalDomainsIcon.size.width - Constants.domainsIconPaddingToRemove * 2, diff --git a/WordPressAuthenticator/NUX/NUXButton.swift b/WordPressAuthenticator/NUX/NUXButton.swift index 8a0d52927..01451f107 100644 --- a/WordPressAuthenticator/NUX/NUXButton.swift +++ b/WordPressAuthenticator/NUX/NUXButton.swift @@ -1,6 +1,7 @@ import UIKit import WordPressShared import WordPressUI +import WordPressKit /// A stylized button used by Login controllers. It also can display a `UIActivityIndicatorView`. @objc open class NUXButton: UIButton { @@ -28,6 +29,8 @@ import WordPressUI return indicator }() + static let titleFont = WPStyleGuide.mediumWeightFont(forStyle: .title3) + override open func layoutSubviews() { super.layoutSubviews() @@ -41,6 +44,18 @@ import WordPressUI } } + open override func tintColorDidChange() { + // Update colors when toggling light/dark mode. + super.tintColorDidChange() + configureBackgrounds() + configureTitleColors() + + if socialService == .apple { + setAttributedTitle(WPStyleGuide.formattedAppleString(), for: .normal) + } + } + + // MARK: - Instance Methods @@ -71,6 +86,7 @@ import WordPressUI } } + var socialService: SocialServiceName? // MARK: - LifeCycle Methods @@ -95,18 +111,11 @@ import WordPressUI /// Setup: Everything = [Insets, Backgrounds, titleColor(s), titleLabel] /// private func configureAppearance() { - configureInsets() configureBackgrounds() configureTitleColors() configureTitleLabel() } - /// Setup: NUXButton's Default Settings - /// - private func configureInsets() { - contentEdgeInsets = UIImage.DefaultRenderMetrics.contentInsets - } - /// Setup: BackgroundImage /// private func configureBackgrounds() { @@ -142,7 +151,7 @@ import WordPressUI /// Setup: TitleLabel /// private func configureTitleLabel() { - titleLabel?.font = WPFontManager.systemSemiBoldFont(ofSize: 17.0) + titleLabel?.font = NUXButton.titleFont titleLabel?.adjustsFontForContentSizeCategory = true titleLabel?.textAlignment = .center } @@ -157,8 +166,4 @@ extension NUXButton { didChangePreferredContentSize() } } - - private struct Metrics { - static let maxFontSize = CGFloat(22) - } } diff --git a/WordPressAuthenticator/NUX/NUXButtonView.storyboard b/WordPressAuthenticator/NUX/NUXButtonView.storyboard index b31af762b..1a8e7cb8d 100644 --- a/WordPressAuthenticator/NUX/NUXButtonView.storyboard +++ b/WordPressAuthenticator/NUX/NUXButtonView.storyboard @@ -1,11 +1,9 @@ - - - - + + - + @@ -14,8 +12,8 @@ - - + + @@ -24,14 +22,14 @@ - - + + - - - - + @@ -207,11 +205,11 @@ - - + + - + - + - + @@ -393,39 +391,39 @@ - + - + - + - + - + - + - + - + @@ -489,7 +487,7 @@ - +