Skip to content

Commit aa4ad1d

Browse files
Remove unused amount label from PledgeShippingLocationViewController and shimmer view (#2641)
This is prep-work for fixing MBL-2832. Removing the amount label simplifies the view controller so we can decouple it from ShippingRule.
1 parent 28befed commit aa4ad1d

File tree

5 files changed

+41
-122
lines changed

5 files changed

+41
-122
lines changed

Kickstarter-iOS/Features/PledgeShippingLocation/PledgeShippingLocationViewController.swift

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ final class PledgeShippingLocationViewController: UIViewController {
2626
private let viewModel: PledgeShippingLocationViewModelType = PledgeShippingLocationViewModel()
2727

2828
private lazy var adaptableStackView: UIStackView = { UIStackView(frame: .zero) }()
29-
private lazy var amountLabel: UILabel = { UILabel(frame: .zero) }()
3029
private lazy var shippingLocationButton: UIButton = { UIButton(frame: .zero) }()
3130
private lazy var titleLabel: UILabel = { UILabel(frame: .zero) }()
3231
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
@@ -45,7 +44,7 @@ final class PledgeShippingLocationViewController: UIViewController {
4544
super.viewDidLoad()
4645

4746
_ = self
48-
|> \.accessibilityElements .~ [self.titleLabel, self.shippingLocationButton, self.amountLabel]
47+
|> \.accessibilityElements .~ [self.titleLabel, self.shippingLocationButton]
4948

5049
_ = (self.rootStackView, self.view)
5150
|> ksr_addSubviewToParent()
@@ -54,7 +53,7 @@ final class PledgeShippingLocationViewController: UIViewController {
5453
_ = ([self.titleLabel, self.adaptableStackView, self.shimmerLoadingView], self.rootStackView)
5554
|> ksr_addArrangedSubviewsToStackView()
5655

57-
_ = ([self.shippingLocationButton, self.spacer, self.amountLabel], self.adaptableStackView)
56+
_ = ([self.shippingLocationButton, self.spacer], self.adaptableStackView)
5857
|> ksr_addArrangedSubviewsToStackView()
5958

6059
self.shippingLocationButton.addTarget(
@@ -65,8 +64,6 @@ final class PledgeShippingLocationViewController: UIViewController {
6564

6665
self.spacer.widthAnchor.constraint(greaterThanOrEqualToConstant: Styles.grid(3)).isActive = true
6766

68-
self.amountLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
69-
7067
self.viewModel.inputs.viewDidLoad()
7168
}
7269

@@ -83,11 +80,6 @@ final class PledgeShippingLocationViewController: UIViewController {
8380
self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory
8481
)
8582

86-
_ = self.amountLabel
87-
|> checkoutBackgroundStyle
88-
_ = self.amountLabel
89-
|> amountLabelStyle
90-
9183
_ = self.shippingLocationButton
9284
|> countryButtonStyle
9385
|> checkoutWhiteBackgroundStyle
@@ -112,31 +104,21 @@ final class PledgeShippingLocationViewController: UIViewController {
112104
super.bindViewModel()
113105

114106
self.adaptableStackView.rac.hidden = self.viewModel.outputs.adaptableStackViewIsHidden
115-
self.amountLabel.rac.attributedText = self.viewModel.outputs.amountAttributedText
116-
self.amountLabel.rac.hidden = self.viewModel.outputs.amountLabelIsHidden
117107
self.shimmerLoadingView.rac.hidden = self.viewModel.outputs.shimmerLoadingViewIsHidden
118108
self.shippingLocationButton.rac.title = self.viewModel.outputs.shippingLocationButtonTitle
119109

120-
self.viewModel.outputs.amountLabelIsHidden
121-
.observeForUI()
122-
.observeValues { [weak self] isHidden in
123-
self?.shimmerLoadingView.amountPlaceholder.alpha = isHidden ? 0 : 1
124-
}
125-
126110
/**
127111
When any layout updates occur we need to notify the delegate. This is only necessary when
128112
this view is contained within a view that is not fully supported by Auto Layout,
129113
e.g. a `UITableView` header.
130114
*/
131115
Signal.combineLatest(
132116
self.viewModel.outputs.adaptableStackViewIsHidden,
133-
self.viewModel.outputs.amountAttributedText,
134-
self.viewModel.outputs.amountLabelIsHidden,
135117
self.viewModel.outputs.shimmerLoadingViewIsHidden,
136118
self.viewModel.outputs.shippingLocationButtonTitle
137119
)
138120
.observeForUI()
139-
.observeValues { [weak self] _, _, _, shimmerLoadingViewIsHidden, _ in
121+
.observeValues { [weak self] _, shimmerLoadingViewIsHidden, _ in
140122
guard let self = self else { return }
141123
self.delegate?.pledgeShippingLocationViewControllerLayoutDidUpdate(self, shimmerLoadingViewIsHidden)
142124
}

Kickstarter-iOS/SharedViews/PledgeShippingLocationShimmerLoadingView.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import UIKit
66
final class PledgeShippingLocationShimmerLoadingView: UIView {
77
// MARK: - Properties
88

9-
internal lazy var amountPlaceholder: UIView = { UIView(frame: .zero) }()
109
private lazy var buttonPlaceholder: UIView = { UIView(frame: .zero) }()
1110
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
1211

@@ -41,9 +40,6 @@ final class PledgeShippingLocationShimmerLoadingView: UIView {
4140

4241
_ = self.buttonPlaceholder
4342
|> roundedStyle(cornerRadius: Styles.gridHalf(3))
44-
45-
_ = self.amountPlaceholder
46-
|> roundedStyle(cornerRadius: Styles.gridHalf(3))
4743
}
4844

4945
// MARK: - Subviews
@@ -53,16 +49,14 @@ final class PledgeShippingLocationShimmerLoadingView: UIView {
5349
|> ksr_addSubviewToParent()
5450
|> ksr_constrainViewToEdgesInParent()
5551

56-
_ = ([self.buttonPlaceholder, UIView(), self.amountPlaceholder], self.rootStackView)
52+
_ = ([self.buttonPlaceholder, UIView()], self.rootStackView)
5753
|> ksr_addArrangedSubviewsToStackView()
5854
}
5955

6056
private func setupConstraints() {
6157
NSLayoutConstraint.activate([
6258
self.buttonPlaceholder.heightAnchor.constraint(equalToConstant: Styles.grid(3)),
63-
self.amountPlaceholder.heightAnchor.constraint(equalToConstant: Styles.grid(3)),
64-
self.buttonPlaceholder.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.4),
65-
self.amountPlaceholder.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.2)
59+
self.buttonPlaceholder.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.4)
6660
])
6761
}
6862
}
@@ -71,6 +65,6 @@ final class PledgeShippingLocationShimmerLoadingView: UIView {
7165

7266
extension PledgeShippingLocationShimmerLoadingView: ShimmerLoading {
7367
func shimmerViews() -> [UIView] {
74-
return [self.amountPlaceholder, self.buttonPlaceholder]
68+
return [self.buttonPlaceholder]
7569
}
7670
}

Library/ViewModels/PledgeShippingLocationViewModel.swift

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import Prelude
44
import ReactiveExtensions
55
import ReactiveSwift
66

7-
public typealias PledgeShippingLocationViewData = (
8-
project: Project,
9-
reward: Reward,
10-
showAmount: Bool,
11-
selectedLocationId: Int?
12-
)
7+
public struct PledgeShippingLocationViewData {
8+
let project: Project
9+
let selectedLocationId: Int?
10+
}
1311

1412
public protocol PledgeShippingLocationViewModelInputs {
1513
func configureWith(data: PledgeShippingLocationViewData)
@@ -21,8 +19,6 @@ public protocol PledgeShippingLocationViewModelInputs {
2119

2220
public protocol PledgeShippingLocationViewModelOutputs {
2321
var adaptableStackViewIsHidden: Signal<Bool, Never> { get }
24-
var amountAttributedText: Signal<NSAttributedString, Never> { get }
25-
var amountLabelIsHidden: Signal<Bool, Never> { get }
2622
var dismissShippingRules: Signal<Void, Never> { get }
2723
var presentShippingRules: Signal<(Project, [ShippingRule], ShippingRule), Never> { get }
2824
var notifyDelegateOfSelectedShippingRule: Signal<ShippingRule, Never> { get }
@@ -47,17 +43,15 @@ public final class PledgeShippingLocationViewModel: PledgeShippingLocationViewMo
4743
.map(first)
4844

4945
let project = configData
50-
.map { $0.0 }
51-
let reward = configData
52-
.map { $0.1 }
46+
.map { $0.project }
5347
let selectedLocationId = configData
54-
.map { $0.3 }
48+
.map { $0.selectedLocationId }
5549

56-
let shippingShouldBeginLoading = reward
50+
let shippingShouldBeginLoading = project
5751
.mapConst(true)
5852

59-
let shippingRulesEvent = Signal.zip(project, reward)
60-
.switchMap { project, _ -> SignalProducer<Signal<[ShippingRule], ErrorEnvelope>.Event, Never> in
53+
let shippingRulesEvent = project
54+
.switchMap { project -> SignalProducer<Signal<[ShippingRule], ErrorEnvelope>.Event, Never> in
6155
getShippingRulesForAllRewards(in: project)
6256
}
6357

@@ -92,22 +86,13 @@ public final class PledgeShippingLocationViewModel: PledgeShippingLocationViewMo
9286
self.shippingRuleUpdatedSignal
9387
)
9488

95-
let shippingAmount = Signal.merge(
96-
self.notifyDelegateOfSelectedShippingRule.map { $0.cost },
97-
configData.mapConst(0)
98-
)
99-
10089
self.presentShippingRules = Signal.combineLatest(
10190
project,
10291
shippingRulesEvent.values(),
10392
self.notifyDelegateOfSelectedShippingRule
10493
)
10594
.takeWhen(self.shippingLocationButtonTappedSignal)
10695

107-
self.amountAttributedText = Signal.combineLatest(project, shippingAmount)
108-
.map { project, shippingAmount in shippingValue(of: project, with: shippingAmount) }
109-
.skipNil()
110-
11196
self.shippingLocationButtonTitle = self.notifyDelegateOfSelectedShippingRule
11297
.map { $0.location.localizedName }
11398

@@ -117,8 +102,6 @@ public final class PledgeShippingLocationViewModel: PledgeShippingLocationViewMo
117102
.ignoreValues()
118103
.ksr_debounce(.milliseconds(300), on: AppEnvironment.current.scheduler)
119104
)
120-
121-
self.amountLabelIsHidden = configData.map { $0.2 }.negate()
122105
}
123106

124107
private let configDataProperty = MutableProperty<PledgeShippingLocationViewData?>(nil)
@@ -148,8 +131,6 @@ public final class PledgeShippingLocationViewModel: PledgeShippingLocationViewMo
148131
}
149132

150133
public let adaptableStackViewIsHidden: Signal<Bool, Never>
151-
public let amountAttributedText: Signal<NSAttributedString, Never>
152-
public let amountLabelIsHidden: Signal<Bool, Never>
153134
public let dismissShippingRules: Signal<Void, Never>
154135
public let presentShippingRules: Signal<(Project, [ShippingRule], ShippingRule), Never>
155136
public let notifyDelegateOfSelectedShippingRule: Signal<ShippingRule, Never>

0 commit comments

Comments
 (0)