From 2cf2e37f8e7db4c2a1140a6c4f5ec02c48d1653e Mon Sep 17 00:00:00 2001 From: aerych Date: Thu, 19 Oct 2017 14:45:39 -0500 Subject: [PATCH 1/8] Login: Renames file. --- ...WPStyleGuide+NUX.swift => WPStyleGuide+Login.swift} | 0 WordPress/WordPress.xcodeproj/project.pbxproj | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) rename WordPress/Classes/ViewRelated/NUX/{WPStyleGuide+NUX.swift => WPStyleGuide+Login.swift} (100%) diff --git a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+NUX.swift b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift similarity index 100% rename from WordPress/Classes/ViewRelated/NUX/WPStyleGuide+NUX.swift rename to WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 6cf85d6d1f3f..992b921e4a42 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -857,7 +857,7 @@ E63BBC961C5168BE00598BE8 /* SharingAuthorizationHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E63BBC951C5168BE00598BE8 /* SharingAuthorizationHelper.m */; }; E63C89741CB99A8500649C8F /* SigninHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63C89731CB99A8500649C8F /* SigninHelperTests.swift */; }; E63C897C1CB9A0D700649C8F /* UITextFieldTextHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63C897B1CB9A0D700649C8F /* UITextFieldTextHelperTests.swift */; }; - E6417B991CA07B9C0084050A /* WPStyleGuide+NUX.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6417B981CA07B9C0084050A /* WPStyleGuide+NUX.swift */; }; + E6417B991CA07B9C0084050A /* WPStyleGuide+Login.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6417B981CA07B9C0084050A /* WPStyleGuide+Login.swift */; }; E6417B9C1CA07C3C0084050A /* NUXAbstractViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6417B9B1CA07C3C0084050A /* NUXAbstractViewController.swift */; }; E6417BAC1CA07F7F0084050A /* SigninHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6417BAB1CA07F7F0084050A /* SigninHelpers.swift */; }; E6431DE51C4E892900FD8D90 /* SharingConnectionsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E6431DE01C4E892900FD8D90 /* SharingConnectionsViewController.m */; }; @@ -2282,7 +2282,7 @@ E63C89731CB99A8500649C8F /* SigninHelperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SigninHelperTests.swift; sourceTree = ""; }; E63C897B1CB9A0D700649C8F /* UITextFieldTextHelperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextFieldTextHelperTests.swift; sourceTree = ""; }; E63FF0581C5C297500906C07 /* WordPress 46.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 46.xcdatamodel"; sourceTree = ""; }; - E6417B981CA07B9C0084050A /* WPStyleGuide+NUX.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WPStyleGuide+NUX.swift"; sourceTree = ""; }; + E6417B981CA07B9C0084050A /* WPStyleGuide+Login.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WPStyleGuide+Login.swift"; sourceTree = ""; }; E6417B9B1CA07C3C0084050A /* NUXAbstractViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NUXAbstractViewController.swift; sourceTree = ""; }; E6417BAB1CA07F7F0084050A /* SigninHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SigninHelpers.swift; sourceTree = ""; }; E6431DDF1C4E892900FD8D90 /* SharingConnectionsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharingConnectionsViewController.h; sourceTree = ""; }; @@ -5048,6 +5048,7 @@ children = ( 436269631ECD0726008692C7 /* LoginButton.swift */, 43CC1EBF1ED898E30097E334 /* LoginTextField.swift */, + 43AD9F9B1F4F756C00565CE6 /* LoginTextButton.swift */, 43FB3F441EC1020600FC8A62 /* LoginEpilogueSectionHeader.swift */, 4346FD9A1EBA4FF40031452F /* LoginEpilogueUserInfoCell.swift */, 43FB3F401EBD215C00FC8A62 /* LoginEpilogueBlogCell.swift */, @@ -5061,7 +5062,6 @@ A2DC5B181953451B009584C3 /* WPNUXHelpBadgeLabel.h */, A2DC5B191953451B009584C3 /* WPNUXHelpBadgeLabel.m */, E6B84DD41F01BDAA00B1B686 /* SiteInfoHeaderView.swift */, - 43AD9F9B1F4F756C00565CE6 /* LoginTextButton.swift */, ); name = Views; sourceTree = ""; @@ -5089,7 +5089,7 @@ E6417B971CA07B0D0084050A /* Style */ = { isa = PBXGroup; children = ( - E6417B981CA07B9C0084050A /* WPStyleGuide+NUX.swift */, + E6417B981CA07B9C0084050A /* WPStyleGuide+Login.swift */, ); name = Style; sourceTree = ""; @@ -6155,7 +6155,7 @@ F1D690171F82914200200E30 /* BuildConfiguration.swift in Sources */, 5D2FB2861AE98C6600F1D4ED /* RestorePostTableViewCell.m in Sources */, E1BEEC651C4E3978000B4FA0 /* PaddedLabel.swift in Sources */, - E6417B991CA07B9C0084050A /* WPStyleGuide+NUX.swift in Sources */, + E6417B991CA07B9C0084050A /* WPStyleGuide+Login.swift in Sources */, E1A6DBE519DC7D230071AC1E /* PostService.m in Sources */, E62AFB6E1DC8E593007484FC /* WPTextAttachmentManager.swift in Sources */, E68580F61E0D91470090EE63 /* WPHorizontalRuleAttachment.swift in Sources */, From 81c3852783cb2f043ce6821dbf63ef716ce6fe9f Mon Sep 17 00:00:00 2001 From: aerych Date: Thu, 19 Oct 2017 16:19:03 -0500 Subject: [PATCH 2/8] Login: Moves code for google button. Simplifes. Configures highlight state. --- .../ViewRelated/NUX/WPStyleGuide+Login.swift | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift index a92bb648ff81..3a0540a273f9 100644 --- a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift +++ b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift @@ -2,6 +2,12 @@ import WordPressShared extension WPStyleGuide { + private struct Constants { + static let labelMinHeight: CGFloat = 30.0 + static let googleIconOffset: CGFloat = -1.0 + static let verticalPadding: CGFloat = 5.0 + } + /// Common view style for signin view controllers. /// /// - Parameters: @@ -69,4 +75,50 @@ extension WPStyleGuide { let fontToGetSize = WPStyleGuide.fontForTextStyle(style) return UIFont.systemFont(ofSize: fontToGetSize.pointSize, weight: UIFontWeightMedium) } + + // MARK: - Google Signin Button Methods + + /// A factory method for getting a button for Google Sign-in + /// + /// - Returns: A properly styled UIButton + /// + class func googleLoginButton() -> UIButton { + let baseString = NSLocalizedString("Or you can {G} Log in with Google.", comment: "Label for button to log in using Google. The {G} will be replaced with the Google logo.") + + let font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) + let button = UIButton() + button.translatesAutoresizingMaskIntoConstraints = false + button.contentHorizontalAlignment = .left + button.titleLabel?.font = font + button.titleLabel?.numberOfLines = 0 + button.titleLabel?.lineBreakMode = .byTruncatingTail + + let attrStrNormal = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.wordPressBlue()) + let attrStrHiglight = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.lightBlue()) + button.setAttributedTitle(attrStrNormal, for: .normal) + button.setAttributedTitle(attrStrHiglight, for: .highlighted) + return button + } + + private class func googleButtonString(_ baseString: String, for font: UIFont, linkColor: UIColor) -> NSAttributedString { + let labelParts = baseString.components(separatedBy: "{G}") + + let firstPart = labelParts[0] + // 👇 don't want to crash when a translation lacks "{G}" + let lastPart = labelParts.indices.contains(1) ? labelParts[1] : "" + + let labelString = NSMutableAttributedString(string: firstPart, attributes: [NSForegroundColorAttributeName: WPStyleGuide.greyDarken30()]) + + if let googleIcon = UIImage(named: "google"), lastPart != "" { + 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(NSAttributedString(string: lastPart, attributes: [NSForegroundColorAttributeName: linkColor])) + + return labelString + } } From b578553aa2837ece01990e09a36dc5cd7b5613c4 Mon Sep 17 00:00:00 2001 From: aerych Date: Thu, 19 Oct 2017 16:19:57 -0500 Subject: [PATCH 3/8] Login: Use style guide version of the button. --- .../Classes/ViewRelated/NUX/LoginEmailViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift b/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift index 9795f73145de..a6de0c133eea 100644 --- a/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift @@ -135,7 +135,7 @@ class LoginEmailViewController: LoginViewController, SigninKeyboardResponder { return } - let button = UIButton.googleLoginButton() + let button = WPStyleGuide.googleLoginButton() let buttonWrapper = UIView() buttonWrapper.addSubview(button) stackView.addArrangedSubview(buttonWrapper) From 9095277bf051fd10375989934eb184499cd0f413 Mon Sep 17 00:00:00 2001 From: aerych Date: Thu, 19 Oct 2017 16:20:16 -0500 Subject: [PATCH 4/8] Login: Removes previous code. --- .../ViewRelated/NUX/LoginTextButton.swift | 61 ------------------- WordPress/WordPress.xcodeproj/project.pbxproj | 4 -- 2 files changed, 65 deletions(-) delete mode 100644 WordPress/Classes/ViewRelated/NUX/LoginTextButton.swift diff --git a/WordPress/Classes/ViewRelated/NUX/LoginTextButton.swift b/WordPress/Classes/ViewRelated/NUX/LoginTextButton.swift deleted file mode 100644 index e2fe0190c040..000000000000 --- a/WordPress/Classes/ViewRelated/NUX/LoginTextButton.swift +++ /dev/null @@ -1,61 +0,0 @@ -extension UIButton { - private struct Constants { - static let labelMinHeight: CGFloat = 30.0 - static let googleIconOffset: CGFloat = -1.0 - static let verticalPadding: CGFloat = 5.0 - } - - class func googleLoginButton() -> UIButton { - let label = UILabel() - label.isUserInteractionEnabled = false - label.font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) - - let baseString = NSLocalizedString("Or you can {G} Log in with Google.", comment: "Label for button to log in using Google. The {G} will be replaced with the Google logo.") - setGoogleString(baseString, for: label) - - let button = UIButton() - setupLoginButtonLayout(button, label: label) - - return button - } - - class func setGoogleString(_ baseString: String, for label: UILabel) { - let labelParts = baseString.components(separatedBy: "{G}") - - let firstPart = labelParts[0] - // 👇 don't want to crash when a translation lacks "{G}" - let lastPart = labelParts.indices.contains(1) ? labelParts[1] : "" - - let labelString = NSMutableAttributedString(string: firstPart, attributes: [NSForegroundColorAttributeName: WPStyleGuide.greyDarken30()]) - - if let googleIcon = UIImage(named: "google"), lastPart != "" { - let googleAttachment = NSTextAttachment() - googleAttachment.image = googleIcon - googleAttachment.bounds = CGRect(x: 0.0, y: label.font.descender + Constants.googleIconOffset, width: googleIcon.size.width, height: googleIcon.size.height) - let iconString = NSAttributedString(attachment: googleAttachment) - labelString.append(iconString) - } - - labelString.append(NSAttributedString(string: lastPart, attributes: [NSForegroundColorAttributeName: WPStyleGuide.wordPressBlue()])) - - label.attributedText = labelString - } - - private class func setupLoginButtonLayout(_ button: UIButton, label: UILabel) { - button.translatesAutoresizingMaskIntoConstraints = false - label.translatesAutoresizingMaskIntoConstraints = false - label.numberOfLines = 0 - button.addSubview(label) - - button.addConstraints([ - button.topAnchor.constraint(equalTo: label.topAnchor, constant: Constants.verticalPadding * -1.0), - button.leftAnchor.constraint(equalTo: label.leftAnchor), - button.rightAnchor.constraint(equalTo: label.rightAnchor), - button.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: Constants.verticalPadding) - ]) - - label.addConstraints([ - label.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.labelMinHeight) - ]) - } -} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 992b921e4a42..0257b7ec9277 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -204,7 +204,6 @@ 438A809E1EA5DC31005D4651 /* LoginWPComViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 438A809D1EA5DC31005D4651 /* LoginWPComViewController.swift */; }; 43A85B311E9E815B00FA990B /* Login.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43A85B301E9E815B00FA990B /* Login.storyboard */; }; 43AB7C5E1D3E70510066CB6A /* PostListFilterSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43AB7C5D1D3E70510066CB6A /* PostListFilterSettings.swift */; }; - 43AD9F9C1F4F756C00565CE6 /* LoginTextButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43AD9F9B1F4F756C00565CE6 /* LoginTextButton.swift */; }; 43CC1EC01ED898E30097E334 /* LoginTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43CC1EBF1ED898E30097E334 /* LoginTextField.swift */; }; 43CE48B31F103C1F00768B87 /* FancyAlertViewController+LoginError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43CE48B21F103C1F00768B87 /* FancyAlertViewController+LoginError.swift */; }; 43D2436D1EAFCE3C00D0C77B /* LoginSegueHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D2436C1EAFCE3C00D0C77B /* LoginSegueHandler.swift */; }; @@ -1300,7 +1299,6 @@ 438A809D1EA5DC31005D4651 /* LoginWPComViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginWPComViewController.swift; sourceTree = ""; }; 43A85B301E9E815B00FA990B /* Login.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Login.storyboard; sourceTree = ""; }; 43AB7C5D1D3E70510066CB6A /* PostListFilterSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostListFilterSettings.swift; sourceTree = ""; }; - 43AD9F9B1F4F756C00565CE6 /* LoginTextButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginTextButton.swift; sourceTree = ""; }; 43C5A3E11F80AED50008BE81 /* LoginSocialErrorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginSocialErrorCell.swift; sourceTree = ""; }; 43CC1EBF1ED898E30097E334 /* LoginTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginTextField.swift; sourceTree = ""; }; 43CE48B21F103C1F00768B87 /* FancyAlertViewController+LoginError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FancyAlertViewController+LoginError.swift"; sourceTree = ""; }; @@ -5048,7 +5046,6 @@ children = ( 436269631ECD0726008692C7 /* LoginButton.swift */, 43CC1EBF1ED898E30097E334 /* LoginTextField.swift */, - 43AD9F9B1F4F756C00565CE6 /* LoginTextButton.swift */, 43FB3F441EC1020600FC8A62 /* LoginEpilogueSectionHeader.swift */, 4346FD9A1EBA4FF40031452F /* LoginEpilogueUserInfoCell.swift */, 43FB3F401EBD215C00FC8A62 /* LoginEpilogueBlogCell.swift */, @@ -6169,7 +6166,6 @@ F128C31C1AFCC95B008C2404 /* WPNavigationMediaPickerViewController+StatusBarStyle.m in Sources */, E1B9128F1BB05B1D003C25B9 /* PeopleCell.swift in Sources */, 313AE4A019E3F20400AAFABE /* CommentViewController.m in Sources */, - 43AD9F9C1F4F756C00565CE6 /* LoginTextButton.swift in Sources */, B5015C581D4FDBB300C9449E /* NotificationActionsService.swift in Sources */, A0E293F10E21027E00C6919C /* WPAddPostCategoryViewController.m in Sources */, E6BDEA731CE4824300682885 /* ReaderSearchTopic.swift in Sources */, From 8d25720b5ecbc2081bd9d2fb4f15d8563185dbf5 Mon Sep 17 00:00:00 2001 From: aerych Date: Thu, 19 Oct 2017 20:29:02 -0500 Subject: [PATCH 5/8] Login: Wrap, don't truncate. --- WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift index 3a0540a273f9..5f5375b0d035 100644 --- a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift +++ b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift @@ -91,7 +91,7 @@ extension WPStyleGuide { button.contentHorizontalAlignment = .left button.titleLabel?.font = font button.titleLabel?.numberOfLines = 0 - button.titleLabel?.lineBreakMode = .byTruncatingTail + button.titleLabel?.lineBreakMode = .byWordWrapping let attrStrNormal = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.wordPressBlue()) let attrStrHiglight = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.lightBlue()) From 36a6d78fd5783a0f28c1074df829a3a92d8f4f3e Mon Sep 17 00:00:00 2001 From: aerych Date: Thu, 19 Oct 2017 20:30:05 -0500 Subject: [PATCH 6/8] Login: Enforce minimum height. Remove bottom offset for more tappable area. --- .../Classes/ViewRelated/NUX/LoginEmailViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift b/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift index a6de0c133eea..da2a9b1f5094 100644 --- a/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift @@ -141,9 +141,12 @@ class LoginEmailViewController: LoginViewController, SigninKeyboardResponder { stackView.addArrangedSubview(buttonWrapper) button.addTarget(self, action: #selector(googleLoginTapped), for: .touchUpInside) + // Ensure height. + button.heightAnchor.constraint(greaterThanOrEqualToConstant: 40.0).isActive = true + buttonWrapper.addConstraints([ buttonWrapper.topAnchor.constraint(equalTo: button.topAnchor, constant: Constants.googleButtonOffset), - buttonWrapper.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: Constants.googleButtonOffset * -1.0), + buttonWrapper.bottomAnchor.constraint(equalTo: button.bottomAnchor), buttonWrapper.leadingAnchor.constraint(equalTo: button.leadingAnchor), buttonWrapper.trailingAnchor.constraint(equalTo: button.trailingAnchor) ]) From a42d4009a9f54bd4203200d2b6ab1f7693ff312a Mon Sep 17 00:00:00 2001 From: aerych Date: Fri, 20 Oct 2017 16:55:09 -0500 Subject: [PATCH 7/8] Login: Setting constraints to reserve top and bottom padding. --- .../Classes/ViewRelated/NUX/WPStyleGuide+Login.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift index 5f5375b0d035..2348f36aa0d0 100644 --- a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift +++ b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift @@ -87,12 +87,23 @@ extension WPStyleGuide { let font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) let button = UIButton() + button.clipsToBounds = true button.translatesAutoresizingMaskIntoConstraints = false button.contentHorizontalAlignment = .left button.titleLabel?.font = font button.titleLabel?.numberOfLines = 0 button.titleLabel?.lineBreakMode = .byWordWrapping + // Manually setting constraints to ensure that a multiline lable is fully + // visible. Some layout scenarios seem to cause the button height to size + // smaller than the text in the label. + // The constant in the anchors are to ensure there is always a + // consistent amount of space between the top and bottom of the label and + // the containing button. Edge insets can also do this but do not + // solve the height issue. + button.titleLabel?.topAnchor.constraint(equalTo: button.topAnchor, constant: 10).isActive = true + button.titleLabel?.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -10).isActive = true + let attrStrNormal = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.wordPressBlue()) let attrStrHiglight = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.lightBlue()) button.setAttributedTitle(attrStrNormal, for: .normal) From 3c9590c9285ba2e148c221bde07626cabe954935 Mon Sep 17 00:00:00 2001 From: aerych Date: Sat, 21 Oct 2017 17:43:17 -0500 Subject: [PATCH 8/8] Login: Some updates from code review. --- .../NUX/LoginEmailViewController.swift | 3 --- .../ViewRelated/NUX/WPStyleGuide+Login.swift | 19 ++++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift b/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift index 7079d0391af5..22ccd5bb3ff1 100644 --- a/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/LoginEmailViewController.swift @@ -141,9 +141,6 @@ class LoginEmailViewController: LoginViewController, SigninKeyboardResponder { stackView.addArrangedSubview(buttonWrapper) button.addTarget(self, action: #selector(googleLoginTapped), for: .touchUpInside) - // Ensure height. - button.heightAnchor.constraint(greaterThanOrEqualToConstant: 40.0).isActive = true - buttonWrapper.addConstraints([ buttonWrapper.topAnchor.constraint(equalTo: button.topAnchor, constant: Constants.googleButtonOffset), buttonWrapper.bottomAnchor.constraint(equalTo: button.bottomAnchor), diff --git a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift index 2348f36aa0d0..a1ba6860b2be 100644 --- a/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift +++ b/WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift @@ -3,9 +3,9 @@ import WordPressShared extension WPStyleGuide { private struct Constants { - static let labelMinHeight: CGFloat = 30.0 + static let buttonMinHeight: CGFloat = 40.0 static let googleIconOffset: CGFloat = -1.0 - static let verticalPadding: CGFloat = 5.0 + static let verticalLabelSpacing: CGFloat = 10.0 } /// Common view style for signin view controllers. @@ -94,15 +94,12 @@ extension WPStyleGuide { button.titleLabel?.numberOfLines = 0 button.titleLabel?.lineBreakMode = .byWordWrapping - // Manually setting constraints to ensure that a multiline lable is fully - // visible. Some layout scenarios seem to cause the button height to size - // smaller than the text in the label. - // The constant in the anchors are to ensure there is always a - // consistent amount of space between the top and bottom of the label and - // the containing button. Edge insets can also do this but do not - // solve the height issue. - button.titleLabel?.topAnchor.constraint(equalTo: button.topAnchor, constant: 10).isActive = true - button.titleLabel?.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -10).isActive = true + // These constraints work around some issues with multiline buttons and + // vertical layout. Without them the button's height may not account + // for the titleLabel's height. + button.titleLabel?.topAnchor.constraint(equalTo: button.topAnchor, constant: Constants.verticalLabelSpacing).isActive = true + button.titleLabel?.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -Constants.verticalLabelSpacing).isActive = true + button.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonMinHeight).isActive = true let attrStrNormal = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.wordPressBlue()) let attrStrHiglight = googleButtonString(baseString, for: font, linkColor: WPStyleGuide.lightBlue())