-
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] Shipping Picker - Navigation Workflow - 1/4 #738
Changes from 21 commits
61304be
679e925
984c9dc
0b5c286
7acbf60
f4b9773
b9ba115
81a80f6
4d95e88
bc80e17
7393789
8e464e5
7c412a6
c4ecb5b
595d125
b9aa1fa
5579fac
8f50d34
edffb9f
1851a3d
3d6fc62
67bdad5
570ed94
390f15c
d02aa04
6f0d173
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 |
---|---|---|
|
@@ -3,6 +3,12 @@ import Library | |
import Prelude | ||
import UIKit | ||
|
||
private enum Layout { | ||
enum Sheet { | ||
static let offset: CGFloat = 200 | ||
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 fine for different device sizes? 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. Yeah, it looks like we need enough space to still show the shipping location cell behind the modal. |
||
} | ||
} | ||
|
||
class PledgeTableViewController: UITableViewController { | ||
// MARK: - Properties | ||
|
||
|
@@ -67,6 +73,14 @@ class PledgeTableViewController: UITableViewController { | |
} | ||
} | ||
|
||
self.viewModel.outputs.presentShippingRules | ||
.observeForUI() | ||
.observeValues { [weak self] project, shippingRules, selectedShippingRule in | ||
self?.presentShippingRules( | ||
project, shippingRules: shippingRules, selectedShippingRule: selectedShippingRule | ||
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. The argument naming here is fine because |
||
) | ||
} | ||
|
||
self.viewModel.outputs.configureShippingLocationCellWithData | ||
.observeForUI() | ||
.observeValues { [weak self] isLoading, project, selectedShippingRule in | ||
|
@@ -82,12 +96,6 @@ class PledgeTableViewController: UITableViewController { | |
} | ||
} | ||
|
||
// MARK: - Actions | ||
|
||
@objc func dismissKeyboard() { | ||
self.tableView.endEditing(true) | ||
} | ||
|
||
// MARK: - UITableViewDelegate | ||
|
||
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { | ||
|
@@ -118,10 +126,24 @@ class PledgeTableViewController: UITableViewController { | |
|
||
// MARK: - Actions | ||
|
||
@objc func dismissKeyboard() { | ||
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. Little bit of reordering #boyScoutRule |
||
self.tableView.endEditing(true) | ||
} | ||
|
||
private func presentHelpWebViewController(with helpType: HelpType) { | ||
let vc = HelpWebViewController.configuredWith(helpType: helpType) | ||
let nav = UINavigationController(rootViewController: vc) | ||
self.present(nav, animated: true, completion: nil) | ||
let nc = UINavigationController(rootViewController: vc) | ||
self.present(nc, animated: true) | ||
} | ||
|
||
private func presentShippingRules( | ||
_: Project, shippingRules _: [ShippingRule], selectedShippingRule _: ShippingRule | ||
) { | ||
let vc = UIViewController() | ||
vc.view.backgroundColor = UIColor.cyan | ||
let nc = UINavigationController(rootViewController: vc) | ||
let sheetVC = SheetOverlayViewController(child: nc, offset: Layout.Sheet.offset) | ||
self.present(sheetVC, animated: true) | ||
} | ||
} | ||
|
||
|
@@ -131,9 +153,9 @@ extension PledgeTableViewController: PledgeDescriptionCellDelegate { | |
} | ||
} | ||
|
||
extension PledgeTableViewController: PledgeSummaryCellDelegate { | ||
internal func pledgeSummaryCell(_: PledgeSummaryCell, didOpen helpType: HelpType) { | ||
self.presentHelpWebViewController(with: helpType) | ||
extension PledgeTableViewController: PledgeAmountCellDelegate { | ||
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. Delegate conformance sorted alphabetically now |
||
func pledgeAmountCell(_: PledgeAmountCell, didUpdateAmount amount: Double) { | ||
self.viewModel.inputs.pledgeAmountDidUpdate(to: amount) | ||
} | ||
} | ||
|
||
|
@@ -143,9 +165,9 @@ extension PledgeTableViewController: PledgeShippingLocationCellDelegate { | |
} | ||
} | ||
|
||
extension PledgeTableViewController: PledgeAmountCellDelegate { | ||
func pledgeAmountCell(_: PledgeAmountCell, didUpdateAmount amount: Double) { | ||
self.viewModel.inputs.pledgeAmountDidUpdate(to: amount) | ||
extension PledgeTableViewController: PledgeSummaryCellDelegate { | ||
internal func pledgeSummaryCell(_: PledgeSummaryCell, didOpen helpType: HelpType) { | ||
self.presentHelpWebViewController(with: helpType) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ import ReactiveSwift | |
|
||
public protocol PledgeShippingLocationCellViewModelInputs { | ||
func configureWith(isLoading: Bool, project: Project, selectedShippingRule: ShippingRule?) | ||
func shippingLocationButtonTapped() | ||
} | ||
|
||
public protocol PledgeShippingLocationCellViewModelOutputs { | ||
var amountAttributedText: Signal<NSAttributedString, Never> { get } | ||
var shippingLocationButtonTitle: Signal<String, Never> { get } | ||
var shippingLocationSelected: Signal<ShippingRule, Never> { get } | ||
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. Not |
||
} | ||
|
||
public protocol PledgeShippingLocationCellViewModelType { | ||
|
@@ -32,15 +34,25 @@ public final class PledgeShippingLocationCellViewModel: PledgeShippingLocationCe | |
|
||
self.shippingLocationButtonTitle = projectAndSelectedShippingRule | ||
.map { _, selectedShippingRule in selectedShippingRule.location.localizedName } | ||
|
||
self.shippingLocationSelected = projectAndSelectedShippingRule | ||
.map(second) | ||
.takeWhen(self.shippingLocationButtonTappedProperty.signal) | ||
} | ||
|
||
private let configDataProperty = MutableProperty<(Bool, Project, ShippingRule?)?>(nil) | ||
public func configureWith(isLoading: Bool, project: Project, selectedShippingRule: ShippingRule?) { | ||
self.configDataProperty.value = (isLoading, project, selectedShippingRule) | ||
} | ||
|
||
private let shippingLocationButtonTappedProperty = MutableProperty(()) | ||
public func shippingLocationButtonTapped() { | ||
self.shippingLocationButtonTappedProperty.value = () | ||
} | ||
|
||
public let amountAttributedText: Signal<NSAttributedString, Never> | ||
public let shippingLocationButtonTitle: Signal<String, Never> | ||
public let shippingLocationSelected: Signal<ShippingRule, Never> | ||
|
||
public var inputs: PledgeShippingLocationCellViewModelInputs { return self } | ||
public var outputs: PledgeShippingLocationCellViewModelOutputs { return self } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ public protocol PledgeViewModelOutputs { | |
recycled it will be reloaded with its most recent data. | ||
*/ | ||
var pledgeViewDataAndReload: Signal<(PledgeViewData, Bool), Never> { get } | ||
var presentShippingRules: Signal<[ShippingRule], Never> { get } | ||
var presentShippingRules: Signal<(Project, [ShippingRule], ShippingRule), Never> { get } | ||
var shippingRulesError: Signal<String, Never> { get } | ||
} | ||
|
||
|
@@ -74,15 +74,20 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge | |
.materialize() | ||
} | ||
|
||
self.presentShippingRules = shippingRulesEvent.values() | ||
|
||
let selectedShippingRule = Signal.merge( | ||
let defaultShippingRule = Signal.merge( | ||
self.viewDidLoadProperty.signal.mapConst(nil), | ||
self.presentShippingRules.map(defaultShippingRule(fromShippingRules:)) | ||
shippingRulesEvent.values().map(defaultShippingRule(fromShippingRules:)) | ||
) | ||
|
||
self.presentShippingRules = Signal.combineLatest( | ||
project, | ||
shippingRulesEvent.values(), | ||
defaultShippingRule.skipNil() | ||
) | ||
.takeWhen(self.shippingRuleSignal.signal) | ||
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.
So perhaps the delegate should be: func pledgeShippingCellWillPresentShippingRules(_: PledgeShippingLocationCell, selectedShippingRule rule: ShippingRule)
// or
func pledgeShippingCellPresentedShippingRules(_: PledgeShippingLocationCell, selectedShippingRule rule: ShippingRule) I think we can then base the view model input on that and it should improve the signal naming. |
||
|
||
let shippingAmount = Signal.merge( | ||
selectedShippingRule.skipNil().map { $0.cost }, | ||
defaultShippingRule.skipNil().map { $0.cost }, | ||
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. Renaming as this is the |
||
self.shippingRuleSignal.map { $0.cost }, | ||
projectAndReward.mapConst(0) | ||
) | ||
|
@@ -102,7 +107,7 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge | |
let pledgeTotal = Signal.combineLatest(pledgeAmount, shippingAmount).map(+) | ||
|
||
let data = Signal | ||
.combineLatest(project, reward, isLoggedIn, isShippingLoading, selectedShippingRule, pledgeTotal) | ||
.combineLatest(project, reward, isLoggedIn, isShippingLoading, defaultShippingRule, pledgeTotal) | ||
.map(pledgeViewData(with:reward:isLoggedIn:isShippingLoading:selectedShippingRule:pledgeTotal:)) | ||
|
||
self.pledgeViewDataAndReload = Signal.merge( | ||
|
@@ -120,7 +125,7 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge | |
|
||
let isShippingLoadingAndSelectedShippingRule = Signal.combineLatest( | ||
isShippingLoading, | ||
selectedShippingRule | ||
defaultShippingRule | ||
) | ||
|
||
self.configureShippingLocationCellWithData = updatedData | ||
|
@@ -154,7 +159,7 @@ public class PledgeViewModel: PledgeViewModelType, PledgeViewModelInputs, Pledge | |
public let configureShippingLocationCellWithData: Signal<(Bool, Project, ShippingRule?), Never> | ||
public let configureSummaryCellWithData: Signal<(Project, Double), Never> | ||
public let pledgeViewDataAndReload: Signal<(PledgeViewData, Bool), Never> | ||
public let presentShippingRules: Signal<[ShippingRule], Never> | ||
public let presentShippingRules: Signal<(Project, [ShippingRule], ShippingRule), Never> | ||
public let shippingRulesError: Signal<String, Never> | ||
|
||
public var inputs: PledgeViewModelInputs { return self } | ||
|
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.
Seeing as
ShippingRule
is a type that explains this at the callsite, we can actually make this: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.
See later comment, I now realize exactly what the delegate is doing, it's really just presenting the rules, the actual selection will happen elsewhere.