@@ -12,7 +12,17 @@ class CardView: UIView {
13 var post: WallPost? {
13 var post: WallPost? {
15− print(post?.owner)
15+// print(post?.owner)
19+ var width: CGFloat = 300 {
24+ var height: CGFloat = 400 {
@@ -28,6 +38,11 @@ class CardView: UIView {
28 fatalError("init(coder:) has not been implemented")
38 fatalError("init(coder:) has not been implemented")
41+ private let padding = CGPoint(x: 32, y: 32)
42+ private let vPadding1: CGFloat = 16
43+ private let vPadding2: CGFloat = 16
44+ private let minTextHeight: CGFloat = 50
31// private let avatar = UIImage()
46// private let avatar = UIImage()
32// private let name = UIImage()
47// private let name = UIImage()
@@ -35,7 +50,7 @@ class CardView: UIView {
35 subviews.map {$0.removeFromSuperview()}
50 subviews.map {$0.removeFromSuperview()}
37 let largeStack = StackView(axis: .vertical, alignment: .left)
52 let largeStack = StackView(axis: .vertical, alignment: .left)
38− largeStack.padding = CGPoint(x: 32, y: 32)
53+ largeStack.padding = padding
39 addSubview(largeStack)
54 addSubview(largeStack)
41 let userView = StackView(axis: .horizontal, alignment: .center)
56 let userView = StackView(axis: .horizontal, alignment: .center)
@@ -52,7 +67,7 @@ class CardView: UIView {
52 avatar.frame.size = CGSize(width: avatarDim, height: avatarDim)
67 avatar.frame.size = CGSize(width: avatarDim, height: avatarDim)
53 userView.addArrangedSubview(.view(avatar))
68 userView.addArrangedSubview(.view(avatar))
55− userView.addArrangedSubview(.spacer(8))
70+ userView.addArrangedSubview(.spacer(16))
57 let userName = UILabel()
72 let userName = UILabel()
58 let firstName = post?.owner?.firstName ?? ""
73 let firstName = post?.owner?.firstName ?? ""
@@ -61,21 +76,79 @@ class CardView: UIView {
61 userName.font = UIFont.systemFont(ofSize: 28, weight: UIFontWeightHeavy)
76 userName.font = UIFont.systemFont(ofSize: 28, weight: UIFontWeightHeavy)
62 userName.sizeToFit()
77 userName.sizeToFit()
63 userView.addArrangedSubview(.view(userName))
78 userView.addArrangedSubview(.view(userName))
64− userView.frame.origin = CGPoint(x: 16, y: 16)
79+
80+ userView.layoutIfNeeded()
66 largeStack.addArrangedSubview(.view(userView))
82 largeStack.addArrangedSubview(.view(userView))
68− largeStack.addArrangedSubview(.spacer(16))
84+ largeStack.addArrangedSubview(.spacer(vPadding1))
87+ let photoView = CollectionView()
88+ photoView.alignment = .top
89+ photoView.horizontalPadding = 8
90+ photoView.verticalPadding = 8
91+ photoView.padding = CGPoint.zero
92+ var maxPhotoDim: CGFloat = 150
93+ if let attachments = post?.attachments {
94+ for attachment in attachments {
95+ if let v = attachment.value {
97+ case .photo(let photo):
98+ if var pWidth = photo.width.value >>> {CGFloat($0)},
99+ var pHeight = photo.height.value >>> {CGFloat($0)} {
100+ let photoV = UIImageView()
101+ photo.image?.load(into: photoV)
103+ if pWidth > pHeight {
104+ k = CGFloat(pWidth) / maxPhotoDim
106+ k = CGFloat(pHeight) / maxPhotoDim
110+ photoV.frame.size = CGSize(width: pWidth, height: pHeight)
111+ photoView.addArrangedSubview(photoV)
115+ break // TODO: Handle other data types
120+ photoView.layoutIfNeeded()
122+ var textHeight = height
123+ textHeight -= padding.y + vPadding1 + userView.frame.height
124+ if let count = post?.attachments.count{
126+ textHeight -= vPadding2 + photoView.frame.height
130+ textHeight = max(textHeight, minTextHeight)
70 let body = UILabel()
133 let body = UILabel()
71 body.numberOfLines = 0
134 body.numberOfLines = 0
72− let bodyWidth: Double = 300
135+ let bodyWidth: Double = Double(width - padding.x * 2)
73 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
136 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
74− body.text = post?.body ?? "Spicy jalapeno flank landjaeger sausage tongue tail fatback frankfurter. Meatball tongue tail short ribs pastrami. Short ribs chicken pig tenderloin sausage pork. Corned beef t-bone pancetta jerky chuck picanha venison, turducken tenderloin shoulder boudin drumstick hamburger. Pork meatball meatloaf prosciutto pig andouille. Sirloin bacon hamburger short ribs pork cupim shank biltong turducken bresaola kevin prosciutto shoulder meatball. Strip steak frankfurter pork chop biltong jowl beef rump venison pancetta turkey tongue."
137+ body.text = post?.body
75 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
138 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
76− body.frame.size = size
139+ body.frame.size.height = min(size.height, textHeight)
140+ body.frame.size.width = size.width
78 largeStack.addArrangedSubview(.view(body))
142 largeStack.addArrangedSubview(.view(body))
144+ if let count = post?.attachments.count{
146+ largeStack.addArrangedSubview(.spacer(vPadding2))
147+ largeStack.addArrangedSubview(.view(photoView))
151+ frame.size = CGSize(width: width, height: height)