Skip to content

Commit

Permalink
Merge branch 'main' into feat/adyer/mbl-1965
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-at-kickstarter committed Jan 29, 2025
2 parents 0eded2e + 631e6bf commit 9e0909e
Show file tree
Hide file tree
Showing 103 changed files with 1,537 additions and 1,274 deletions.
5 changes: 5 additions & 0 deletions Kickstarter-iOS/AppDelegateViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,13 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
return
}

let ppoSettings = user
.flatMap { $0.me.ppoHasAction }
.flatMap { PPOUserSettings(hasAction: $0) }

AppEnvironment.replaceCurrentEnvironment(
currentUserEmail: email,
currentUserPPOSettings: ppoSettings,
currentUserServerFeatures: features
)
NotificationCenter.default.post(.init(name: .ksr_userUpdated))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,9 @@ final class ConfirmDetailsViewController: UIViewController, MessageBannerViewCon

// MARK: - Functions

private func goToLoginSignup(with intent: LoginIntent, project: Project, reward: Reward?) {
private func goToLoginSignup(with intent: LoginIntent, project _: Project, reward _: Reward?) {
let loginSignupViewController = LoginToutViewController.configuredWith(
loginIntent: intent,
project: project,
reward: reward
loginIntent: intent
)

let navigationController = UINavigationController(rootViewController: loginSignupViewController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ public final class LoginToutViewController: UIViewController, MFMailComposeViewC
// MARK: - Configuration

public static func configuredWith(
loginIntent intent: LoginIntent,
project: Project? = nil,
reward: Reward? = nil
loginIntent intent: LoginIntent
) -> LoginToutViewController {
let vc = LoginToutViewController.instantiate()
vc.viewModel.inputs.configureWith(intent, project: project, reward: reward)
vc.viewModel.inputs.configureWith(intent)
vc.helpViewModel.inputs.configureWith(helpContext: .loginTout)
vc.helpViewModel.inputs.canSendEmail(MFMailComposeViewController.canSendMail())
return vc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ final class PledgeOverTimePaymentScheduleViewController: UIViewController {
self.paymentsScheduleStackView.isHidden = true
self.titleLabel.text = Strings.Payment_schedule()

self.termsOfUseButton.setContentCompressionResistancePriority(.required, for: .vertical)
self.termsOfUseButton.setAttributedTitle(
NSAttributedString(
string: Strings.login_tout_help_sheet_terms(),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions Kickstarter-iOS/Features/ManagePledge/Views/BadgeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Library
import UIKit

private enum Constants {
/// Spacing & Padding
public static let badgeTopButtonPadding = 6.0
public static let badgeLeadingTrailingPadding = 8.0
public static let defaultStackViewSpacing = Styles.grid(1)

/// Corner radius
public static let defaultCornerRadius = Styles.grid(1)
}

final class BadgeView: UIView {
// MARK: - Properties

private lazy var badgeLabel: UILabel = { UILabel(frame: .zero) }()

// MARK: - Lifecycle

override init(frame: CGRect) {
super.init(frame: frame)

self.configureSubviews()
self.bindStyles()
self.setupConstraints()
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Configuration

private func configureSubviews() {
self.addSubview(self.badgeLabel)
}

private func setupConstraints() {
self.badgeLabel.translatesAutoresizingMaskIntoConstraints = false
self.badgeLabel.setContentHuggingPriority(.required, for: .horizontal)
self.badgeLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
self.badgeLabel.setContentHuggingPriority(.required, for: .vertical)
self.badgeLabel.setContentCompressionResistancePriority(.required, for: .vertical)

NSLayoutConstraint.activate([
self.badgeLabel.topAnchor.constraint(
equalTo: self.topAnchor,
constant: Constants.badgeTopButtonPadding
),
self.badgeLabel.bottomAnchor.constraint(
equalTo: self.bottomAnchor,
constant: -Constants.badgeTopButtonPadding
),
self.badgeLabel.leadingAnchor.constraint(
equalTo: self.leadingAnchor,
constant: Constants.badgeLeadingTrailingPadding
),
self.badgeLabel.trailingAnchor.constraint(
equalTo: self.trailingAnchor,
constant: -Constants.badgeLeadingTrailingPadding
)
])
}

public func configure(with text: String) {
self.badgeLabel.text = text
}

// MARK: - Styles

override func bindStyles() {
super.bindStyles()

applyBadgeViewStyle(self)
applyBadgeLabelStyle(self.badgeLabel)
}
}

private func applyBadgeViewStyle(_ view: UIView) {
view.backgroundColor = .ksr_create_100
view.rounded(with: Constants.defaultCornerRadius)
}

private func applyBadgeLabelStyle(_ label: UILabel) {
label.font = UIFont.ksr_subhead().bolded
label.textColor = .ksr_create_700
label.textAlignment = .center
label.numberOfLines = 1
label.adjustsFontForContentSizeCategory = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import UIKit
final class PledgeStatusLabelView: UIView {
// MARK: - Properties

private lazy var containerView: UIView = { UIView(frame: .zero) }()
private lazy var label: UILabel = { UILabel(frame: .zero) }()
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var textView = { UITextView(frame: .zero) }()
private lazy var badgeView = { BadgeView(frame: .zero) }()

private let viewModel: PledgeStatusLabelViewModelType = PledgeStatusLabelViewModel()

Expand All @@ -31,29 +32,37 @@ final class PledgeStatusLabelView: UIView {
override func bindStyles() {
super.bindStyles()

_ = self.containerView
_ = self.rootStackView
|> containerViewStyle

_ = self.label
|> labelStyle
applyTextViewStyle(self.textView)
}

private func configureSubviews() {
_ = (self.containerView, self)
_ = (self.rootStackView, self)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = (self.label, self.containerView)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToMarginsInParent()
self.badgeView.configure(with: Strings.Beta())
self.badgeView.isHidden = true

applyRootStackViewStyle(self.rootStackView)

self.rootStackView.addArrangedSubviews(self.badgeView, self.textView)
}

// MARK: - View model

override func bindViewModel() {
super.bindViewModel()

self.label.rac.attributedText = self.viewModel.outputs.labelText
self.viewModel.outputs.labelText
.observeForUI()
.observeValues { attributedText in
self.textView.attributedText = attributedText
}

self.badgeView.rac.hidden = self.viewModel.outputs.badgeHidden
}

// MARK: - Configuration
Expand All @@ -72,10 +81,26 @@ private let containerViewStyle: ViewStyle = { (view: UIView) in
|> roundedStyle()
}

private let labelStyle: LabelStyle = { (label: UILabel) in
label
|> \.adjustsFontForContentSizeCategory .~ true
|> \.isAccessibilityElement .~ true
|> \.numberOfLines .~ 0
|> \.backgroundColor .~ .ksr_support_200
private func applyRootStackViewStyle(_ stackView: UIStackView) {
stackView.backgroundColor = .ksr_support_200
stackView.isLayoutMarginsRelativeArrangement = true
stackView.layoutMargins = .init(all: Styles.grid(2))
stackView.rounded()
stackView.axis = .vertical
stackView.alignment = .center
stackView.spacing = Styles.grid(2)
}

private func applyTextViewStyle(_ textView: UITextView) {
textView.accessibilityTraits = [.staticText]
textView.backgroundColor = .ksr_support_200
textView.isScrollEnabled = false
textView.isEditable = false
textView.isUserInteractionEnabled = true
textView.adjustsFontForContentSizeCategory = true
textView.textContainerInset = .zero
textView.textContainer.lineFragmentPadding = 0
textView.linkTextAttributes = [
.foregroundColor: UIColor.ksr_create_700
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ final class NoShippingPledgeViewController: UIViewController,

private var paymentSectionLabel: UILabel = { UILabel(frame: .zero) }()

private lazy var pledgeAmountViewController = {
PledgeAmountViewController.instantiate()
|> \.delegate .~ self
}()

internal var processingView: ProcessingView? = ProcessingView(frame: .zero)
private lazy var pledgeDisclaimerView: PledgeDisclaimerView = {
PledgeDisclaimerView(frame: .zero)
Expand Down Expand Up @@ -305,12 +300,6 @@ final class NoShippingPledgeViewController: UIViewController,
self?.pledgeRewardsSummaryViewController.configureWith(pledgeOverTimeData: data)
}

self.viewModel.outputs.configurePledgeAmountViewWithData
.observeForUI()
.observeValues { [weak self] data in
self?.pledgeAmountViewController.configureWith(value: data)
}

self.viewModel.outputs.configurePledgeAmountSummaryViewControllerWithData
.observeForUI()
.observeValues { [weak self] data in
Expand All @@ -337,12 +326,6 @@ final class NoShippingPledgeViewController: UIViewController,
self?.pledgeCTAContainerView.configureWith(value: value)
}

self.viewModel.outputs.notifyPledgeAmountViewControllerUnavailableAmountChanged
.observeForUI()
.observeValues { [weak self] amount in
self?.pledgeAmountViewController.unavailableAmountChanged(to: amount)
}

self.viewModel.outputs.configurePaymentMethodsViewControllerWithValue
.observeForUI()
.observeValues { [weak self] value in
Expand All @@ -351,8 +334,8 @@ final class NoShippingPledgeViewController: UIViewController,

self.viewModel.outputs.goToLoginSignup
.observeForControllerAction()
.observeValues { [weak self] intent, project, reward in
self?.goToLoginSignup(with: intent, project: project, reward: reward)
.observeValues { [weak self] intent in
self?.goToLoginSignup(with: intent)
}

self.sessionStartedObserver = NotificationCenter.default
Expand Down Expand Up @@ -394,7 +377,6 @@ final class NoShippingPledgeViewController: UIViewController,

self.localPickupLocationView.rac.hidden = self.viewModel.outputs.localPickupViewHidden
self.paymentMethodsViewController.view.rac.hidden = self.viewModel.outputs.paymentMethodsViewHidden
self.pledgeAmountViewController.view.rac.hidden = self.viewModel.outputs.pledgeAmountViewHidden

self.viewModel.outputs.title
.observeForUI()
Expand Down Expand Up @@ -429,12 +411,6 @@ final class NoShippingPledgeViewController: UIViewController,
.observeValues { [weak self] errorMessage in
self?.messageBannerViewController?.showBanner(with: .error, message: errorMessage)
}

self.viewModel.outputs.showApplePayAlert
.observeForControllerAction()
.observeValues { [weak self] title, message in
self?.presentApplePayInvalidAmountAlert(title: title, message: message)
}
}

private func goToPaymentAuthorization(_ paymentAuthorizationData: PaymentAuthorizationData) {
Expand All @@ -461,10 +437,6 @@ final class NoShippingPledgeViewController: UIViewController,
self.navigationController?.pushViewController(thanksVC, animated: true)
}

private func presentApplePayInvalidAmountAlert(title: String, message: String) {
self.present(UIAlertController.alert(title, message: message), animated: true)
}

// MARK: - Actions

@objc private func dismissKeyboard() {
Expand Down Expand Up @@ -498,11 +470,9 @@ final class NoShippingPledgeViewController: UIViewController,
self.estimatedShippingStackView.layoutIfNeeded()
}

private func goToLoginSignup(with intent: LoginIntent, project: Project, reward: Reward) {
private func goToLoginSignup(with intent: LoginIntent) {
let loginSignupViewController = LoginToutViewController.configuredWith(
loginIntent: intent,
project: project,
reward: reward
loginIntent: intent
)

let navigationController = UINavigationController(rootViewController: loginSignupViewController)
Expand Down Expand Up @@ -562,17 +532,6 @@ final class NoShippingPledgeViewController: UIViewController,
}
}

// MARK: - PledgeAmountViewControllerDelegate

extension NoShippingPledgeViewController: PledgeAmountViewControllerDelegate {
func pledgeAmountViewController(
_: PledgeAmountViewController,
didUpdateWith data: PledgeAmountData
) {
self.viewModel.inputs.pledgeAmountViewControllerDidUpdate(with: data)
}
}

// MARK: - STPAuthenticationContext

extension NoShippingPledgeViewController: STPAuthenticationContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ final class NoShippingPledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [nonReward],
bonusSupport: 1.0,
selectedShippingRule: shippingRule,
selectedQuantities: [nonReward.id: 1],
selectedLocationId: ShippingRule.template.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ final class NoShippingPostCampaignCheckoutViewController: UIViewController,

self.viewModel.outputs.goToLoginSignup
.observeForControllerAction()
.observeValues { [weak self] intent, project, reward in
self?.goToLoginSignup(with: intent, project: project, reward: reward)
.observeValues { [weak self] intent in
self?.goToLoginSignup(with: intent)
}

self.viewModel.outputs.validateCheckoutSuccess
Expand Down Expand Up @@ -325,11 +325,9 @@ final class NoShippingPostCampaignCheckoutViewController: UIViewController,

// MARK: - Functions

private func goToLoginSignup(with intent: LoginIntent, project: Project, reward: Reward) {
private func goToLoginSignup(with intent: LoginIntent) {
let loginSignupViewController = LoginToutViewController.configuredWith(
loginIntent: intent,
project: project,
reward: reward
loginIntent: intent
)

let navigationController = UINavigationController(rootViewController: loginSignupViewController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,9 @@ final class PledgeViewController: UIViewController,
self.pledgeDisclaimerView.configure(with: ("icon-not-a-store", attributedText))
}

private func goToLoginSignup(with intent: LoginIntent, project: Project, reward: Reward) {
private func goToLoginSignup(with intent: LoginIntent, project _: Project, reward _: Reward) {
let loginSignupViewController = LoginToutViewController.configuredWith(
loginIntent: intent,
project: project,
reward: reward
loginIntent: intent
)

let navigationController = UINavigationController(rootViewController: loginSignupViewController)
Expand Down
Loading

0 comments on commit 9e0909e

Please sign in to comment.