Skip to content

Commit 8141c8b

Browse files
committed
Code review - use interface builder for uistackview. Remove intrinsic height classes in favor of new API in iOS 11
1 parent fe3eddc commit 8141c8b

File tree

8 files changed

+76
-109
lines changed

8 files changed

+76
-109
lines changed

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/OrderDetailsViewController.swift

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ class OrderDetailsViewController: UIViewController {
3939
}
4040

4141
func configureSections() {
42-
let summarySection = Section(titles: [], footer: nil, rows: [.summary])
42+
let summarySection = Section(leftTitle: nil, rightTitle: nil, footer: nil, rows: [.summary])
4343

44-
let productSectionTitles = [NSLocalizedString("PRODUCT", comment: "Product section title"),
45-
NSLocalizedString("QTY", comment: "Quantity abbreviation for section title")]
46-
let productListSection = Section(titles: productSectionTitles, footer: nil, rows: [.productList])
44+
let productLeftTitle = NSLocalizedString("PRODUCT", comment: "Product section title")
45+
let productRightTitle = NSLocalizedString("QTY", comment: "Quantity abbreviation for section title")
46+
let productListSection = Section(leftTitle: productLeftTitle, rightTitle: productRightTitle, footer: nil, rows: [.productList])
4747

48-
let customerNoteSection = Section(titles: [NSLocalizedString("CUSTOMER PROVIDED NOTE", comment: "Customer note section title")], footer: nil, rows: [.customerNote])
48+
let customerNoteSection = Section(leftTitle: NSLocalizedString("CUSTOMER PROVIDED NOTE", comment: "Customer note section title"), rightTitle: nil, footer: nil, rows: [.customerNote])
4949

5050
let infoFooter = billingIsHidden ? NSLocalizedString("Show billing", comment: "Footer text to show the billing cell") : NSLocalizedString("Hide billing", comment: "Footer text to hide the billing cell")
5151
let infoRows: [Row] = billingIsHidden ? [.shippingAddress] : [.shippingAddress, .billingAddress, .billingPhone, .billingEmail]
52-
let infoSection = Section(titles: [NSLocalizedString("CUSTOMER INFORMATION", comment: "Customer info section title")], footer: infoFooter, rows: infoRows)
52+
let infoSection = Section(leftTitle: NSLocalizedString("CUSTOMER INFORMATION", comment: "Customer info section title"), rightTitle: nil, footer: infoFooter, rows: infoRows)
5353

5454
var noteRows: [Row] = [.addOrderNote]
5555
if let notes = order.notes {
5656
for _ in notes {
5757
noteRows.append(.orderNote)
5858
}
5959
}
60-
let orderNotesSection = Section(titles: [NSLocalizedString("ORDER NOTES", comment: "Order notes section title")], footer: nil, rows: noteRows)
60+
let orderNotesSection = Section(leftTitle: NSLocalizedString("ORDER NOTES", comment: "Order notes section title"), rightTitle: nil, footer: nil, rows: noteRows)
6161

62-
let paymentSection = Section(titles: [NSLocalizedString("PAYMENT", comment: "Payment section title")], footer: nil, rows: [.payment])
62+
let paymentSection = Section(leftTitle: NSLocalizedString("PAYMENT", comment: "Payment section title"), rightTitle: nil, footer: nil, rows: [.payment])
6363

6464
// FIXME: this is temporary
6565
// the API response always sends customer note data
@@ -106,7 +106,7 @@ extension OrderDetailsViewController: UITableViewDataSource {
106106
}
107107

108108
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
109-
if sections[section].titles?.count == 0 {
109+
if sections[section].leftTitle == nil {
110110
// iOS 11 table bug. Must return a tiny value to collapse `nil` or `empty` section headers.
111111
return CGFloat.leastNonzeroMagnitude
112112
}
@@ -115,19 +115,17 @@ extension OrderDetailsViewController: UITableViewDataSource {
115115
}
116116

117117
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
118-
guard let titles = sections[section].titles else {
118+
guard let leftText = sections[section].leftTitle else {
119119
return nil
120120
}
121-
let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: TwoColumnSectionHeaderView.reuseIdentifier)
122-
let header = view as! TwoColumnSectionHeaderView
123-
guard let leftText = titles.first else {
124-
return nil
121+
122+
guard let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: TwoColumnSectionHeaderView.reuseIdentifier) as? TwoColumnSectionHeaderView else {
123+
fatalError()
125124
}
126125

127-
let rightText = titles.count > 1 ? titles[1] : nil
128-
header.configure(leftText: leftText, rightText: rightText)
126+
header.configure(leftText: leftText, rightText: sections[section].rightTitle)
129127

130-
return view
128+
return header
131129
}
132130

133131
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
@@ -307,7 +305,8 @@ private extension OrderDetailsViewController {
307305
}
308306

309307
private struct Section {
310-
let titles: [String]?
308+
let leftTitle: String?
309+
let rightTitle: String?
311310
let footer: String?
312311
let rows: [Row]
313312
}
Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
import UIKit
22

33
class ProductListTableViewCell: UITableViewCell {
4-
var verticalStackView = UIStackView()
4+
@IBOutlet private var verticalStackView: UIStackView!
5+
@IBOutlet private var fulfillButton: UIButton!
56

67
static let reuseIdentifier = "ProductListTableViewCell"
78

8-
override func awakeFromNib() {
9-
super.awakeFromNib()
10-
verticalStackView.axis = .vertical
11-
verticalStackView.distribution = .fillProportionally
12-
verticalStackView.translatesAutoresizingMaskIntoConstraints = false
13-
contentView.addSubview(verticalStackView)
14-
15-
NSLayoutConstraint.activate([
16-
verticalStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
17-
verticalStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
18-
verticalStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: Constants.defaultPadding),
19-
verticalStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: Constants.negativePadding)
20-
])
21-
}
22-
239
override func setSelected(_ selected: Bool, animated: Bool) {
2410
super.setSelected(selected, animated: animated)
2511
backgroundColor = .white
@@ -28,34 +14,20 @@ class ProductListTableViewCell: UITableViewCell {
2814

2915
extension ProductListTableViewCell {
3016
func configure(with viewModel: OrderDetailsViewModel) {
31-
if verticalStackView.arrangedSubviews.count > 0 {
32-
for subView in verticalStackView.arrangedSubviews {
33-
verticalStackView.removeArrangedSubview(subView)
34-
}
17+
for subView in verticalStackView.arrangedSubviews {
18+
verticalStackView.removeArrangedSubview(subView)
3519
}
36-
for item in viewModel.items {
20+
21+
for (index, item) in viewModel.items.enumerated() {
3722
let itemView = TwoColumnLabelView.makeFromNib()
3823
itemView.leftText = item.name
3924
itemView.rightText = item.quantity.description
40-
verticalStackView.addArrangedSubview(itemView)
25+
verticalStackView.insertArrangedSubview(itemView, at: index)
4126
}
42-
let spacerView = IntrinsicHeightView()
43-
spacerView.height = 8.0
44-
verticalStackView.addArrangedSubview(spacerView)
45-
let fulfillButton = IntrinsicHeightButton()
46-
fulfillButton.height = 48.0
27+
4728
fulfillButton.setTitle(viewModel.fulfillTitle, for: .normal)
4829
fulfillButton.applyFilledRoundStyle()
49-
verticalStackView.addArrangedSubview(fulfillButton)
50-
NSLayoutConstraint.activate([
51-
fulfillButton.leadingAnchor.constraint(equalTo: verticalStackView.leadingAnchor, constant: Constants.defaultPadding),
52-
fulfillButton.trailingAnchor.constraint(equalTo: verticalStackView.trailingAnchor, constant: Constants.negativePadding)
53-
])
54-
fulfillButton.layoutIfNeeded()
55-
}
5630

57-
struct Constants {
58-
static let negativePadding = CGFloat(-16)
59-
static let defaultPadding = CGFloat(16)
31+
verticalStackView.setCustomSpacing(8.0, after: fulfillButton)
6032
}
6133
}

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/ProductListTableViewCell.xib

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -17,8 +17,33 @@
1717
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
1818
<rect key="frame" x="0.0" y="0.0" width="331" height="187.5"/>
1919
<autoresizingMask key="autoresizingMask"/>
20+
<subviews>
21+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="UBp-2C-MWu">
22+
<rect key="frame" x="16" y="16" width="299" height="99.5"/>
23+
</stackView>
24+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rng-8C-l5l">
25+
<rect key="frame" x="16" y="123.5" width="299" height="48"/>
26+
<constraints>
27+
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="48" id="egT-Dg-qmZ"/>
28+
</constraints>
29+
<state key="normal" title="Button"/>
30+
</button>
31+
</subviews>
32+
<constraints>
33+
<constraint firstItem="Rng-8C-l5l" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="1ki-E8-crI"/>
34+
<constraint firstItem="UBp-2C-MWu" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="4fY-7I-8Kh"/>
35+
<constraint firstItem="UBp-2C-MWu" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="16" id="5QQ-kw-gtJ"/>
36+
<constraint firstAttribute="trailing" secondItem="Rng-8C-l5l" secondAttribute="trailing" constant="16" id="CJh-nb-HvE"/>
37+
<constraint firstAttribute="trailing" secondItem="UBp-2C-MWu" secondAttribute="trailing" constant="16" id="WOB-jB-nRg"/>
38+
<constraint firstItem="Rng-8C-l5l" firstAttribute="top" secondItem="UBp-2C-MWu" secondAttribute="bottom" priority="750" constant="8" id="dbS-fW-98Y"/>
39+
<constraint firstAttribute="bottom" secondItem="Rng-8C-l5l" secondAttribute="bottom" constant="16" id="zHo-8e-b50"/>
40+
</constraints>
2041
</tableViewCellContentView>
2142
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
43+
<connections>
44+
<outlet property="fulfillButton" destination="Rng-8C-l5l" id="GrA-wO-Ocb"/>
45+
<outlet property="verticalStackView" destination="UBp-2C-MWu" id="AUM-Xi-GY1"/>
46+
</connections>
2247
<point key="canvasLocation" x="39.5" y="126"/>
2348
</tableViewCell>
2449
</objects>

WooCommerce/Classes/ViewRelated/ReusableViews/IntrinsicHeightButton.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

WooCommerce/Classes/ViewRelated/ReusableViews/IntrinsicHeightView.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -12,45 +12,42 @@
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1313
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
1414
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="TwoColumnLabelView" customModule="WooCommerce" customModuleProvider="target">
15-
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
15+
<rect key="frame" x="0.0" y="0.0" width="375" height="73"/>
1616
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1717
<subviews>
18-
<stackView autoresizesSubviews="NO" opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="4UN-Y3-EbP">
19-
<rect key="frame" x="16" y="2" width="343" height="40"/>
20-
<subviews>
21-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="240" horizontalCompressionResistancePriority="1000" text="Payment subline item" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Td-Am-Wbd">
22-
<rect key="frame" x="0.0" y="0.0" width="269.5" height="40"/>
23-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
24-
<nil key="textColor"/>
25-
<nil key="highlightedColor"/>
26-
</label>
27-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="1000" text="$823.00" textAlignment="natural" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="v4f-dh-0ZA">
28-
<rect key="frame" x="277.5" y="0.0" width="65.5" height="40"/>
29-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
30-
<nil key="textColor"/>
31-
<nil key="highlightedColor"/>
32-
</label>
33-
</subviews>
34-
</stackView>
18+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="240" verticalHuggingPriority="240" horizontalCompressionResistancePriority="1000" text="Payment subline item" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Td-Am-Wbd">
19+
<rect key="frame" x="0.0" y="0.0" width="301.5" height="73"/>
20+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
21+
<nil key="textColor"/>
22+
<nil key="highlightedColor"/>
23+
</label>
24+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="1000" text="$823.00" textAlignment="natural" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="v4f-dh-0ZA">
25+
<rect key="frame" x="309.5" y="0.0" width="65.5" height="73"/>
26+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
27+
<nil key="textColor"/>
28+
<nil key="highlightedColor"/>
29+
</label>
3530
</subviews>
3631
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3732
<constraints>
38-
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="4UN-Y3-EbP" secondAttribute="bottom" constant="2" id="6YY-h7-JXn"/>
39-
<constraint firstItem="4UN-Y3-EbP" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="2" id="JkY-Xb-WQU"/>
40-
<constraint firstItem="4UN-Y3-EbP" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="16" id="Q5b-ch-dyK"/>
41-
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="4UN-Y3-EbP" secondAttribute="trailing" constant="16" id="gBH-Jd-AOH"/>
33+
<constraint firstItem="3Td-Am-Wbd" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="0kO-Vk-ouZ"/>
34+
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="3Td-Am-Wbd" secondAttribute="bottom" priority="750" id="6xK-5K-Ys6"/>
35+
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="v4f-dh-0ZA" secondAttribute="trailing" id="AhK-69-dl9"/>
36+
<constraint firstItem="3Td-Am-Wbd" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="EQw-xJ-Ktb"/>
37+
<constraint firstItem="v4f-dh-0ZA" firstAttribute="centerY" secondItem="3Td-Am-Wbd" secondAttribute="centerY" id="JIQ-v9-Vuc"/>
38+
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="v4f-dh-0ZA" secondAttribute="bottom" priority="750" id="XJt-AF-oRJ"/>
39+
<constraint firstItem="v4f-dh-0ZA" firstAttribute="leading" secondItem="3Td-Am-Wbd" secondAttribute="trailing" constant="8" id="thT-Kp-vFH"/>
40+
<constraint firstItem="v4f-dh-0ZA" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="zaM-hF-5ol"/>
4241
</constraints>
4342
<nil key="simulatedTopBarMetrics"/>
4443
<nil key="simulatedBottomBarMetrics"/>
4544
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
4645
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
4746
<connections>
48-
<outlet property="bottomConstraint" destination="6YY-h7-JXn" id="Cdz-44-d8b"/>
4947
<outlet property="leftColumn" destination="3Td-Am-Wbd" id="tmZ-dE-xL2"/>
5048
<outlet property="rightColumn" destination="v4f-dh-0ZA" id="QOA-XC-1Cx"/>
51-
<outlet property="topConstraint" destination="JkY-Xb-WQU" id="joY-O6-w5i"/>
5249
</connections>
53-
<point key="canvasLocation" x="-104.5" y="133"/>
50+
<point key="canvasLocation" x="-104.5" y="147.5"/>
5451
</view>
5552
</objects>
5653
</document>

WooCommerce/Classes/ViewRelated/ReusableViews/TwoColumnSectionHeaderView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class TwoColumnSectionHeaderView: UITableViewHeaderFooterView {
1616

1717
override func awakeFromNib() {
1818
super.awakeFromNib()
19+
tintColor = .clear
1920
leftColumn.applyFootnoteStyle()
2021
rightColumn.applyFootnoteStyle()
2122
leftColumn.textColor = StyleManager.sectionTitleColor
@@ -27,6 +28,5 @@ extension TwoColumnSectionHeaderView {
2728
func configure(leftText: String?, rightText: String?) {
2829
leftColumn.text = leftText
2930
rightColumn.text = rightText
30-
tintColor = .clear
3131
}
3232
}

0 commit comments

Comments
 (0)