-
Notifications
You must be signed in to change notification settings - Fork 0
Text field refactor/richie #75
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
Open
rs929
wants to merge
2
commits into
main
Choose a base branch
from
textFieldRefactor/richie
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
|---|---|---|
|
|
@@ -23,24 +23,28 @@ class FavoritesViewController: OnboardingViewController { | |
| view.backgroundColor = .white | ||
| setupTitle(name: "Favorites") | ||
|
|
||
| nextAction = UIAction { _ in | ||
| guard let navCtrl = self.navigationController else { return } | ||
|
|
||
| guard let snack = self.snackTextField.textField.text, !snack.isEmpty, | ||
| let song = self.songTextField.textField.text, !song.isEmpty, | ||
| let stop = self.stopTextField.textField.text, !stop.isEmpty else { | ||
| self.presentErrorAlert(title: "Error", message: "Please complete all fields.") | ||
|
|
||
| return | ||
| } | ||
| nextAction = UIAction { [self] _ in | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change |
||
| guard let navCtrl = navigationController else { return } | ||
|
|
||
| [snackTextField, songTextField, stopTextField].forEach { textField in | ||
| if (textField.textField.text ?? "").isEmpty { | ||
| textField.displayError() | ||
| } | ||
| } | ||
|
|
||
| guard let snack = snackTextField.textField.text, !snack.isEmpty, | ||
| let song = songTextField.textField.text, !song.isEmpty, | ||
| let stop = stopTextField.textField.text, !stop.isEmpty else { | ||
| return | ||
| } | ||
|
|
||
| let snackTrimmed = snack.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| let songTrimmed = song.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| let stopTrimmed = stop.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| self.addPrompt(name: "Snack", placeholder: "Chips", answer: snackTrimmed) | ||
| self.addPrompt(name: "Song", placeholder: "Favorite Song", answer: songTrimmed) | ||
| self.addPrompt(name: "Stop", placeholder: "Gates Hall", answer: stopTrimmed) | ||
| self.delegate?.didTapNext(navCtrl, nextViewController: nil) | ||
| addPrompt(name: "Snack", placeholder: "Chips", answer: snackTrimmed) | ||
| addPrompt(name: "Song", placeholder: "Favorite Song", answer: songTrimmed) | ||
| addPrompt(name: "Stop", placeholder: "Gates Hall", answer: stopTrimmed) | ||
| delegate?.didTapNext(navCtrl, nextViewController: nil) | ||
| } | ||
|
|
||
| setupTitleLines() | ||
|
|
@@ -53,9 +57,6 @@ class FavoritesViewController: OnboardingViewController { | |
| // MARK: - Setup View Functions | ||
|
|
||
| private func setupStackView() { | ||
| let textFieldBorderWidth = 1.0 | ||
| let textFieldCornerRadius = 4.0 | ||
| let textFieldFont = UIFont(name: "SFPro", size: 16) | ||
| let leadingTrailingInset = 32 | ||
| let textFieldHeight = 56 | ||
|
|
||
|
|
@@ -105,21 +106,19 @@ class FavoritesViewController: OnboardingViewController { | |
| extension FavoritesViewController: UITextFieldDelegate { | ||
|
|
||
| func textFieldDidBeginEditing(_ textField: UITextField) { | ||
| if let onboardingTextField = textField as? OnboardingTextField { | ||
| if let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: true) | ||
| associatedView.hidesLabel(isHidden: false) | ||
| } | ||
| if let onboardingTextField = textField as? OnboardingTextField, | ||
| let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: true) | ||
| associatedView.hidesLabel(isHidden: false) | ||
| } | ||
| } | ||
|
|
||
| func textFieldDidEndEditing(_ textField: UITextField) { | ||
| if let onboardingTextField = textField as? OnboardingTextField { | ||
| if let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: false) | ||
| if textField.text?.isEmpty ?? true { | ||
| associatedView.hidesLabel(isHidden: true) | ||
| } | ||
| if let onboardingTextField = textField as? OnboardingTextField, | ||
| let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: false) | ||
| if textField.text?.isEmpty ?? true { | ||
| associatedView.hidesLabel(isHidden: true) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -130,6 +129,13 @@ extension FavoritesViewController: UITextFieldDelegate { | |
|
|
||
| setNextButtonColor(disabled: !textFieldsComplete(texts: responses)) | ||
| } | ||
|
|
||
| func textFieldDidChangeSelection(_ textField: UITextField) { | ||
| if let onboardingTextField = textField as? OnboardingTextField, | ||
| let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: true) | ||
| } | ||
| } | ||
|
|
||
| func textFieldShouldReturn(_ textField: UITextField) -> Bool { | ||
| textField.endEditing(true) | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ class PreferredContactViewController: OnboardingViewController { | |
| } | ||
|
|
||
| guard let phoneNumber = self.numberTextField.textField.text, self.validateNumber(value: phoneNumber) else { | ||
| self.presentErrorAlert(title: "Error", message: "Please enter a valid phone number.") | ||
| self.numberTextField.displayError() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure you retain an |
||
| return | ||
| } | ||
|
|
||
|
|
@@ -137,7 +137,7 @@ class PreferredContactViewController: OnboardingViewController { | |
|
|
||
| numberTextField.isHidden = true | ||
| numberTextField.delegate = self | ||
| numberTextField.setup(title: "Phone", placeholder: "000-000-0000") | ||
| numberTextField.setup(title: "Phone", placeholder: "000-000-0000", error: "Please enter a valid phone number") | ||
| numberTextField.textField.keyboardType = .phonePad | ||
| view.addSubview(numberTextField) | ||
|
|
||
|
|
@@ -172,31 +172,32 @@ extension PreferredContactViewController: UITextFieldDelegate { | |
| } | ||
|
|
||
| func textFieldDidChangeSelection(_ textField: UITextField) { | ||
| if textField == numberTextField.textField { | ||
| self.setNextButtonColor(disabled: !self.validateNumber(value: self.numberTextField.textField.text ?? "")) | ||
| if let onboardingTextField = textField as? OnboardingTextField, | ||
| let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: true) | ||
| } | ||
|
|
||
| setNextButtonColor(disabled: !validateNumber(value: textField.text ?? "")) | ||
| } | ||
|
|
||
| func textFieldDidBeginEditing(_ textField: UITextField) { | ||
| if let onboardingTextField = textField as? OnboardingTextField { | ||
| if let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: true) | ||
| associatedView.hidesLabel(isHidden: false) | ||
| } | ||
| if let onboardingTextField = textField as? OnboardingTextField, | ||
| let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: true) | ||
| associatedView.hidesLabel(isHidden: false) | ||
| } | ||
| } | ||
|
|
||
| func textFieldDidEndEditing(_ textField: UITextField) { | ||
| if let onboardingTextField = textField as? OnboardingTextField { | ||
| if let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: false) | ||
| if textField.text?.isEmpty ?? true { | ||
| associatedView.hidesLabel(isHidden: true) | ||
| } | ||
| if let onboardingTextField = textField as? OnboardingTextField, | ||
| let associatedView = onboardingTextField.associatedView as? LabeledTextField { | ||
| associatedView.labeledTextField(isSelected: false) | ||
| if textField.text?.isEmpty ?? true { | ||
| associatedView.hidesLabel(isHidden: true) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func textFieldShouldReturn(_ textField: UITextField) -> Bool { | ||
| textField.endEditing(true) | ||
| } | ||
|
|
||
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.
Change
[self]to[unowned self]