-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ActivityFriendBackingCell.swift
91 lines (76 loc) · 3.27 KB
/
ActivityFriendBackingCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import KsApi
import Library
import Prelude
import ReactiveSwift
import UIKit
internal final class ActivityFriendBackingCell: UITableViewCell, ValueCell {
fileprivate let viewModel: ActivityFriendBackingViewModel = ActivityFriendBackingViewModel()
@IBOutlet fileprivate weak var cardView: UIView!
@IBOutlet fileprivate weak var containerView: UIView!
@IBOutlet fileprivate weak var friendImageView: UIImageView!
@IBOutlet fileprivate weak var friendTitleLabel: UILabel!
@IBOutlet fileprivate weak var fundingProgressBarView: UIView!
@IBOutlet fileprivate weak var fundingProgressContainerView: UIView!
@IBOutlet fileprivate weak var fundingProgressLabel: UILabel!
@IBOutlet fileprivate weak var projectNameLabel: UILabel!
@IBOutlet fileprivate weak var projectImageView: UIImageView!
@IBOutlet fileprivate weak var projectTextContainerView: UIView!
func configureWith(value: Activity) {
self.viewModel.inputs.configureWith(activity: value)
}
override func bindViewModel() {
self.rac.accessibilityLabel = self.viewModel.outputs.cellAccessibilityLabel
self.friendTitleLabel.rac.attributedText = self.viewModel.outputs.friendTitle
self.fundingProgressBarView.rac.backgroundColor = self.viewModel.outputs.fundingBarColor
self.fundingProgressLabel.rac.attributedText = self.viewModel.outputs.percentFundedText
self.projectNameLabel.rac.text = self.viewModel.outputs.projectName
self.viewModel.outputs.friendImageURL
.observeForUI()
.on(event: { [weak friendImageView] _ in
friendImageView?.af_cancelImageRequest()
friendImageView?.image = nil
})
.skipNil()
.observeValues { [weak friendImageView] url in
friendImageView?.ksr_setImageWithURL(url)
}
self.viewModel.outputs.fundingProgressPercentage
.observeForUI()
.observeValues { [weak self] progress in
let anchorX = progress == 0 ? 0 : 0.5 / progress
self?.fundingProgressBarView.layer.anchorPoint = CGPoint(x: CGFloat(anchorX), y: 0.5)
self?.fundingProgressBarView.transform = CGAffineTransform(scaleX: CGFloat(progress), y: 1.0)
}
self.viewModel.outputs.projectImageURL
.observeForUI()
.on(event: { [weak projectImageView] _ in
projectImageView?.af_cancelImageRequest()
projectImageView?.image = nil
})
.skipNil()
.observeValues { [weak projectImageView] url in
projectImageView?.ksr_setImageWithURL(url)
}
}
override func bindStyles() {
super.bindStyles()
_ = self
|> feedTableViewCellStyle
|> UITableViewCell.lens.accessibilityTraits .~ UIAccessibilityTraitButton
_ = self.cardView
|> cardStyle()
_ = self.containerView
|> UIView.lens.layoutMargins .~ .init(all: Styles.grid(2))
_ = self.fundingProgressContainerView
|> UIView.lens.backgroundColor .~ .ksr_navy_400
_ = self.projectImageView
|> UIImageView.lens.clipsToBounds .~ true
_ = self.projectNameLabel
|> UILabel.lens.font .~ .ksr_title1(size: 18)
|> UILabel.lens.textColor .~ .ksr_text_dark_grey_900
_ = self.projectTextContainerView
|> UIView.lens.alpha .~ 0.96
|> UIView.lens.layoutMargins .~ .init(topBottom: Styles.gridHalf(5),
leftRight: Styles.grid(2))
}
}