-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature/7675 google button touch states #8017
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2cf2e37
Login: Renames file.
aerych 81c3852
Login: Moves code for google button. Simplifes. Configures highlight …
aerych b578553
Login: Use style guide version of the button.
aerych 9095277
Login: Removes previous code.
aerych 8d25720
Login: Wrap, don't truncate.
aerych 36a6d78
Login: Enforce minimum height. Remove bottom offset for more tappable…
aerych a42d400
Login: Setting constraints to reserve top and bottom padding.
aerych d9f857d
Merge branch 'develop' of github.com:wordpress-mobile/WordPress-iOS i…
aerych 3c9590c
Login: Some updates from code review.
aerych File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
WordPress/Classes/ViewRelated/NUX/WPStyleGuide+Login.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import WordPressShared | ||
|
|
||
| extension WPStyleGuide { | ||
|
|
||
| private struct Constants { | ||
| static let buttonMinHeight: CGFloat = 40.0 | ||
| static let googleIconOffset: CGFloat = -1.0 | ||
| static let verticalLabelSpacing: CGFloat = 10.0 | ||
| } | ||
|
|
||
| /// Common view style for signin view controllers. | ||
| /// | ||
| /// - Parameters: | ||
| /// - view: The view to style. | ||
| /// | ||
| class func configureColorsForSigninView(_ view: UIView) { | ||
| view.backgroundColor = wordPressBlue() | ||
| } | ||
|
|
||
| /// Adds a 1password button to a WPWalkthroughTextField, if available | ||
| /// | ||
| class func configureOnePasswordButtonForTextfield(_ textField: WPWalkthroughTextField, target: NSObject, selector: Selector) { | ||
| if !OnePasswordFacade().isOnePasswordEnabled() { | ||
| return | ||
| } | ||
|
|
||
| let onePasswordButton = UIButton(type: .custom) | ||
| onePasswordButton.setImage(UIImage(named: "onepassword-wp-button"), for: UIControlState()) | ||
| onePasswordButton.sizeToFit() | ||
|
|
||
| textField.rightView = onePasswordButton | ||
| textField.rightViewPadding = UIOffset(horizontal: 20.0, vertical: 0.0) | ||
| textField.rightViewMode = .always | ||
|
|
||
| onePasswordButton.addTarget(target, action: selector, for: .touchUpInside) | ||
| } | ||
|
|
||
| /// Adds a 1password button to a stack view, if available | ||
| /// | ||
| class func configureOnePasswordButtonForStackView(_ stack: UIStackView, target: NSObject, selector: Selector) { | ||
| if !OnePasswordFacade().isOnePasswordEnabled() { | ||
| return | ||
| } | ||
|
|
||
| let onePasswordButton = UIButton(type: .custom) | ||
| onePasswordButton.setImage(UIImage(named: "onepassword-wp-button"), for: UIControlState()) | ||
| onePasswordButton.sizeToFit() | ||
| onePasswordButton.setContentHuggingPriority(UILayoutPriorityRequired, for: .horizontal) | ||
| onePasswordButton.setContentCompressionResistancePriority(UILayoutPriorityRequired, for: .horizontal) | ||
|
|
||
| stack.addArrangedSubview(onePasswordButton) | ||
|
|
||
| onePasswordButton.addTarget(target, action: selector, for: .touchUpInside) | ||
| } | ||
|
|
||
| /// | ||
| /// | ||
| class func colorForErrorView(_ opaque: Bool) -> UIColor { | ||
| let alpha: CGFloat = opaque ? 1.0 : 0.95 | ||
| return UIColor(fromRGBAColorWithRed: 17.0, green: 17.0, blue: 17.0, alpha: alpha) | ||
| } | ||
|
|
||
| /// | ||
| /// | ||
| class func edgeInsetForLoginTextFields() -> UIEdgeInsets { | ||
| return UIEdgeInsetsMake(7, 20, 7, 20) | ||
| } | ||
|
|
||
| /// Return the system font in medium weight for the given style | ||
| /// | ||
| /// - note: iOS won't return UIFontWeightMedium for dynamic system font :( | ||
| /// So instead get the dynamic font size, then ask for the non-dynamic font at that size | ||
| /// | ||
| class func mediumWeightFont(forStyle style: UIFontTextStyle) -> UIFont { | ||
| 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.clipsToBounds = true | ||
| button.translatesAutoresizingMaskIntoConstraints = false | ||
| button.contentHorizontalAlignment = .left | ||
| button.titleLabel?.font = font | ||
| button.titleLabel?.numberOfLines = 0 | ||
| button.titleLabel?.lineBreakMode = .byWordWrapping | ||
|
|
||
| // 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()) | ||
| 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 | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this edited comment :D