-
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
[MBL-1288] Update pledge CTA #2000
Changes from 4 commits
b5eed17
173a106
22640e3
755d10e
4c9a103
4094e35
21ffb0c
67be623
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 |
---|---|---|
|
@@ -29,6 +29,11 @@ final class PledgeViewCTAContainerView: UIView { | |
|
||
private lazy var termsTextView: UITextView = { UITextView(frame: .zero) |> \.delegate .~ self }() | ||
|
||
private lazy var pledgeImmediatelyLabel: UILabel = { | ||
UILabel(frame: .zero) | ||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||
}() | ||
|
||
private lazy var disclaimerStackView: UIStackView = { | ||
UIStackView(frame: .zero) | ||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||
|
@@ -84,6 +89,10 @@ final class PledgeViewCTAContainerView: UIView { | |
_ = self.termsTextView | ||
|> termsTextViewStyle | ||
|
||
self.pledgeImmediatelyLabel.attributedText = pledgeImmediatelyText() | ||
self.pledgeImmediatelyLabel.numberOfLines = 0 | ||
self.pledgeImmediatelyLabel.textAlignment = .center | ||
|
||
_ = self.disclaimerStackView | ||
|> disclaimerStackViewStyle | ||
|
||
|
@@ -139,6 +148,8 @@ final class PledgeViewCTAContainerView: UIView { | |
self.submitButton.rac.hidden = self.viewModel.outputs.submitButtonIsHidden | ||
self.submitButton.rac.title = self.viewModel.outputs.submitButtonTitle | ||
self.submitButton.rac.enabled = self.viewModel.outputs.submitButtonIsEnabled | ||
|
||
self.pledgeImmediatelyLabel.rac.hidden = self.viewModel.outputs.pledgeImmediatelyLabelIsHidden | ||
} | ||
|
||
// MARK: - Configuration | ||
|
@@ -157,7 +168,7 @@ final class PledgeViewCTAContainerView: UIView { | |
_ = ([self.continueButton, self.submitButton, self.applePayButton], self.ctaStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
|
||
_ = ([self.termsTextView], self.disclaimerStackView) | ||
_ = ([self.pledgeImmediatelyLabel, self.termsTextView], self.disclaimerStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
|
||
_ = ([self.ctaStackView, self.disclaimerStackView], self.rootStackView) | ||
|
@@ -241,7 +252,8 @@ private let ctaStackViewStyle: StackViewStyle = { stackView in | |
|
||
private let disclaimerStackViewStyle: StackViewStyle = { stackView in | ||
stackView | ||
|> \.axis .~ .horizontal | ||
|> \.axis .~ .vertical | ||
|> \.spacing .~ Styles.grid(2) | ||
|> \.layoutMargins .~ UIEdgeInsets.init( | ||
top: Styles.grid(0), | ||
left: Styles.grid(5), | ||
|
@@ -292,3 +304,55 @@ private func attributedTermsText() -> NSAttributedString? { | |
|
||
return checkoutAttributedLink(with: string) | ||
} | ||
|
||
private func pledgeImmediatelyText() -> NSAttributedString? { | ||
let rawText = Strings.Your_payment_method_will_be_charged() | ||
|
||
guard let text = try? NSMutableAttributedString( | ||
data: Data(rawText.utf8), | ||
options: [ | ||
.documentType: NSAttributedString.DocumentType.html, | ||
.characterEncoding: String.Encoding.utf8.rawValue | ||
], | ||
documentAttributes: nil | ||
) else { | ||
return nil | ||
} | ||
|
||
let attributes: String.Attributes = [ | ||
.font: UIFont.ksr_caption2(), | ||
.foregroundColor: UIColor.ksr_support_400 | ||
] | ||
|
||
let fullRange = (text.string as NSString).range(of: text.string) | ||
text.addAttributes(attributes, range: fullRange) | ||
|
||
let boldRanges = getBoldRangesFromHtmlTags(plainString: text.string, htmlString: rawText) | ||
for range in boldRanges { | ||
text.addAttribute(.font, value: UIFont.ksr_caption2().bolded, range: range) | ||
} | ||
|
||
return text | ||
} | ||
|
||
private func getBoldRangesFromHtmlTags(plainString: String, htmlString: String) -> [NSRange] { | ||
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. Nit: This should live in |
||
let stringWithoutHtml = plainString as NSString | ||
var boldRanges: [NSRange] = [] | ||
|
||
var currentString = htmlString as NSString | ||
while currentString.contains("<b>") { | ||
let startTagRange = currentString.range(of: "<b>") | ||
let endTagRange = currentString.range(of: "</b>") | ||
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. Nit: will this code break/infinite loop if there's no closing |
||
|
||
// Calculate range of bolded text in the string without html tags. | ||
let location = startTagRange.location | ||
let length = endTagRange.location - (location + startTagRange.length) | ||
let toBold = NSRange(location: location, length: length) | ||
boldRanges.append(toBold) | ||
|
||
let processedSubstring = stringWithoutHtml.substring(to: toBold.location + toBold.length) | ||
let remainingHtml = currentString.substring(from: endTagRange.location + endTagRange.length) | ||
currentString = (processedSubstring + remainingHtml) as NSString | ||
} | ||
return boldRanges | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,7 @@ final class RewardAddOnSelectionViewController: UIViewController { | |
.observeValues { [weak self] data in | ||
guard let self else { return } | ||
|
||
if featurePostCampaignPledgeEnabled(), data.project.isInPostCampaignPledgingPhase { | ||
if data.context == .latePledge { | ||
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. Nice 👍 |
||
self.goToConfirmDetails(data: data) | ||
} else { | ||
self.goToPledge(data: data) | ||
|
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.
Will the helper method
simpleHtmlAttributedString
do what you need, here? Or is the custom implementation required?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.
Oh nice find! I looked for something like this but clearly not hard enough - I really wasn't expecting us to already handle strings like this.