-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Login: Social Error Screens #7887
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
15 commits
Select commit
Hold shift + click to select a range
8e372dd
Add error screen VC
nheagy be1e614
Add social login error action to try again buttons
nheagy e38ed89
Add signup button to social login error
nheagy 64a020b
Add display of error screen to google login
nheagy bc51ab8
fix a brace from a really bad bad brace to an obviously better one
nheagy 0ec7017
Add missing new entries to project file
nheagy eb709dc
Change button color to darkGrey
nheagy 1d6228a
Set awaitingGoogle back to false, cleanup configureViewLoading
nheagy 2af050a
Make min height value a Constant
nheagy 42d648c
Move bg color to viewDidLoad; clean up estimated height code
nheagy c93e916
Remove frame: .zero init calls
nheagy e30271b
Add some comments to LoginSocialErrorViewController
nheagy fee9eda
Switch social error VC to use modal presentation
nheagy 677a8d0
Add help button and WP logo to social error screen
nheagy d63f41d
Merge branch 'develop' into feature/7675-error-screens
nheagy 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
65 changes: 65 additions & 0 deletions
65
WordPress/Classes/ViewRelated/NUX/LoginSocialErrorCell.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,65 @@ | ||
| class LoginSocialErrorCell: UITableViewCell { | ||
| private let errorTitle: String | ||
| private let errorDescription: String | ||
| private let titleLabel: UILabel | ||
| private let descriptionLabel: UILabel | ||
| private let labelStack: UIStackView | ||
|
|
||
| private struct Constants { | ||
| static let labelSpacing: CGFloat = 15.0 | ||
| static let labelVerticalMargin: CGFloat = 20.0 | ||
| static let descriptionMinHeight: CGFloat = 14.0 | ||
| } | ||
|
|
||
| init(title: String, description: String) { | ||
| errorTitle = title | ||
| errorDescription = description | ||
| titleLabel = UILabel() | ||
| descriptionLabel = UILabel() | ||
| labelStack = UIStackView() | ||
|
|
||
| super.init(style: .default, reuseIdentifier: "LoginSocialErrorCell") | ||
|
|
||
| layoutLabels() | ||
| } | ||
|
|
||
| required init?(coder aDecoder: NSCoder) { | ||
| errorTitle = aDecoder.value(forKey: "errorTitle") as? String ?? "" | ||
| errorDescription = aDecoder.value(forKey: "errorDescription") as? String ?? "" | ||
| titleLabel = UILabel() | ||
| descriptionLabel = UILabel() | ||
| labelStack = UIStackView() | ||
|
|
||
| super.init(coder: aDecoder) | ||
|
|
||
| layoutLabels() | ||
| } | ||
|
|
||
| private func layoutLabels() { | ||
| contentView.addSubview(labelStack) | ||
| labelStack.translatesAutoresizingMaskIntoConstraints = false | ||
| labelStack.addArrangedSubview(titleLabel) | ||
| labelStack.addArrangedSubview(descriptionLabel) | ||
| labelStack.axis = .vertical | ||
| labelStack.spacing = Constants.labelSpacing | ||
|
|
||
| titleLabel.font = WPStyleGuide.fontForTextStyle(.footnote) | ||
| titleLabel.textColor = WPStyleGuide.greyDarken30() | ||
| descriptionLabel.font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) | ||
| descriptionLabel.textColor = WPStyleGuide.darkGrey() | ||
| descriptionLabel.numberOfLines = 0 | ||
| descriptionLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.descriptionMinHeight).isActive = true | ||
|
|
||
| contentView.addConstraints([ | ||
| contentView.topAnchor.constraint(equalTo: labelStack.topAnchor, constant: Constants.labelVerticalMargin * -1.0), | ||
| contentView.bottomAnchor.constraint(equalTo: labelStack.bottomAnchor, constant: Constants.labelVerticalMargin), | ||
| contentView.layoutMarginsGuide.leadingAnchor.constraint(equalTo: labelStack.leadingAnchor), | ||
| contentView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: labelStack.trailingAnchor) | ||
| ]) | ||
|
|
||
| titleLabel.text = errorTitle.localizedUppercase | ||
| descriptionLabel.text = errorDescription | ||
|
|
||
| backgroundColor = WPStyleGuide.greyLighten30() | ||
| } | ||
| } |
168 changes: 168 additions & 0 deletions
168
WordPress/Classes/ViewRelated/NUX/LoginSocialErrorViewController.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,168 @@ | ||
| import Foundation | ||
| import Gridicons | ||
|
|
||
| @objc | ||
| protocol LoginSocialErrorViewControllerDelegate { | ||
| func retryWithEmail() | ||
| func retryWithAddress() | ||
| func retryAsSignup() | ||
| } | ||
|
|
||
| /// ViewController for presenting recovery options when social login fails | ||
| class LoginSocialErrorViewController: UITableViewController, LoginWithLogoAndHelpViewController { | ||
| fileprivate var errorTitle: String | ||
| fileprivate var errorDescription: String | ||
| var delegate: LoginSocialErrorViewControllerDelegate? | ||
|
|
||
| fileprivate enum Sections: Int { | ||
| case titleAndDescription = 0 | ||
| case buttons = 1 | ||
|
|
||
| static var count: Int { | ||
| return buttons.rawValue + 1 | ||
| } | ||
| } | ||
|
|
||
| fileprivate enum Buttons: Int { | ||
| case tryEmail = 0 | ||
| case tryAddress = 1 | ||
| case signup = 2 | ||
| } | ||
|
|
||
| /// Create and instance of LoginSocialErrorViewController | ||
| /// | ||
| /// - Parameters: | ||
| /// - title: The title that will be shown on the error VC | ||
| /// - description: A brief explination of what failed during social login | ||
| init(title: String, description: String) { | ||
| errorTitle = title | ||
| errorDescription = description | ||
|
|
||
| super.init(nibName: nil, bundle: nil) | ||
| } | ||
|
|
||
| required init?(coder aDecoder: NSCoder) { | ||
| errorTitle = aDecoder.value(forKey: "errorTitle") as? String ?? "" | ||
| errorDescription = aDecoder.value(forKey: "errorDescription") as? String ?? "" | ||
|
|
||
| super.init(coder: aDecoder) | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
|
|
||
| view.backgroundColor = WPStyleGuide.greyLighten30() | ||
| addHelpButtonToNavController() | ||
| addWordPressLogoToNavController() | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
| guard indexPath.section == Sections.buttons.rawValue, | ||
| let delegate = delegate else { | ||
| return | ||
| } | ||
|
|
||
| switch indexPath.row { | ||
| case Buttons.tryEmail.rawValue: | ||
| delegate.retryWithEmail() | ||
| case Buttons.tryAddress.rawValue: | ||
| delegate.retryWithAddress() | ||
| case Buttons.signup.rawValue: | ||
| fallthrough | ||
| default: | ||
| delegate.retryAsSignup() | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // MARK: UITableViewDelegate methods | ||
|
|
||
| extension LoginSocialErrorViewController { | ||
| private struct RowHeightConstants { | ||
| static let estimate: CGFloat = 45.0 | ||
| static let automatic: CGFloat = UITableViewAutomaticDimension | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { | ||
| return RowHeightConstants.estimate | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
| return RowHeightConstants.automatic | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // MARK: UITableViewDataSource methods | ||
|
|
||
| extension LoginSocialErrorViewController { | ||
| private struct Constants { | ||
| static let buttonCount = 3 | ||
| } | ||
|
|
||
| override func numberOfSections(in tableView: UITableView) -> Int { | ||
| return Sections.count | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
| switch section { | ||
| case Sections.titleAndDescription.rawValue: | ||
| return 1 | ||
| case Sections.buttons.rawValue: | ||
| return Constants.buttonCount | ||
| default: | ||
| return 0 | ||
| } | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
| let cell: UITableViewCell | ||
| switch indexPath.section { | ||
| case Sections.titleAndDescription.rawValue: | ||
| cell = titleAndDescriptionCell() | ||
| case Sections.buttons.rawValue: | ||
| fallthrough | ||
| default: | ||
| cell = buttonCell(index: indexPath.row) | ||
| } | ||
| return cell | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { | ||
| let footer = UIView() | ||
| footer.backgroundColor = WPStyleGuide.greyLighten20() | ||
| return footer | ||
| } | ||
|
|
||
| override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { | ||
| return 0.5 | ||
| } | ||
|
|
||
| private func titleAndDescriptionCell() -> UITableViewCell { | ||
| return LoginSocialErrorCell(title: errorTitle, description: errorDescription) | ||
| } | ||
|
|
||
| private func buttonCell(index: Int) -> UITableViewCell { | ||
| let cell = UITableViewCell() | ||
| let buttonText: String | ||
| let buttonIcon: UIImage | ||
| switch index { | ||
| case Buttons.tryEmail.rawValue: | ||
| buttonText = NSLocalizedString("Try with another email", comment: "When social login fails, this button offers to let the user try again with a differen email address") | ||
| buttonIcon = Gridicon.iconOfType(.undo) | ||
| case Buttons.tryAddress.rawValue: | ||
| buttonText = NSLocalizedString("Try with the site address", comment: "When social login fails, this button offers to let them try tp login using a URL") | ||
| buttonIcon = Gridicon.iconOfType(.domains) | ||
| case Buttons.signup.rawValue: | ||
| fallthrough | ||
| default: | ||
| buttonText = NSLocalizedString("Sign up", comment: "When social login fails, this button offers to let them signup for a new WordPress.com account") | ||
| buttonIcon = Gridicon.iconOfType(.mySites) | ||
| } | ||
| cell.textLabel?.text = buttonText | ||
| cell.textLabel?.textColor = WPStyleGuide.darkGrey() | ||
| cell.imageView?.image = buttonIcon.imageWithTintColor(WPStyleGuide.grey()) | ||
| return cell | ||
| } | ||
| } | ||
Oops, something went wrong.
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 think this method can be removed if
tableView:viewForFooterInSection:returnsUIView(frame: .zero). Seems that way when I test. Same for setting thefooter.backgroundColorUh oh!
There was an error while loading. Please reload this page.
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.
This draws the dark line above and below the button cells.
The initial frame size of
.zerowill be ignored/modified by autolayout.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 totally missed that there were lines in the mock. Totally makes sense now. :)
This hasn't been my experience, but whatev 🤷♂️
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 usually just do
UIView()not sure why I decided to useUIView(frame: .zero)here 😜 I'll probably switch it to the former, to make the result more clear.