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

[NT-205] Manage pledge reward section #868

Merged
merged 25 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1bb0497
Added rewardview to the ManagePledgeViewController
Scollaco Sep 24, 2019
e936062
Now using RewardCardViewContext to set the right style depending on w…
Scollaco Sep 25, 2019
90ee7bc
Merge remote-tracking branch 'oss/master' into manage-pledge-reward-s…
Scollaco Sep 25, 2019
4981930
Fixed colors based on context / Added separators to Manage Pledge View
Scollaco Sep 25, 2019
0bdc382
Merge remote-tracking branch 'oss/master' into manage-pledge-reward-s…
Scollaco Sep 26, 2019
287bf14
Created container class for RewardCard view
Scollaco Sep 27, 2019
2f2dc67
Fixed tests
Scollaco Oct 2, 2019
4864106
Merge remote-tracking branch 'oss/master' into manage-pledge-reward-s…
Scollaco Oct 3, 2019
58cad5a
UI tweaks
Scollaco Oct 3, 2019
fb41bed
SwiftFormat
Scollaco Oct 3, 2019
6cccece
View Controller tests
Scollaco Oct 3, 2019
0ee1d4f
Reverted unwanted change
Scollaco Oct 3, 2019
ee81a76
Removed unnecessary argument from configureWith function
Scollaco Oct 7, 2019
a70f188
Removed navigationBarShadowImage property
Scollaco Oct 7, 2019
68f2c1a
Moved backgroundColor func to bindStyles, renamed private function
Scollaco Oct 7, 2019
0c986b0
Changed map syntax
Scollaco Oct 7, 2019
c60b1e1
Reverted project compatibilityVersion
Scollaco Oct 8, 2019
69b1e7b
Merge remote-tracking branch 'oss/master' into manage-pledge-reward-s…
Scollaco Oct 8, 2019
9e71ca2
Renamed output
Scollaco Oct 8, 2019
6a03c3d
Deleted snapshots with spelling mistake
Scollaco Oct 9, 2019
99bb8ab
Merge remote-tracking branch 'oss/master' into manage-pledge-reward-s…
Scollaco Oct 9, 2019
a092622
Merge branch 'master' into manage-pledge-reward-section
Scollaco Oct 9, 2019
0503111
Merge remote-tracking branch 'oss/master' into manage-pledge-reward-s…
Scollaco Oct 9, 2019
5c0e11e
Merge branch 'manage-pledge-reward-section' of https://github.com/kic…
Scollaco Oct 9, 2019
63f8ab1
Merge branch 'master' into manage-pledge-reward-section
Scollaco Oct 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Kickstarter-iOS/Views/Controllers/ManagePledgeRewardView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import KsApi
import Library
import Prelude
import UIKit

final class ManagePledgeRewardView: UIView {
// MARK: - Properties

private lazy var rewardView: RewardCardView = {
RewardCardView(frame: .zero)
}()

private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var titleLabel: UILabel = { UILabel(frame: .zero) }()

// MARK: - Life cycle

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

self.configureViews()
self.bindStyles()
}

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

// MARK: - Configuration

public func configure(with value: (Project, Either<Reward, Backing>)) {
self.rewardView.configure(with: value, context: .pledgeView)
}

private func configureViews() {
_ = ([self.titleLabel, self.rewardView], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()

_ = (self.rootStackView, self)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()
}

// MARK: - Styles

override func bindStyles() {
super.bindStyles()

_ = self.rewardView
|> checkoutBackgroundStyle

_ = self.rootStackView
|> checkoutCardStackViewStyle

_ = self.titleLabel
|> titleLabelStyle
}
}

// MARK: - Styles

private let titleLabelStyle: LabelStyle = { label in
label
|> checkoutTitleLabelStyle
|> \.text %~ { _ in Strings.Selected_reward() }
}
82 changes: 69 additions & 13 deletions Kickstarter-iOS/Views/Controllers/ManagePledgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import UIKit
final class ManagePledgeViewController: UIViewController {
// MARK: - Properties

private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel()

private lazy var closeButton: UIBarButtonItem = {
UIBarButtonItem(
image: UIImage(named: "icon--cross"),
Expand All @@ -26,16 +24,47 @@ final class ManagePledgeViewController: UIViewController {
)
}()

private lazy var pledgeSummaryView: ManagePledgeSummaryView = { ManagePledgeSummaryView(frame: .zero) }()
private lazy var paymentMethodSectionSeparator: UIView = {
UIView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private lazy var paymentMethodViews = {
[self.paymentMethodView, self.paymentMethodSectionSeparator]
}()

private lazy var paymentMethodView: ManagePledgePaymentMethodView = {
ManagePledgePaymentMethodView(frame: .zero)
}()

private lazy var pledgeSummaryView: ManagePledgeSummaryView = { ManagePledgeSummaryView(frame: .zero) }()

private lazy var pledgeSummarySectionViews = {
[self.pledgeSummaryView, self.pledgeSummarySectionSeparator]
}()

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

private lazy var rewardView: ManagePledgeRewardView = {
ManagePledgeRewardView(frame: .zero)
}()

private lazy var rewardReceivedViewController: ManageViewPledgeRewardReceivedViewController = {
ManageViewPledgeRewardReceivedViewController.instantiate()
}()

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

private lazy var rewardSectionViews = {
[self.rewardView, self.rewardSectionSeparator]
}()

private lazy var rootScrollView: UIScrollView = {
UIScrollView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
Expand All @@ -46,6 +75,19 @@ final class ManagePledgeViewController: UIViewController {
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private lazy var sectionSeparatorViews = {
[self.pledgeSummarySectionSeparator, self.paymentMethodSectionSeparator, self.rewardSectionSeparator]
}()

private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel()

static func instantiate(with project: Project, reward: Reward) -> ManagePledgeViewController {
let manageViewPledgeVC = ManagePledgeViewController.instantiate()
manageViewPledgeVC.viewModel.inputs.configureWith(project, reward: reward)

return manageViewPledgeVC
}

// MARK: - Lifecycle

override func viewDidLoad() {
Expand Down Expand Up @@ -81,6 +123,9 @@ final class ManagePledgeViewController: UIViewController {

_ = self.rootStackView
|> checkoutRootStackViewStyle

_ = self.sectionSeparatorViews
||> separatorStyleDark
}

// MARK: - View model
Expand Down Expand Up @@ -119,7 +164,9 @@ final class ManagePledgeViewController: UIViewController {

self.viewModel.outputs.configureRewardSummaryView
.observeForUI()
.observeValues { _ in }
.observeValues { [weak self] in
self?.rewardView.configure(with: $0)
}

self.viewModel.outputs.showActionSheetMenuWithOptions
.observeForControllerAction()
Expand Down Expand Up @@ -168,6 +215,13 @@ final class ManagePledgeViewController: UIViewController {
NSLayoutConstraint.activate([
self.rootStackView.widthAnchor.constraint(equalTo: self.rootScrollView.widthAnchor)
])

self.sectionSeparatorViews.forEach { view in
_ = view.heightAnchor.constraint(equalToConstant: 1)
|> \.isActive .~ true

view.setContentCompressionResistancePriority(.required, for: .vertical)
}
}

// MARK: Functions
Expand All @@ -181,17 +235,19 @@ final class ManagePledgeViewController: UIViewController {
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = ([self.pledgeSummaryView, self.paymentMethodView], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()

[self.rewardReceivedViewController].forEach { viewController in
self.addChild(viewController)
let childViews: [UIView] = [
self.pledgeSummarySectionViews,
self.paymentMethodViews,
self.rewardSectionViews,
[self.rewardReceivedViewController.view]
]
.flatMap { $0 }

_ = ([viewController.view], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()
_ = (childViews, self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()

viewController.didMove(toParent: self)
}
self.addChild(self.rewardReceivedViewController)
self.rewardReceivedViewController.didMove(toParent: self)
}

// MARK: Actions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@testable import Kickstarter_Framework
@testable import KsApi
@testable import Library
import Prelude
import UIKit

final class ManagePledgeViewControllerTests: TestCase {
override func setUp() {
super.setUp()

AppEnvironment.pushEnvironment(mainBundle: Bundle.framework)
UIView.setAnimationsEnabled(false)
}

override func tearDown() {
AppEnvironment.popEnvironment()
UIView.setAnimationsEnabled(true)

super.tearDown()
}

func testView() {
combos(Language.allLanguages, [Device.phone4_7inch, Device.pad]).forEach { language, device in
withEnvironment(language: language) {
let reward = Reward.template
|> Reward.lens.shipping.enabled .~ true
let backing = Backing.template
|> Backing.lens.reward .~ reward
let backedProject = Project.cosmicSurgery
|> Project.lens.personalization.backing .~ backing

let controller = ManagePledgeViewController.instantiate()
controller.configureWith(project: backedProject, reward: Reward.template)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 1_200

self.scheduler.run()

FBSnapshotVerifyView(parent.view, identifier: "lang_\(language)_device_\(device)")
}
}
}
}

This file was deleted.

5 changes: 4 additions & 1 deletion Kickstarter-iOS/Views/RewardCardContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public final class RewardCardContainerView: UIView {
|> roundedStyle(cornerRadius: Styles.grid(3))
|> \.layoutMargins .~ .init(all: Styles.grid(3))

_ = self.rewardCardView
|> checkoutWhiteBackgroundStyle

_ = self.gradientView
|> \.backgroundColor .~ .clear
|> \.startPoint .~ .zero
Expand Down Expand Up @@ -108,7 +111,7 @@ public final class RewardCardContainerView: UIView {

internal func configure(with value: (project: Project, reward: Either<Reward, Backing>)) {
self.viewModel.inputs.configureWith(project: value.project, rewardOrBacking: value.reward)
self.rewardCardView.configure(with: value)
self.rewardCardView.configure(with: value, context: RewardCardViewContext.rewardsCollectionView)
}

// MARK: - Private Helpers
Expand Down
Loading