Skip to content

Commit

Permalink
[NO TICKET] Rewards Load Before Shipping Locations Have Loaded (#2136)
Browse files Browse the repository at this point in the history
* only show rewards once shipping locations have loaded and shimmer view has gone away

* cleanup unused delegate conformance

* add a comment to explain that this loading state is temporary and will be investigated as tech debt
  • Loading branch information
scottkicks authored Aug 29, 2024
1 parent 4decc8f commit 40d4356
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ extension ConfirmDetailsViewController: PledgeShippingLocationViewControllerDele
self.viewModel.inputs.shippingRuleSelected(shippingRule)
}

func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController) {}
func pledgeShippingLocationViewControllerLayoutDidUpdate(
_: PledgeShippingLocationViewController,
_: Bool
) {}
func pledgeShippingLocationViewControllerFailedToLoad(_: PledgeShippingLocationViewController) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ protocol PledgeShippingLocationViewControllerDelegate: AnyObject {
didSelect shippingRule: ShippingRule
)
func pledgeShippingLocationViewControllerLayoutDidUpdate(
_ viewController: PledgeShippingLocationViewController
_ viewController: PledgeShippingLocationViewController,
_ shimmerLoadingViewIsHidden: Bool
)
func pledgeShippingLocationViewControllerFailedToLoad(
_ viewController: PledgeShippingLocationViewController
Expand Down Expand Up @@ -134,9 +135,9 @@ final class PledgeShippingLocationViewController: UIViewController {
self.viewModel.outputs.shippingLocationButtonTitle
)
.observeForUI()
.observeValues { [weak self] _ in
.observeValues { [weak self] _, _, _, shimmerLoadingViewIsHidden, _ in
guard let self = self else { return }
self.delegate?.pledgeShippingLocationViewControllerLayoutDidUpdate(self)
self.delegate?.pledgeShippingLocationViewControllerLayoutDidUpdate(self, shimmerLoadingViewIsHidden)
}

self.viewModel.outputs.notifyDelegateOfSelectedShippingRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,10 @@ extension PledgeViewController: PledgeShippingLocationViewControllerDelegate {
self.viewModel.inputs.shippingRuleSelected(shippingRule)
}

func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController) {}
func pledgeShippingLocationViewControllerLayoutDidUpdate(
_: PledgeShippingLocationViewController,
_: Bool
) {}
func pledgeShippingLocationViewControllerFailedToLoad(_: PledgeShippingLocationViewController) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ extension RewardAddOnSelectionViewController: PledgeShippingLocationViewControll
self.viewModel.inputs.shippingRuleSelected(shippingRule)
}

func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController) {
func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController, _: Bool) {
self.tableView.ksr_sizeHeaderFooterViewsToFit()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class WithShippingRewardsCollectionViewController: UICollectionViewControl

_ = self.collectionView
|> \.dataSource .~ self.dataSource
|> \.isHidden .~ true

_ = (self.headerView, self.view)
|> ksr_addSubviewToParent()
Expand Down Expand Up @@ -200,6 +201,15 @@ final class WithShippingRewardsCollectionViewController: UICollectionViewControl
}
}

self.viewModel.outputs.rewardsCollectionViewIsHidden
.observeForUI()
.observeValues { [weak self] shimmerLoadingViewIsHidden in
guard let self else { return }

self.collectionView.isHidden = !shimmerLoadingViewIsHidden
self.collectionView.layoutIfNeeded()
}

self.viewModel.outputs.rewardsCollectionViewFooterIsHidden
.observeForUI()
.observeValues { [weak self] isHidden in
Expand Down Expand Up @@ -410,7 +420,13 @@ extension WithShippingRewardsCollectionViewController: PledgeShippingLocationVie
self.viewModel.inputs.shippingRuleSelected(shippingRule)
}

func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController) {}
func pledgeShippingLocationViewControllerLayoutDidUpdate(
_: PledgeShippingLocationViewController,
_ shimmerLoadingViewIsHidden: Bool
) {
self.viewModel.inputs.pledgeShippingLocationViewControllerDidUpdate(shimmerLoadingViewIsHidden)
}

func pledgeShippingLocationViewControllerFailedToLoad(_: PledgeShippingLocationViewController) {
self.viewModel.inputs.shippingLocationViewDidFailToLoad()
}
Expand Down
12 changes: 12 additions & 0 deletions Library/ViewModels/WithShippingRewardsCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UIKit
public protocol WithShippingRewardsCollectionViewModelInputs {
func configure(with project: Project, refTag: RefTag?, context: RewardsCollectionViewContext)
func confirmedEditReward()
func pledgeShippingLocationViewControllerDidUpdate(_ shimmerLoadingViewIsHidden: Bool)
func rewardCellShouldShowDividerLine(_ show: Bool)
func rewardSelected(with rewardId: Int)
func shippingLocationViewDidFailToLoad()
Expand All @@ -25,6 +26,7 @@ public protocol WithShippingRewardsCollectionViewModelOutputs {
var goToPledge: Signal<PledgeViewData, Never> { get }
var navigationBarShadowImageHidden: Signal<Bool, Never> { get }
var reloadDataWithValues: Signal<[RewardCardViewData], Never> { get }
var rewardsCollectionViewIsHidden: Signal<Bool, Never> { get }
var rewardsCollectionViewFooterIsHidden: Signal<Bool, Never> { get }
var scrollToBackedRewardIndexPath: Signal<IndexPath, Never> { get }
var shippingLocationViewHidden: Signal<Bool, Never> { get }
Expand Down Expand Up @@ -201,6 +203,10 @@ public final class WithShippingRewardsCollectionViewModel: WithShippingRewardsCo
goToPledgeBackedConfirmed
)

/// Temporary loading state solution. Proper designs will be explored in this ticket [mbl-1678](https://kickstarter.atlassian.net/browse/MBL-1678)
self.rewardsCollectionViewIsHidden = self.pledgeShippingLocationViewControllerDidUpdateProperty.signal
.map { $0 }

self.rewardsCollectionViewFooterIsHidden = self.traitCollectionChangedProperty.signal
.skipNil()
.map { isFalse($0.verticalSizeClass == .regular) }
Expand Down Expand Up @@ -323,6 +329,11 @@ public final class WithShippingRewardsCollectionViewModel: WithShippingRewardsCo
self.confirmedEditRewardProperty.value = ()
}

private let pledgeShippingLocationViewControllerDidUpdateProperty = MutableProperty<Bool>(false)
public func pledgeShippingLocationViewControllerDidUpdate(_ shimmerLoadingViewIsHidden: Bool) {
self.pledgeShippingLocationViewControllerDidUpdateProperty.value = shimmerLoadingViewIsHidden
}

private let rewardCellShouldShowDividerLineProperty = MutableProperty<Bool>(false)
public func rewardCellShouldShowDividerLine(_ show: Bool) {
self.rewardCellShouldShowDividerLineProperty.value = show
Expand Down Expand Up @@ -375,6 +386,7 @@ public final class WithShippingRewardsCollectionViewModel: WithShippingRewardsCo
public let goToPledge: Signal<PledgeViewData, Never>
public let navigationBarShadowImageHidden: Signal<Bool, Never>
public let reloadDataWithValues: Signal<[RewardCardViewData], Never>
public let rewardsCollectionViewIsHidden: Signal<Bool, Never>
public let rewardsCollectionViewFooterIsHidden: Signal<Bool, Never>
public let scrollToBackedRewardIndexPath: Signal<IndexPath, Never>
public var shippingLocationViewHidden: Signal<Bool, Never>
Expand Down

0 comments on commit 40d4356

Please sign in to comment.