Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions Scoop/Controller/Onboarding/AboutYouViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ class AboutYouViewController: OnboardingViewController {
view.backgroundColor = .white
setupTitle(name: "About you")

nextAction = UIAction { _ in
nextAction = UIAction { [self] _ in
Copy link
Collaborator

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]

guard let navCtrl = self.navigationController else {
return
}

[nameTextField, pronounsTextField, hometownTextField, yearTextField].forEach { textField in
if (textField.textField.text ?? "").isEmpty {
textField.displayError()
}
}

guard let name = self.nameTextField.textField.text, !name.isEmpty,
let pronouns = self.pronounsTextField.textField.text, !pronouns.isEmpty,
let hometown = self.hometownTextField.textField.text, !hometown.isEmpty,
let year = self.yearTextField.textField.text, !year.isEmpty else {
self.presentErrorAlert(title: "Error", message: "Please complete all fields.")
return
}
return
}

NetworkManager.shared.currentUser.pronouns = pronouns
NetworkManager.shared.currentUser.grade = year
let hometownTrimmed = hometown.trimmingCharacters(in: .whitespacesAndNewlines)
Expand All @@ -65,9 +71,6 @@ class AboutYouViewController: OnboardingViewController {
var stackViewMultiplier = 0.20
let leadingTrailingInset = 32
let screenSize = UIScreen.main.bounds
let textFieldBorderWidth = 1.0
let textFieldCornerRadius = 4.0
let textFieldFont = UIFont(name: "SFPro", size: 16)
let textFieldHeight = 56

if screenSize.height < 2000 {
Expand Down Expand Up @@ -150,25 +153,23 @@ class AboutYouViewController: OnboardingViewController {
extension AboutYouViewController: UITextFieldDelegate {

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
return !(textField == yearTextField || textField == pronounsTextField)
return !(textField == yearTextField.textField || textField == pronounsTextField.textField)
}

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)
}
}

Expand All @@ -183,6 +184,13 @@ extension AboutYouViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.endEditing(true)
}

func textFieldDidChangeSelection(_ textField: UITextField) {
if let onboardingTextField = textField as? OnboardingTextField,
let associatedView = onboardingTextField.associatedView as? LabeledTextField {
associatedView.labeledTextField(isSelected: true)
}
}

}

Expand Down
62 changes: 34 additions & 28 deletions Scoop/Controller/Onboarding/FavoritesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

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]

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()
Expand All @@ -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

Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
Expand Down
33 changes: 17 additions & 16 deletions Scoop/Controller/Onboarding/PreferredContactViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you retain an [unowned self]

return
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down
Loading