Skip to content

Commit 5d0cef8

Browse files
authored
Merge pull request #7545 from woocommerce/issue/7518-add-learn-more-action
[Mobile Payments] Add a “Learn more” action to the connecting dialog
2 parents 07194b0 + 94a97e7 commit 5d0cef8

File tree

3 files changed

+92
-7
lines changed

3 files changed

+92
-7
lines changed

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalScanningForReader.swift

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ final class CardPresentModalScanningForReader: CardPresentPaymentsModalViewModel
77
private let cancelAction: () -> Void
88

99
let textMode: PaymentsModalTextMode = .reducedBottomInfo
10-
let actionsMode: PaymentsModalActionsMode = .secondaryOnlyAction
10+
let actionsMode: PaymentsModalActionsMode = .secondaryActionAndAuxiliaryButton
1111

1212
let topTitle: String = Localization.title
1313

@@ -21,6 +21,29 @@ final class CardPresentModalScanningForReader: CardPresentPaymentsModalViewModel
2121

2222
let auxiliaryButtonTitle: String? = nil
2323

24+
let auxiliaryButtonimage: UIImage? = .infoOutlineImage
25+
26+
var auxiliaryAttributedButtonTitle: NSAttributedString? {
27+
let result = NSMutableAttributedString(
28+
string: .localizedStringWithFormat(
29+
Localization.learnMoreText,
30+
Localization.learnMoreLink
31+
),
32+
attributes: [.foregroundColor: UIColor.text]
33+
)
34+
result.replaceFirstOccurrence(
35+
of: Localization.learnMoreLink,
36+
with: NSAttributedString(
37+
string: Localization.learnMoreLink,
38+
attributes: [
39+
.foregroundColor: UIColor.accent,
40+
.underlineStyle: NSUnderlineStyle.single.rawValue
41+
]
42+
))
43+
result.addAttribute(.font, value: UIFont.footnote, range: NSRange(location: 0, length: result.length))
44+
return result
45+
}
46+
2447
let bottomTitle: String? = Localization.instruction
2548

2649
var bottomSubtitle: String?
@@ -43,10 +66,20 @@ final class CardPresentModalScanningForReader: CardPresentPaymentsModalViewModel
4366
viewController?.dismiss(animated: true, completion: nil)
4467
}
4568

46-
func didTapAuxiliaryButton(in viewController: UIViewController?) {}
69+
func didTapAuxiliaryButton(in viewController: UIViewController?) {
70+
ServiceLocator.analytics.track(.cardPresentOnboardingLearnMoreTapped)
71+
guard let viewController = viewController else {
72+
return
73+
}
74+
WebviewHelper.launch(Constants.learnMoreURL.asURL(), with: viewController)
75+
}
4776
}
4877

