Skip to content
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

[MBL-1209] Select Your Reward Title #1952

Merged
merged 10 commits into from
Feb 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ final class RewardsCollectionViewController: UICollectionViewController {
return self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout
}

private lazy var headerView: RewardsCollectionViewHeaderView = {
RewardsCollectionViewHeaderView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private let layout: UICollectionViewFlowLayout = {
UICollectionViewFlowLayout()
|> \.minimumLineSpacing .~ Styles.grid(3)
Expand Down Expand Up @@ -61,6 +66,11 @@ final class RewardsCollectionViewController: UICollectionViewController {
_ = self
|> \.extendedLayoutIncludesOpaqueBars .~ true

if featurePostCampaignPledgeEnabled() {
_ = (self.headerView, self.view)
|> ksr_addSubviewToParent()
}

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

Expand All @@ -69,6 +79,12 @@ final class RewardsCollectionViewController: UICollectionViewController {

self.collectionView.register(RewardCell.self)

self.collectionView.register(
RewardsCollectionViewHeaderView.self,
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: RewardsCollectionViewHeaderView.defaultReusableId
)

self.setupConstraints()

self.viewModel.inputs.viewDidLoad()
Expand All @@ -85,6 +101,8 @@ final class RewardsCollectionViewController: UICollectionViewController {

guard let layout = self.flowLayout else { return }

self.headerView.layoutIfNeeded()

let itemSize = self.calculateItemSize(from: layout, using: self.collectionView)

if itemSize != layout.itemSize {
Expand Down Expand Up @@ -112,6 +130,9 @@ final class RewardsCollectionViewController: UICollectionViewController {
_ = self.view
|> checkoutBackgroundStyle

_ = self.headerView
|> \.layoutMargins .~ .init(all: Styles.grid(3))

_ = self.collectionView
|> collectionViewStyle
|> checkoutBackgroundStyle
Expand Down Expand Up @@ -194,13 +215,23 @@ final class RewardsCollectionViewController: UICollectionViewController {
_ = self.collectionView
|> \.translatesAutoresizingMaskIntoConstraints .~ false

if featurePostCampaignPledgeEnabled() {
self.headerView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
self.headerView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
self.headerView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
}

NSLayoutConstraint.activate([
self.rewardsCollectionFooterView.leftAnchor.constraint(equalTo: self.view.leftAnchor),
self.rewardsCollectionFooterView.rightAnchor.constraint(equalTo: self.view.rightAnchor),
self.rewardsCollectionFooterView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
self.collectionView.leftAnchor.constraint(equalTo: self.view.leftAnchor),
self.collectionView.rightAnchor.constraint(equalTo: self.view.rightAnchor),
self.collectionView.topAnchor.constraint(equalTo: self.view.topAnchor)
self.collectionView.topAnchor
.constraint(equalTo: featurePostCampaignPledgeEnabled()
? self.headerView.bottomAnchor
: self.view.topAnchor
)
])

self.collectionViewBottomConstraintFooterView = self.collectionView.bottomAnchor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Foundation
import Library
import Prelude
import UIKit

public final class RewardsCollectionViewHeaderView: UICollectionReusableView {
// MARK: - Properties

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

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

// TODO: [MBL-1217])https://kickstarter.atlassian.net/browse/MBL-1217) Update hardcoded string with translations
self.label.text = "Select your reward."
self.setupSubviews()
}

required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public override func bindStyles() {
super.bindStyles()

_ = self
|> baseStyle

_ = self.label
|> labelStyle
}

private func setupSubviews() {
_ = (self.label, self)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToMarginsInParent(priority: .defaultHigh)

self.label.setContentCompressionResistancePriority(.required, for: .vertical)
self.label.setContentHuggingPriority(.required, for: .vertical)
}
}

private let baseStyle: ViewStyle = { view in
view
|> \.layoutMargins .~ .init(
top: Styles.grid(4),
left: Styles.grid(3),
bottom: Styles.grid(1),
right: Styles.grid(3)
)
|> \.backgroundColor .~ .clear
}

private let labelStyle: LabelStyle = { label in
label
|> \.numberOfLines .~ 1
|> \.textColor .~ UIColor.ksr_support_700
|> \.font .~ UIFont.ksr_title2().bolded
}
4 changes: 4 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
6093098D2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6093098C2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift */; };
609309912A60555F004297AF /* TriggerThirdPartyEventInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 609309902A60555F004297AF /* TriggerThirdPartyEventInput.swift */; };
609309952A6055A5004297AF /* TriggerThirdPartyEvent.graphql in Resources */ = {isa = PBXBuildFile; fileRef = 609309942A6055A5004297AF /* TriggerThirdPartyEvent.graphql */; };
60A3ED252B85361E008E1BA8 /* RewardsCollectionViewHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60A3ED232B853618008E1BA8 /* RewardsCollectionViewHeaderView.swift */; };
60AE9F062ABB897900FB3A96 /* ReportProjectInfoListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60AE9F022ABB822300FB3A96 /* ReportProjectInfoListItem.swift */; };
60C996E42ABCA5E5006BE4F4 /* ReportProjectLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60C996E32ABCA5E5006BE4F4 /* ReportProjectLabelView.swift */; };
60C996E62ABCC002006BE4F4 /* ReportProjectCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60C996E52ABCC002006BE4F4 /* ReportProjectCell.swift */; };
Expand Down Expand Up @@ -2078,6 +2079,7 @@
609309902A60555F004297AF /* TriggerThirdPartyEventInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerThirdPartyEventInput.swift; sourceTree = "<group>"; };
609309922A605563004297AF /* TriggerThirdPartyEventInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerThirdPartyEventInputTests.swift; sourceTree = "<group>"; };
609309942A6055A5004297AF /* TriggerThirdPartyEvent.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = TriggerThirdPartyEvent.graphql; sourceTree = "<group>"; };
60A3ED232B853618008E1BA8 /* RewardsCollectionViewHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RewardsCollectionViewHeaderView.swift; sourceTree = "<group>"; };
60AE9F022ABB822300FB3A96 /* ReportProjectInfoListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportProjectInfoListItem.swift; sourceTree = "<group>"; };
60C996E32ABCA5E5006BE4F4 /* ReportProjectLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportProjectLabelView.swift; sourceTree = "<group>"; };
60C996E52ABCC002006BE4F4 /* ReportProjectCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportProjectCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5711,6 +5713,7 @@
isa = PBXGroup;
children = (
77D19FFC24085A170058FC8E /* CategoryCollectionViewSectionHeaderView.swift */,
60A3ED232B853618008E1BA8 /* RewardsCollectionViewHeaderView.swift */,
77320F8924411459004C631E /* SettingsAccountHeaderView.swift */,
);
path = HeaderFooterViews;
Expand Down Expand Up @@ -8359,6 +8362,7 @@
770187C022FDCFCA0019129D /* PledgeViewControllerMessageDisplaying.swift in Sources */,
D60C8BF12143167200D96152 /* SettingsAccountViewController.swift in Sources */,
8A8099EC22E213F100373E66 /* RewardCardContainerView.swift in Sources */,
60A3ED252B85361E008E1BA8 /* RewardsCollectionViewHeaderView.swift in Sources */,
014D62991E6E22920033D2BD /* BackerDashboardEmptyStateCell.swift in Sources */,
D7237099211A3DA9001EA4CA /* SettingsFollowCell.swift in Sources */,
A7CC143E1D00E74F00035C52 /* FindFriendsFriendFollowCell.swift in Sources */,
Expand Down