-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
💲[Native Checkout] Project Pledge States UI - UI Fixes #724
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,14 +8,27 @@ final class PledgeCTAContainerView: UIView { | |||||
|
||||||
private let vm: PledgeCTAContainerViewViewModelType = PledgeCTAContainerViewViewModel() | ||||||
|
||||||
private lazy var amountAndRewardTitleStackView: UIStackView = { UIStackView(frame: .zero) }() | ||||||
private lazy var amountAndRewardTitleStackView: UIStackView = { | ||||||
UIStackView(frame: .zero) | ||||||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||||||
}() | ||||||
|
||||||
private lazy var amountOrRewardLabel: UILabel = { UILabel(frame: .zero) }() | ||||||
private lazy var pledgeCTAbutton: UIButton = { | ||||||
private lazy var pledgeCTAButton: UIButton = { | ||||||
MultiLineButton(type: .custom) | ||||||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||||||
}() | ||||||
|
||||||
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }() | ||||||
private lazy var rootStackView: UIStackView = { | ||||||
UIStackView(frame: .zero) | ||||||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||||||
}() | ||||||
|
||||||
private lazy var spacer: UIView = { | ||||||
UIView(frame: .zero) | ||||||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||||||
}() | ||||||
|
||||||
private lazy var youreABackerLabel: UILabel = { UILabel(frame: .zero) }() | ||||||
|
||||||
// MARK: - Lifecycle | ||||||
|
@@ -30,17 +43,12 @@ final class PledgeCTAContainerView: UIView { | |||||
_ = ([self.youreABackerLabel, self.amountOrRewardLabel], self.amountAndRewardTitleStackView) | ||||||
|> ksr_addArrangedSubviewsToStackView() | ||||||
|
||||||
_ = ([self.amountAndRewardTitleStackView, self.pledgeCTAbutton], self.rootStackView) | ||||||
_ = ([self.amountAndRewardTitleStackView, self.spacer, self.pledgeCTAButton], self.rootStackView) | ||||||
|> ksr_addArrangedSubviewsToStackView() | ||||||
|
||||||
NSLayoutConstraint.activate( | ||||||
[ | ||||||
self.pledgeCTAbutton.heightAnchor.constraint( | ||||||
greaterThanOrEqualToConstant: Styles.minTouchSize.height | ||||||
), | ||||||
self.pledgeCTAbutton.trailingAnchor.constraint(equalTo: self.rootStackView.trailingAnchor) | ||||||
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. 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. I did not reproduce this but it could have been pointed out in #702. |
||||||
] | ||||||
) | ||||||
NSLayoutConstraint.activate([ | ||||||
self.pledgeCTAButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Styles.minTouchSize.height) | ||||||
]) | ||||||
|
||||||
self.bindViewModel() | ||||||
} | ||||||
|
@@ -54,41 +62,44 @@ final class PledgeCTAContainerView: UIView { | |||||
override func bindStyles() { | ||||||
super.bindStyles() | ||||||
|
||||||
_ = self.pledgeCTAbutton | ||||||
|> projectStateButtonStyle | ||||||
let isAccessibilityCategory = self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory | ||||||
|
||||||
_ = self.youreABackerLabel | ||||||
|> \.font .~ .ksr_headline(size: 14) | ||||||
|> \.text %~ { _ in Strings.Youre_a_backer() } | ||||||
_ = self.amountAndRewardTitleStackView | ||||||
|> \.axis .~ NSLayoutConstraint.Axis.vertical | ||||||
|> \.isLayoutMarginsRelativeArrangement .~ true | ||||||
|
||||||
_ = self.amountOrRewardLabel | ||||||
|> \.font .~ .ksr_caption1(size: 14) | ||||||
|> \.textColor .~ .ksr_dark_grey_500 | ||||||
|> \.font .~ UIFont.ksr_caption1(size: 14) | ||||||
|> \.textColor .~ UIColor.ksr_dark_grey_500 | ||||||
|> \.numberOfLines .~ 0 | ||||||
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. 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. I'm wondering if we should to handle Dynamic Type on fixed elements differently. The viewable part of the screen (beneath the |
||||||
|
||||||
_ = self.pledgeCTAButton | ||||||
|> pledgeCTAButtonStyle( | ||||||
isAccessibilityCategory, | ||||||
amountAndRewardTitleStackViewIsHidden: self.amountAndRewardTitleStackView.isHidden | ||||||
) | ||||||
|
||||||
_ = self.rootStackView | ||||||
|> checkoutAdaptableStackViewStyle( | ||||||
self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory | ||||||
) | ||||||
|> \.distribution .~ UIStackView.Distribution.equalCentering | ||||||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||||||
|> adaptableStackViewStyle(isAccessibilityCategory) | ||||||
|> \.isLayoutMarginsRelativeArrangement .~ true | ||||||
|> \.layoutMargins .~ UIEdgeInsets.init(topBottom: Styles.grid(3), leftRight: Styles.grid(3)) | ||||||
|
||||||
_ = self.amountAndRewardTitleStackView | ||||||
|> \.axis .~ NSLayoutConstraint.Axis.vertical | ||||||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||||||
|> \.isLayoutMarginsRelativeArrangement .~ true | ||||||
_ = self.youreABackerLabel | ||||||
|> \.font .~ UIFont.ksr_headline(size: 14) | ||||||
|> \.text %~ { _ in Strings.Youre_a_backer() } | ||||||
|> \.numberOfLines .~ 0 | ||||||
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. Same as above |
||||||
} | ||||||
|
||||||
// MARK: - Binding | ||||||
|
||||||
override func bindViewModel() { | ||||||
super.bindViewModel() | ||||||
|
||||||
self.pledgeCTAbutton.rac.title = self.vm.outputs.buttonTitleText | ||||||
self.pledgeCTAbutton.rac.backgroundColor = self.vm.outputs.buttonBackgroundColor | ||||||
self.amountAndRewardTitleStackView.rac.hidden = self.vm.outputs.stackViewIsHidden | ||||||
self.amountOrRewardLabel.rac.text = self.vm.outputs.rewardTitle | ||||||
self.pledgeCTAButton.rac.backgroundColor = self.vm.outputs.buttonBackgroundColor | ||||||
self.pledgeCTAButton.rac.title = self.vm.outputs.buttonTitleText | ||||||
self.spacer.rac.hidden = self.vm.outputs.spacerIsHidden | ||||||
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. We now also need to hide the spacer so we need 1 additional signal that should be tested as well |
||||||
} | ||||||
|
||||||
// MARK: - Configuration | ||||||
|
@@ -100,12 +111,31 @@ final class PledgeCTAContainerView: UIView { | |||||
|
||||||
// MARK: - Styles | ||||||
|
||||||
private let projectStateButtonStyle: ButtonStyle = { (button: UIButton) in | ||||||
button | ||||||
|> roundedStyle(cornerRadius: 12) | ||||||
|> UIButton.lens.titleColor(for: .normal) .~ .white | ||||||
|> UIButton.lens.titleLabel.font .~ .ksr_headline(size: 15) | ||||||
|> UIButton.lens.layer.borderWidth .~ 0 | ||||||
|> UIButton.lens.titleEdgeInsets .~ .init(topBottom: Styles.grid(1), leftRight: Styles.grid(2)) | ||||||
|> (UIButton.lens.titleLabel .. UILabel.lens.lineBreakMode) .~ .byWordWrapping | ||||||
private func adaptableStackViewStyle(_ isAccessibilityCategory: Bool) -> (StackViewStyle) { | ||||||
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. Using private style because we were only using 50% of the global checkout style which we would use and then had to change 2 props back to default...so this should be simpler |
||||||
return { (stackView: UIStackView) in | ||||||
let axis: NSLayoutConstraint.Axis = (isAccessibilityCategory ? .vertical : .horizontal) | ||||||
let spacing: CGFloat = (isAccessibilityCategory ? Styles.grid(1) : 0) | ||||||
|
||||||
return stackView | ||||||
|> \.axis .~ axis | ||||||
|> \.spacing .~ spacing | ||||||
} | ||||||
} | ||||||
|
||||||
private func pledgeCTAButtonStyle( | ||||||
_ isAccessibilityCategory: Bool, amountAndRewardTitleStackViewIsHidden: Bool | ||||||
) -> (ButtonStyle) { | ||||||
return { (button: UIButton) in | ||||||
let lineBreakMode: NSLineBreakMode = isAccessibilityCategory || amountAndRewardTitleStackViewIsHidden | ||||||
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.
This hopefully fixes the issue of not using 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. I think we want to avoid compression and hugging priorities if possible, seems like a good enough solution to change the |
||||||
? NSLineBreakMode.byWordWrapping : NSLineBreakMode.byTruncatingTail | ||||||
|
||||||
return button | ||||||
|> roundedStyle(cornerRadius: 12) | ||||||
|> UIButton.lens.titleColor(for: .normal) .~ UIColor.white | ||||||
|> UIButton.lens.titleLabel.font .~ UIFont.ksr_headline(size: 15) | ||||||
|> UIButton.lens.layer.borderWidth .~ 0 | ||||||
|> UIButton.lens.titleEdgeInsets .~ .init(topBottom: Styles.grid(1), leftRight: Styles.grid(2)) | ||||||
|> (UIButton.lens.titleLabel .. UILabel.lens.textAlignment) .~ NSTextAlignment.center | ||||||
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. |
||||||
|> (UIButton.lens.titleLabel .. UILabel.lens.lineBreakMode) .~ lineBreakMode | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ public protocol PledgeCTAContainerViewViewModelOutputs { | |
var buttonBackgroundColor: Signal<UIColor, Never> { get } | ||
var buttonTitleText: Signal<String, Never> { get } | ||
var rewardTitle: Signal<String, Never> { get } | ||
var spacerIsHidden: Signal<Bool, Never> { get } | ||
var stackViewIsHidden: Signal<Bool, Never> { get } | ||
} | ||
|
||
|
@@ -35,10 +36,12 @@ public final class PledgeCTAContainerViewViewModel: PledgeCTAContainerViewViewMo | |
} | ||
let backing = backingEvent.values() | ||
let projectAndBacking = Signal.combineLatest(project, backing) | ||
let stackViewAndSpacerAreHidden = pledgeState.map { $0.stackViewAndSpacerAreHidden } | ||
|
||
self.buttonTitleText = pledgeState.map { $0.buttonTitle } | ||
self.buttonBackgroundColor = pledgeState.map { $0.buttonBackgroundColor } | ||
self.stackViewIsHidden = pledgeState.map { $0.stackViewIsHidden } | ||
self.spacerIsHidden = stackViewAndSpacerAreHidden | ||
self.stackViewIsHidden = stackViewAndSpacerAreHidden | ||
|
||
self.rewardTitle = projectAndBacking | ||
.map { (project, backing) -> String in | ||
|
@@ -47,7 +50,7 @@ public final class PledgeCTAContainerViewViewModel: PledgeCTAContainerViewViewMo | |
basicPledge, | ||
country: project.country, | ||
omitCurrencyCode: project.stats.omitUSCurrencyCode | ||
) | ||
).trimmed() | ||
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. 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. This should probably be tested in our VM to make sure that the output is indeed trimmed. Current tests need better template values since those provided values are always trimmed. 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. We can pair on this |
||
guard let rewardTitle = backing.reward?.title else { return "\(amount)" } | ||
return "\(amount) • \(rewardTitle)" | ||
} | ||
|
@@ -64,6 +67,7 @@ public final class PledgeCTAContainerViewViewModel: PledgeCTAContainerViewViewMo | |
public let buttonBackgroundColor: Signal<UIColor, Never> | ||
public let buttonTitleText: Signal<String, Never> | ||
public let rewardTitle: Signal<String, Never> | ||
public let spacerIsHidden: Signal<Bool, Never> | ||
public let stackViewIsHidden: Signal<Bool, Never> | ||
} | ||
|
||
|
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.
Enabling auto layout in initializers thorough this file so that we don't have to combine it with style