Skip to content
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

[NT-312] Pledge amount invalid input color #849

Merged
merged 14 commits into from
Sep 26, 2019
Merged

Conversation

dusi
Copy link
Contributor

@dusi dusi commented Sep 21, 2019

πŸ“² What

  • When the input value is lower than the minimum or higher than the maximum the text turns red
  • When user dismisses keyboard by tapping anywhere on the screen (and the input is still invalid) it stays this way (instead of clamping it to either min or max)

πŸ€” Why

Some UX improvements to amount input

πŸ›  How

See inline comments

πŸ‘€ See

Before πŸ› After πŸ¦‹
Screen Shot 2019-09-20 at 11 17 03 PM Screen Shot 2019-09-20 at 11 18 46 PM
Screen Shot 2019-09-20 at 11 17 19 PM Screen Shot 2019-09-20 at 11 18 57 PM

βœ… Acceptance criteria

TextField input

  • Entering value that is smaller than minimum pledge value should make the text red
  • Entering value that is larger than maximum pledge value should make the text red
  • Entering 0 disables the decrement button of the stepper
  • Entering Double max disables the increment button of the stepper (this will be harder to test so it might be sufficient to review snapshots and integration tests)

Stepper input

  • Entering value that is smaller than minimum pledge value should make the text red
  • Entering value that is larger than maximum pledge value should make the text red
  • Entering 0 disables the decrement button of the stepper
  • Entering Double max disables the increment button of the stepper (this will be harder to test so it might be sufficient to review snapshots and integration tests)

It's possible that the last criteria will be better tested when we remove decimal support in some of the upcoming work.

⏰ TODO

import UIKit

extension UITraitCollection {
static let allCases: [UITraitCollection] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a test helper for allowing us testing large text better.

@@ -112,15 +112,13 @@ private let labelStyle: LabelStyle = { (label: UILabel) in
|> \.font .~ UIFont.ksr_body()
|> \.adjustsFontForContentSizeCategory .~ true
|> \.textAlignment .~ NSTextAlignment.right
|> \.textColor .~ UIColor.ksr_green_500
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are now set using VM's outputs

|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private lazy var horizontalSpacer: UIView = { UIView(frame: .zero) }()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No real need for auto layout anymore...we're using spacing (where we have previously used auto layout)...this should be simpler and more readable.

@@ -40,16 +36,14 @@ final class PledgeAmountViewController: UIViewController {
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = ([self.titleLabel, self.adaptableStackView], self.rootStackView)
_ = ([self.titleLabel, self.adaptableStackView, UIView(frame: .zero)], self.rootStackView)
Copy link
Contributor Author

@dusi dusi Sep 21, 2019

Choose a reason for hiding this comment

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

This makes sure that the vertical stack view will always align its subviews vertically to the top

|> ksr_addArrangedSubviewsToStackView()

self.amountInputView.textField.delegate = self

self.spacer.widthAnchor.constraint(greaterThanOrEqualToConstant: Styles.grid(3)).isActive = true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have previously used this width as the minimum space between the stepper and the input field (otherwise when the text field grows it would almost touch the stepper)...now this is done using spacing on the stack view which should be much simpler and easier to reason about.

import Prelude
import UIKit

final class PledgeAmountViewControllerTests: TestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt like it was a perfect opportunity to add testing...not only can we test large text but also invalid input values, currency symbol, stepper increment/decrement button etc.

}
}

func testView_WithShippingLocation() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Rename to something more meaningful

self.stepperMaxValue = minAndMax.signal
.map(second)
self.stepperMinValue = minValue.mapConst(0)
self.stepperMaxValue = minValue.mapConst(Double.greatestFiniteMagnitude)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made a decision to use 0...Double.max but we can chose something else as well (I'm open to discussing this).

The reason we're able to do 0...Double.max is because we want to allow the user to actually decrement/increment bellow/above pledge's min/max value...in that case we simply change the input text to red to indicate this out of bounds state.

@ksr-ci-bot
Copy link

ksr-ci-bot commented Sep 21, 2019

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@@ -4,7 +4,7 @@ github "Alamofire/AlamofireImage" "c41f8b0acfbb3180fe045df73596e4332c338633"
github "ReactiveCocoa/ReactiveSwift" "6.0.0"
github "facebook/facebook-objc-sdk" "v5.0.2"
github "kickstarter/Kickstarter-Prelude" "d03f8831dcec9ad157db4f1c5f769ec17e1a3766"
github "kickstarter/Kickstarter-ReactiveExtensions" "aa994f0921dca1965ae537fe77c2edc798eef230"
github "kickstarter/Kickstarter-ReactiveExtensions" "99c3013e22fd6d4ea29d9d4c7a4a7b10bf80a99c"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's weird that it builds on Circle and not on my machine. I wonder what's the real problem here. πŸ€”

Copy link
Contributor

Choose a reason for hiding this comment

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

The hash in this file should match the one in the Cartfile.

)

self.textFieldIsFirstResponder = self.doneButtonTappedProperty.signal
.mapConst(false)

self.textFieldTextColor = textColor
.wrapInOptional()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it seemed necessary to pass textColor as an optional to a UITextField (which is how it's also defined in UIKit)

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

All seems good! Just the Carthage.resolved comment and then a question. The abstract seems to require that the Total is also red?

@@ -4,7 +4,7 @@ github "Alamofire/AlamofireImage" "c41f8b0acfbb3180fe045df73596e4332c338633"
github "ReactiveCocoa/ReactiveSwift" "6.0.0"
github "facebook/facebook-objc-sdk" "v5.0.2"
github "kickstarter/Kickstarter-Prelude" "d03f8831dcec9ad157db4f1c5f769ec17e1a3766"
github "kickstarter/Kickstarter-ReactiveExtensions" "aa994f0921dca1965ae537fe77c2edc798eef230"
github "kickstarter/Kickstarter-ReactiveExtensions" "99c3013e22fd6d4ea29d9d4c7a4a7b10bf80a99c"
Copy link
Contributor

Choose a reason for hiding this comment

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

The hash in this file should match the one in the Cartfile.

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

legit!

@dusi dusi merged commit ed41a9a into master Sep 26, 2019
@dusi dusi deleted the pledge-amount-input-invalid branch October 4, 2019 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants