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

Profile updates #4

Merged
merged 9 commits into from Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions Kickstarter-iOS/Tests/Views/ProfileViewControllerTests.swift
@@ -0,0 +1,71 @@
import Prelude
import Result
import XCTest
@testable import Kickstarter_Framework
@testable import KsApi
@testable import Library

internal final class ProfileViewControllerTests: TestCase {
private var project1: Project!
private var project2: Project!
private var project3: Project!

override func setUp() {
super.setUp()
let deadline = self.dateType.init().timeIntervalSince1970 + 60.0 * 60.0 * 24.0 * 14.0
let liveProject = Project.cosmicSurgery
|> Project.lens.photo.full .~ ""
|> (Project.lens.creator.avatar • User.Avatar.lens.small) .~ ""
|> Project.lens.dates.deadline .~ deadline
|> Project.lens.stats.fundingProgress .~ 0.5

let deadProject = Project.anomalisa
|> Project.lens.photo.full .~ ""
|> (Project.lens.creator.avatar • User.Avatar.lens.small) .~ ""
|> Project.lens.dates.deadline .~ self.dateType.init().timeIntervalSince1970
|> Project.lens.state .~ .successful

let failed = Project.cosmicSurgery
|> Project.lens.name .~ "A Failed Project About Mittens"
|> Project.lens.photo.full .~ ""
|> (Project.lens.creator.avatar • User.Avatar.lens.small) .~ ""
|> Project.lens.dates.deadline .~ self.dateType.init().timeIntervalSince1970
|> Project.lens.state .~ .failed

self.project1 = liveProject
self.project2 = deadProject
self.project3 = failed

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

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

func testBackedProjects() {
let env = .template |> DiscoveryEnvelope.lens.projects .~ [self.project1, self.project2, self.project3]

let user = .template
|> User.lens.name .~ "Chuck Berry"
|> User.lens.avatar.large .~ ""
|> User.lens.stats.backedProjectsCount .~ 3
|> User.lens.stats.createdProjectsCount .~ 1

combos(Language.allLanguages, [Device.phone4_7inch, Device.pad]).forEach { language, device in
withEnvironment(apiService: MockService(fetchDiscoveryResponse: env, fetchUserSelfResponse: user),
currentUser: user,
language: language) {
let controller = ProfileViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)

self.scheduler.run()

FBSnapshotVerifyView(parent.view, identifier: "lang_\(language)_device_\(device)")
}
}
}
}
33 changes: 28 additions & 5 deletions Kickstarter-iOS/Views/Cells/ProfileProjectCell.swift
@@ -1,12 +1,15 @@
import Foundation
import UIKit
import Library
import KsApi
import Library
import Prelude
import UIKit

internal final class ProfileProjectCell: UICollectionViewCell, ValueCell {
private let viewModel: ProfileProjectCellViewModelType = ProfileProjectCellViewModel()

@IBOutlet private weak var cardView: UIView!
@IBOutlet private weak var metadataBackgroundView: UIView!
@IBOutlet private weak var metadataLabel: UILabel!
@IBOutlet private weak var projectNameLabel: UILabel!
@IBOutlet private weak var projectImageView: UIImageView!
@IBOutlet private weak var progressView: UIView!
Expand All @@ -22,15 +25,32 @@ internal final class ProfileProjectCell: UICollectionViewCell, ValueCell {
super.bindStyles()

self
|> UICollectionViewCell.lens.backgroundColor .~ .clearColor()
|> UICollectionViewCell.lens.isAccessibilityElement .~ true
|> UICollectionViewCell.lens.accessibilityHint %~ { _ in Strings.Opens_project() }
|> UICollectionViewCell.lens.accessibilityTraits .~ UIAccessibilityTraitButton

self.cardView
|> dropShadowStyle()

self.metadataLabel
|> UILabel.lens.textColor .~ .whiteColor()
|> UILabel.lens.font .~ .ksr_headline(size: 12)

self.projectNameLabel
|> UILabel.lens.textColor .~ .ksr_text_navy_700
|> UILabel.lens.font .~ .ksr_callout(size: 15)

self.stateLabel
|> UILabel.lens.textColor .~ .whiteColor()
|> UILabel.lens.font .~ .ksr_headline(size: 12)
|> UILabel.lens.numberOfLines .~ 0
}

internal override func bindViewModel() {
self.metadataLabel.rac.text = self.viewModel.outputs.metadataText
self.metadataLabel.rac.hidden = self.viewModel.outputs.metadataIsHidden
self.metadataBackgroundView.rac.hidden = self.viewModel.outputs.metadataIsHidden
self.projectNameLabel.rac.text = self.viewModel.outputs.projectName
self.rac.accessibilityLabel = self.viewModel.outputs.cellAccessibilityLabel

Expand All @@ -49,9 +69,12 @@ internal final class ProfileProjectCell: UICollectionViewCell, ValueCell {
self.viewModel.outputs.progress
.observeForUI()
.observeNext { [weak element = progressBarView] progress in
let anchorX = progress == 0 ? 0 : 0.5 / progress
element?.layer.anchorPoint = CGPoint(x: CGFloat(anchorX), y: 0.5)
element?.transform = CGAffineTransformMakeScale(CGFloat(progress), 1.0)
if progress < 1.0 {
let anchorX = progress == 0 ? 0 : 0.5 / progress
element?.layer.anchorPoint = CGPoint(x: CGFloat(anchorX), y: 0.5)
}
let scaleX = progress >= 1.0 ? 1.0 : progress
element?.transform = CGAffineTransformMakeScale(CGFloat(scaleX), 1.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was some funkadelic stuff happening with the progress bar overlapping the space if progress was greater than 1.0, although we use this logic in every place we have a progress bar. I think this could be improved by a math whiz.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do let scaleX = min(1.0, progress) or you could set some clipping properties on the enclosing view to prevent it from overlapping

}

self.stateBannerView.rac.hidden = self.viewModel.outputs.stateHidden
Expand Down
14 changes: 5 additions & 9 deletions Kickstarter-iOS/Views/Controllers/ProfileViewController.swift
Expand Up @@ -21,7 +21,7 @@ internal final class ProfileViewController: UICollectionViewController {
self.collectionView?.backgroundColor = .ksr_grey_100

if let layout = self.collectionView?.collectionViewLayout as? UICollectionViewFlowLayout {
layout.itemSize = CGSize(width: 160, height: 220)
layout.itemSize = CGSize(width: 178, height: 220)
}

self.refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: .ValueChanged)
Expand All @@ -37,24 +37,20 @@ internal final class ProfileViewController: UICollectionViewController {
super.bindViewModel()

self.viewModel.outputs.backedProjects
.observeForControllerAction()
.observeForUI()
.observeNext { [weak self] ps in
self?.dataSource.load(projects: ps)
self?.collectionView?.reloadData()
}

self.viewModel.outputs.user
.observeForControllerAction()
.observeForUI()
.observeNext { [weak self] u in
self?.dataSource.load(user: u)
self?.collectionView?.reloadData()
}

self.viewModel.outputs.endRefreshing
.observeForControllerAction()
.observeNext { [weak self] in
self?.refreshControl.endRefreshing()
}
self.refreshControl.rac.refreshing = self.viewModel.outputs.isRefreshing

self.viewModel.outputs.goToProject
.observeForControllerAction()
Expand All @@ -69,7 +65,7 @@ internal final class ProfileViewController: UICollectionViewController {
}

self.viewModel.outputs.showEmptyState
.observeForControllerAction()
.observeForUI()
.observeNext { [weak self] visible in
self?.dataSource.emptyState(visible: visible)
self?.collectionView?.reloadData()
Expand Down
15 changes: 15 additions & 0 deletions Kickstarter-iOS/Views/ProfileHeaderView.swift
Expand Up @@ -19,6 +19,21 @@ internal final class ProfileHeaderView: UICollectionReusableView, ValueCell {
internal override func bindStyles() {
super.bindStyles()

self.backedProjectsLabel
|> UILabel.lens.textColor .~ .ksr_text_navy_600
|> UILabel.lens.font .~ .ksr_subhead(size: 12)

self.createdProjectsLabel
|> UILabel.lens.textColor .~ .ksr_text_navy_600
|> UILabel.lens.font .~ .ksr_subhead(size: 12)

self.dividerView
|> UIView.lens.backgroundColor .~ .ksr_navy_400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use separatorStyle for this


self.nameLabel
|> UILabel.lens.textColor .~ .ksr_text_navy_700
|> UILabel.lens.font .~ .ksr_headline(size: 15)

[self.backedProjectsLabel, self.createdProjectsLabel]
||> UILabel.lens.adjustsFontSizeToFitWidth .~ true
}
Expand Down