4978
private extension CardPresentModalScanningForReader {
79+
enum Constants {
80+
static let learnMoreURL = WooConstants.URLs.inPersonPaymentsLearnMoreWCPay
81+
}
82+
5083
enum Localization {
5184
static let title = NSLocalizedString(
5285
"Scanning for reader",
@@ -62,5 +95,23 @@ private extension CardPresentModalScanningForReader {
6295
"Cancel",
6396
comment: "Label for a cancel button"
6497
)
98+
99+
static let learnMoreLink = NSLocalizedString(
100+
"Learn more",
101+
comment: """
102+
A label prompting users to learn more about In-Person Payments.
103+
This is the link to the website, and forms part of a longer sentence which it should be considered a part of.
104+
"""
105+
)
106+
107+
static let learnMoreText = NSLocalizedString(
108+
"%1$@ about In\u{2011}Person Payments",
109+
comment: """
110+
A label prompting users to learn more about In-Person Payments.
111+
\u{2011} is a special character that acts as nonbreaking hyphen for "-" in the "In-Person" string.
112+
%1$@ is a placeholder that always replaced with \"Learn more\" string,
113+
which should be translated separately and considered part of this sentence.
114+
"""
115+
)
65116
}
66117
}

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentPaymentsModalViewModel.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ protocol CardPresentPaymentsModalViewModel {
2727
/// Provides a title for an auxiliary button
2828
var auxiliaryButtonTitle: String? { get }
2929

30+
/// Provides a title as a NSAttributedString for an auxiliary button
31+
var auxiliaryAttributedButtonTitle: NSAttributedString? { get }
32+
33+
/// Provides an image for the auxiliary button
34+
var auxiliaryButtonimage: UIImage? { get }
35+
3036
/// The title in the bottom section of the modal. Right below the image
3137
var bottomTitle: String? { get }
3238

@@ -83,9 +89,25 @@ enum PaymentsModalActionsMode {
8389
/// One secondary action button
8490
case secondaryOnlyAction
8591

92+
/// One secondary action button and an auxiliary button
93+
case secondaryActionAndAuxiliaryButton
94+
8695
/// Two action buttons
8796
case twoAction
8897

8998
/// Two action buttons and an auxiliary button
9099
case twoActionAndAuxiliary
100+
101+
}
102+
103+
extension CardPresentPaymentsModalViewModel {
104+
/// Default implementation for NSAttributedString auxiliary button title.
105+
/// If is not set directly by each Modal's ViewModel, it will default to nil
106+
var auxiliaryAttributedButtonTitle: NSAttributedString? {
107+
get { return nil }
108+
}
109+
110+
var auxiliaryButtonimage: UIImage? {
111+
get { return nil }
112+
}
91113
}

WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ private extension CardPresentPaymentsModalViewController {
158158
}
159159

160160
func styleAuxiliaryButton() {
161-
auxiliaryButton.applyLinkButtonStyle()
162-
auxiliaryButton.titleLabel?.adjustsFontSizeToFitWidth = true
161+
if viewModel.actionsMode != .secondaryActionAndAuxiliaryButton {
162+
auxiliaryButton.applyLinkButtonStyle()
163+
}
163164
auxiliaryButton.titleLabel?.minimumScaleFactor = 0.5
165+
auxiliaryButton.titleLabel?.adjustsFontSizeToFitWidth = true
164166
}
165167

166168
func initializeContent() {
@@ -277,14 +279,24 @@ private extension CardPresentPaymentsModalViewController {
277279
}
278280

279281
func configureAuxiliaryButton() {
282+
280283
guard shouldShowAuxiliaryButton() else {
281284
auxiliaryButton.isHidden = true
282285
return
283286
}
284287

285-
auxiliaryButton.setTitleWithoutAnimation(viewModel.auxiliaryButtonTitle, for: .normal)
286288
auxiliaryButton.isHidden = false
287289
auxiliaryButton.accessibilityIdentifier = Accessibility.auxiliaryButton
290+
// Prevents UI flicker when loading different content
291+
UIView.performWithoutAnimation {
292+
auxiliaryButton.setTitle(viewModel.auxiliaryButtonTitle, for: .normal)
293+
auxiliaryButton.setAttributedTitle(viewModel.auxiliaryAttributedButtonTitle, for: .normal)
294+
auxiliaryButton.setImage(viewModel.auxiliaryButtonimage, for: .normal)
295+
if viewModel.auxiliaryButtonimage != nil {
296+
auxiliaryButton.distributeTitleAndImage(spacing: 8.0)
297+
}
298+
view.layoutIfNeeded()
299+
}
288300
}
289301

290302
func configureSpacer() {
@@ -338,12 +350,12 @@ private extension CardPresentPaymentsModalViewController {
338350
}
339351

340352
func shouldShowBottomActionButton() -> Bool {
341-
[.secondaryOnlyAction, .twoAction, .twoActionAndAuxiliary]
353+
[.secondaryOnlyAction, .twoAction, .twoActionAndAuxiliary, .secondaryActionAndAuxiliaryButton]
342354
.contains(viewModel.actionsMode)
343355
}
344356

345357
func shouldShowAuxiliaryButton() -> Bool {
346-
viewModel.actionsMode == .twoActionAndAuxiliary
358+
[.twoActionAndAuxiliary, .secondaryActionAndAuxiliaryButton].contains(viewModel.actionsMode)
347359
}
348360
}
349361

0 commit comments

Comments
 (0)