-
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
[NT-361] Select new reward polish #899
Changes from 43 commits
3a5e5bd
fffa982
f933d99
97f4cd8
02f290e
02bebe8
82b6642
a4b8ffd
e70e2e6
5cbf40b
afa9c9a
e2b3afd
1d69e99
c189ebe
031ebc2
b1de7b0
7c9f91c
5a03263
30e77cc
891f50b
5bf6de3
3a6ae51
189adbe
5ae6f86
d68df53
a8092af
d65823d
4c49d3a
0ed69e0
6d7bf10
43c7655
319688f
4445e9b
f6a3f26
c079a94
d406f97
7d6991c
fbb661d
311f48e
c84f8ad
88ba19b
38ac910
044fcef
b294416
cd582dd
c0cfd26
bd02acd
880355e
d6261bb
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 |
---|---|---|
|
@@ -5,24 +5,32 @@ import ReactiveSwift | |
|
||
public typealias PledgeData = (project: Project, reward: Reward, refTag: RefTag?) | ||
|
||
public enum RewardsCollectionViewContext { | ||
case createPledge | ||
case managePledge | ||
} | ||
|
||
public protocol RewardsCollectionViewModelInputs { | ||
func configure(with project: Project, refTag: RefTag?) | ||
func configure(with project: Project, refTag: RefTag?, context: RewardsCollectionViewContext) | ||
func rewardCellShouldShowDividerLine(_ show: Bool) | ||
func rewardSelected(with rewardId: Int) | ||
func traitCollectionDidChange(_ traitCollection: UITraitCollection) | ||
func viewDidAppear() | ||
func viewDidLayoutSubviews() | ||
func viewDidLoad() | ||
func viewWillAppear() | ||
} | ||
|
||
public protocol RewardsCollectionViewModelOutputs { | ||
var backedRewardIndexPath: Signal<IndexPath, Never> { get } | ||
var configureRewardsCollectionViewFooterWithCount: Signal<Int, Never> { get } | ||
var flashScrollIndicators: Signal<Void, Never> { get } | ||
var goToDeprecatedPledge: Signal<PledgeData, Never> { get } | ||
var goToPledge: Signal<(PledgeData, PledgeViewContext), Never> { get } | ||
var navigationBarShadowImageHidden: Signal<Bool, Never> { get } | ||
var reloadDataWithValues: Signal<[(Project, Either<Reward, Backing>)], Never> { get } | ||
var rewardsCollectionViewFooterIsHidden: Signal<Bool, Never> { get } | ||
var title: Signal<String, Never> { get } | ||
func selectedReward() -> Reward? | ||
} | ||
|
||
|
@@ -46,6 +54,18 @@ public final class RewardsCollectionViewModel: RewardsCollectionViewModelType, | |
let rewards = project | ||
.map { $0.rewards } | ||
|
||
self.title = configData | ||
.map(third) | ||
.combineLatest(with: self.viewDidLoadProperty.signal.ignoreValues()) | ||
.map(first) | ||
.map(titleForContext) | ||
|
||
self.backedRewardIndexPath = Signal.combineLatest(project, rewards) | ||
.takeWhen(self.viewDidLayoutSubviewsProperty.signal.ignoreValues()) | ||
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. Using 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. Interesting 🤔 I believe it needs a run loop to render the cells. We could probably go ahead with this but for interest sake, if you used |
||
.map(backedReward(_:rewards:)) | ||
.skipNil() | ||
.take(first: 1) | ||
|
||
self.reloadDataWithValues = Signal.combineLatest(project, rewards) | ||
.map { project, rewards in | ||
rewards.map { (project, Either<Reward, Backing>.left($0)) } | ||
|
@@ -108,9 +128,9 @@ public final class RewardsCollectionViewModel: RewardsCollectionViewModelType, | |
) | ||
} | ||
|
||
private let configDataProperty = MutableProperty<(Project, RefTag?)?>(nil) | ||
public func configure(with project: Project, refTag: RefTag?) { | ||
self.configDataProperty.value = (project, refTag) | ||
private let configDataProperty = MutableProperty<(Project, RefTag?, RewardsCollectionViewContext)?>(nil) | ||
public func configure(with project: Project, refTag: RefTag?, context: RewardsCollectionViewContext) { | ||
self.configDataProperty.value = (project, refTag, context) | ||
} | ||
|
||
private let rewardCellShouldShowDividerLineProperty = MutableProperty<Bool>(false) | ||
|
@@ -133,6 +153,11 @@ public final class RewardsCollectionViewModel: RewardsCollectionViewModelType, | |
self.viewDidAppearProperty.value = () | ||
} | ||
|
||
private let viewDidLayoutSubviewsProperty = MutableProperty(()) | ||
public func viewDidLayoutSubviews() { | ||
self.viewDidLayoutSubviewsProperty.value = () | ||
} | ||
|
||
private let viewDidLoadProperty = MutableProperty(()) | ||
public func viewDidLoad() { | ||
self.viewDidLoadProperty.value = () | ||
|
@@ -143,13 +168,15 @@ public final class RewardsCollectionViewModel: RewardsCollectionViewModelType, | |
self.viewWillAppearProperty.value = () | ||
} | ||
|
||
public let backedRewardIndexPath: Signal<IndexPath, Never> | ||
public let configureRewardsCollectionViewFooterWithCount: Signal<Int, Never> | ||
public let flashScrollIndicators: Signal<Void, Never> | ||
public let goToDeprecatedPledge: Signal<PledgeData, Never> | ||
public let goToPledge: Signal<(PledgeData, PledgeViewContext), Never> | ||
public let navigationBarShadowImageHidden: Signal<Bool, Never> | ||
public let reloadDataWithValues: Signal<[(Project, Either<Reward, Backing>)], Never> | ||
public let rewardsCollectionViewFooterIsHidden: Signal<Bool, Never> | ||
public let title: Signal<String, Never> | ||
|
||
private let selectedRewardProperty = MutableProperty<Reward?>(nil) | ||
public func selectedReward() -> Reward? { | ||
|
@@ -159,3 +186,16 @@ public final class RewardsCollectionViewModel: RewardsCollectionViewModelType, | |
public var inputs: RewardsCollectionViewModelInputs { return self } | ||
public var outputs: RewardsCollectionViewModelOutputs { return self } | ||
} | ||
|
||
private func titleForContext(_ context: RewardsCollectionViewContext) -> String { | ||
return context == .createPledge ? Strings.Back_this_project() : Strings.Choose_another_reward() | ||
} | ||
|
||
private func backedReward(_ project: Project, rewards: [Reward]) -> IndexPath? { | ||
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. Please update this to use the function @ifbarrera is using in #905 when that merges. https://github.com/kickstarter/ios-oss/pull/905/files#diff-234cfa58d101616352832cb332756878R33 |
||
if let reward = rewards.first(where: { userIsBacking(reward: $0, inProject: project) }) { | ||
return rewards | ||
.firstIndex(where: { $0.id == reward.id }) | ||
.flatMap { IndexPath(row: $0, section: 0) } | ||
} | ||
return nil | ||
} |
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 hey could we rename this to
scrollToBackedRewardIndexPath
just to make it clearer what this output does?