Skip to content

Commit c803fa5

Browse files
authored
Merge pull request #6544 from woocommerce/issue/2448-use-GhostTableViewController-everywhere-part2
Use GhostableViewController for all cases, part 2
2 parents 20247c5 + 590533f commit c803fa5

File tree

9 files changed

+56
-188
lines changed

9 files changed

+56
-188
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [*] In-Person Payments: Removed collecting L2/L3 data. [https://github.com/woocommerce/woocommerce-ios/pull/6519]
77
- [*] Hub Menu: Multiple menu items can no longer be tapped simultaneously. [https://github.com/woocommerce/woocommerce-ios/pull/6484]
88
- [*] Jetpack CP: Fixed crash when attempting to access WP-Admin with an invalid URL that has an unsupported scheme. [https://github.com/woocommerce/woocommerce-ios/pull/6502]
9+
- [internal] Loading screens are refactored to avoid duplicated code and a potential crash. Please quickly smoke test them to make sure that everything still works as before. [https://github.com/woocommerce/woocommerce-ios/pull/6535] [https://github.com/woocommerce/woocommerce-ios/pull/6544]
910

1011
8.8
1112
-----

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Plugins/PluginListViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ final class PluginListViewController: UIViewController, GhostableViewController
99

1010
@IBOutlet private var tableView: UITableView!
1111

12-
lazy var ghostTableViewController = GhostTableViewController(options: GhostTableViewOptions(cellClass: HeadlineLabelTableViewCell.self,
12+
lazy var ghostTableViewController = GhostTableViewController(options: GhostTableViewOptions(displaysSectionHeader: false,
13+
cellClass: HeadlineLabelTableViewCell.self,
1314
rowsPerSection: [10],
14-
tableViewStyle: .grouped,
1515
isScrollEnabled: false))
1616

1717
/// Pull To Refresh Support.

WooCommerce/Classes/ViewRelated/Products/Categories/ProductCategoryListViewController.swift

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import WordPressUI
66
/// Please note that this class cannot be used as is, since there is not configuration for navigation.
77
/// Instead, it shall be embedded through view controller containment by adding it as a child to other view controllers.
88
///
9-
final class ProductCategoryListViewController: UIViewController {
9+
final class ProductCategoryListViewController: UIViewController, GhostableViewController {
1010

1111
@IBOutlet private var tableView: UITableView!
12-
private let ghostTableView = UITableView()
12+
13+
lazy var ghostTableViewController = GhostTableViewController(options: GhostTableViewOptions(displaysSectionHeader: false,
14+
cellClass: ProductCategoryTableViewCell.self))
1315

1416
let viewModel: ProductCategoryListViewModel
1517

@@ -28,7 +30,6 @@ final class ProductCategoryListViewController: UIViewController {
2830

2931
registerTableViewCells()
3032
configureTableView()
31-
configureGhostTableView()
3233
configureViewModel()
3334
handleSwipeBackGesture()
3435
}
@@ -39,7 +40,6 @@ final class ProductCategoryListViewController: UIViewController {
3940
private extension ProductCategoryListViewController {
4041
func registerTableViewCells() {
4142
tableView.registerNib(for: ProductCategoryTableViewCell.self)
42-
ghostTableView.registerNib(for: ProductCategoryTableViewCell.self)
4343
}
4444

4545
func configureTableView() {
@@ -49,15 +49,6 @@ private extension ProductCategoryListViewController {
4949
tableView.delegate = self
5050
tableView.removeLastCellSeparator()
5151
}
52-
53-
func configureGhostTableView() {
54-
view.addSubview(ghostTableView)
55-
ghostTableView.isHidden = true
56-
ghostTableView.translatesAutoresizingMaskIntoConstraints = false
57-
ghostTableView.pinSubviewToAllEdges(view)
58-
ghostTableView.backgroundColor = .listBackground
59-
ghostTableView.removeLastCellSeparator()
60-
}
6152
}
6253

6354
// MARK: - Synchronize Categories
@@ -73,12 +64,13 @@ private extension ProductCategoryListViewController {
7364
case .initialized:
7465
break
7566
case .syncing:
76-
self?.displayGhostTableView()
67+
self?.displayGhostContent()
7768
case let .failed(retryToken):
78-
self?.removeGhostTableView()
69+
self?.removeGhostContent()
7970
self?.displaySyncingErrorNotice(retryToken: retryToken)
8071
case .synced:
81-
self?.removeGhostTableView()
72+
self?.tableView.reloadData()
73+
self?.removeGhostContent()
8274
}
8375
}
8476
}
@@ -88,26 +80,6 @@ private extension ProductCategoryListViewController {
8880
//
8981
private extension ProductCategoryListViewController {
9082

91-
/// Renders ghost placeholder categories.
92-
///
93-
func displayGhostTableView() {
94-
let placeholderCategoriesPerSection = [3]
95-
let options = GhostOptions(displaysSectionHeader: false,
96-
reuseIdentifier: ProductCategoryTableViewCell.reuseIdentifier,
97-
rowsPerSection: placeholderCategoriesPerSection)
98-
ghostTableView.displayGhostContent(options: options,
99-
style: .wooDefaultGhostStyle)
100-
ghostTableView.isHidden = false
101-
}
102-
103-
/// Removes ghost placeholder categories.
104-
///
105-
func removeGhostTableView() {
106-
tableView.reloadData()
107-
ghostTableView.removeGhostContent()
108-
ghostTableView.isHidden = true
109-
}
110-
11183
/// Displays the Sync Error Notice.
11284
///
11385
func displaySyncingErrorNotice(retryToken: ProductCategoryListViewModel.RetryToken) {

WooCommerce/Classes/ViewRelated/Products/Edit Product/Edit Tags/ProductTagsViewController.swift

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import WordPressUI
44

55
/// ProductTagsViewController: Displays the list of ProductTag associated to the active Site and to the specific product.
66
///
7-
final class ProductTagsViewController: UIViewController {
7+
final class ProductTagsViewController: UIViewController, GhostableViewController {
88

99
@IBOutlet private weak var tableView: UITableView!
10-
@IBOutlet private weak var ghostTableView: UITableView!
1110
@IBOutlet private weak var textView: UITextView!
1211
@IBOutlet private var separatorView: UIView!
1312

13+
lazy var ghostTableViewController = GhostTableViewController(options: GhostTableViewOptions(displaysSectionHeader: false,
14+
cellClass: WooBasicTableViewCell.self,
15+
isScrollEnabled: false))
16+
1417
private let product: Product
1518

1619
private let originalTagNames: [String]
@@ -66,7 +69,6 @@ final class ProductTagsViewController: UIViewController {
6669
configureSeparator()
6770
registerTableViewCells()
6871
configureTableView()
69-
configureGhostTableView()
7072
startListeningToNotifications()
7173

7274
textView.text = normalizeInitialTags(tags: originalTagNames)
@@ -151,19 +153,10 @@ private extension ProductTagsViewController {
151153
tableView.removeLastCellSeparator()
152154
}
153155

154-
func configureGhostTableView() {
155-
ghostTableView.translatesAutoresizingMaskIntoConstraints = false
156-
ghostTableView.backgroundColor = .listBackground
157-
ghostTableView.isScrollEnabled = false
158-
ghostTableView.isHidden = true
159-
ghostTableView.removeLastCellSeparator()
160-
}
161-
162156
/// Registers all of the available TableViewCells
163157
///
164158
func registerTableViewCells() {
165159
tableView.registerNib(for: BasicTableViewCell.self)
166-
ghostTableView.registerNib(for: WooBasicTableViewCell.self)
167160
}
168161
}
169162

@@ -214,7 +207,7 @@ extension ProductTagsViewController: KeyboardScrollable {
214207
//
215208
private extension ProductTagsViewController {
216209
func loadTags() {
217-
displayLoading()
210+
displayGhostContent(over: tableView)
218211

219212
let action = ProductTagAction.synchronizeAllProductTags(siteID: product.siteID) { [weak self] error in
220213
if let error = error {
@@ -233,7 +226,7 @@ private extension ProductTagsViewController {
233226
}
234227

235228
func tagsLoaded(tags: [String]) {
236-
hideLoading()
229+
removeGhostContent()
237230
dataSource = SuggestionsDataSource(suggestions: tags,
238231
selectedTags: completeTags,
239232
searchQuery: partialTag)
@@ -265,23 +258,6 @@ private extension ProductTagsViewController {
265258

266259
}
267260

268-
// MARK: Loading handling
269-
//
270-
private extension ProductTagsViewController {
271-
func displayLoading() {
272-
let options = GhostOptions(displaysSectionHeader: false,
273-
reuseIdentifier: WooBasicTableViewCell.reuseIdentifier,
274-
rowsPerSection: [3])
275-
ghostTableView.displayGhostContent(options: options, style: .wooDefaultGhostStyle)
276-
ghostTableView.isHidden = false
277-
}
278-
279-
func hideLoading() {
280-
ghostTableView.removeGhostContent()
281-
ghostTableView.isHidden = true
282-
}
283-
}
284-
285261
// MARK: Error handling
286262
//
287263
private extension ProductTagsViewController {

WooCommerce/Classes/ViewRelated/Products/Edit Product/Edit Tags/ProductTagsViewController.xib

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19455" 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="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<objects>
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ProductTagsViewController" customModule="WooCommerce" customModuleProvider="target">
1313
<connections>
14-
<outlet property="ghostTableView" destination="iGf-7j-RA7" id="8bf-Qd-2gU"/>
1514
<outlet property="separatorView" destination="Yju-A0-WgT" id="Xfk-TL-To5"/>
1615
<outlet property="tableView" destination="zVJ-8z-2vs" id="KHA-P7-8J7"/>
1716
<outlet property="textView" destination="6Wz-Zl-b7p" id="3gD-hq-Ybw"/>
@@ -59,23 +58,15 @@
5958
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="zVJ-8z-2vs">
6059
<rect key="frame" x="0.0" y="113" width="414" height="749"/>
6160
</tableView>
62-
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" estimatedSectionHeaderHeight="-1" sectionFooterHeight="28" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="iGf-7j-RA7" userLabel="Ghost Table View">
63-
<rect key="frame" x="0.0" y="113" width="414" height="783"/>
64-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
65-
</tableView>
6661
</subviews>
6762
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
6863
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
6964
<constraints>
7065
<constraint firstItem="zVJ-8z-2vs" firstAttribute="top" secondItem="Ip2-5h-wvk" secondAttribute="bottom" id="51P-yI-3FR"/>
7166
<constraint firstAttribute="trailing" secondItem="Ip2-5h-wvk" secondAttribute="trailing" id="5AZ-8i-UZP"/>
72-
<constraint firstItem="iGf-7j-RA7" firstAttribute="trailing" secondItem="i5M-Pr-FkT" secondAttribute="trailing" id="9at-iB-L88"/>
73-
<constraint firstItem="iGf-7j-RA7" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="A0R-gI-Qdc"/>
7467
<constraint firstItem="zVJ-8z-2vs" firstAttribute="trailing" secondItem="i5M-Pr-FkT" secondAttribute="trailing" id="Chb-li-7pc"/>
7568
<constraint firstItem="zVJ-8z-2vs" firstAttribute="bottom" secondItem="fnl-2z-Ty3" secondAttribute="bottom" id="ECp-36-O08"/>
76-
<constraint firstItem="iGf-7j-RA7" firstAttribute="bottom" secondItem="i5M-Pr-FkT" secondAttribute="bottom" id="Q1i-f0-IsN"/>
7769
<constraint firstItem="Ip2-5h-wvk" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" constant="24" id="REa-GU-ALk"/>
78-
<constraint firstItem="iGf-7j-RA7" firstAttribute="top" secondItem="Ip2-5h-wvk" secondAttribute="bottom" id="RF7-tb-0sL"/>
7970
<constraint firstItem="zVJ-8z-2vs" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="eeY-QK-my7"/>
8071
<constraint firstItem="Ip2-5h-wvk" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="oUV-Mg-GkZ"/>
8172
</constraints>

WooCommerce/Classes/ViewRelated/Products/Variations/Add Attributes/AddAttributeOptionsViewController.swift

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import UIKit
22
import Yosemite
33
import WordPressUI
44

5-
final class AddAttributeOptionsViewController: UIViewController {
5+
final class AddAttributeOptionsViewController: UIViewController, GhostableViewController {
66

77
@IBOutlet weak private var tableView: UITableView!
8-
private let ghostTableView = UITableView()
8+
9+
lazy var ghostTableViewController = GhostTableViewController(options: GhostTableViewOptions(displaysSectionHeader: false,
10+
cellClass: WooBasicTableViewCell.self))
911

1012
private let viewModel: AddAttributeOptionsViewModel
1113

@@ -59,7 +61,6 @@ final class AddAttributeOptionsViewController: UIViewController {
5961
super.viewDidLoad()
6062
configureMainView()
6163
configureTableView()
62-
configureGhostTableView()
6364
registerTableViewHeaderSections()
6465
registerTableViewCells()
6566
startListeningToNotifications()
@@ -116,15 +117,6 @@ private extension AddAttributeOptionsViewController {
116117
tableView.allowsSelectionDuringEditing = true
117118
}
118119

119-
func configureGhostTableView() {
120-
view.addSubview(ghostTableView)
121-
ghostTableView.isHidden = true
122-
ghostTableView.translatesAutoresizingMaskIntoConstraints = false
123-
ghostTableView.pinSubviewToAllEdges(view)
124-
ghostTableView.backgroundColor = .listBackground
125-
ghostTableView.removeLastCellSeparator()
126-
}
127-
128120
func registerTableViewHeaderSections() {
129121
let headerNib = UINib(nibName: TwoColumnSectionHeaderView.reuseIdentifier, bundle: nil)
130122
tableView.register(headerNib, forHeaderFooterViewReuseIdentifier: TwoColumnSectionHeaderView.reuseIdentifier)
@@ -133,7 +125,6 @@ private extension AddAttributeOptionsViewController {
133125
func registerTableViewCells() {
134126
tableView.registerNib(for: BasicTableViewCell.self)
135127
tableView.registerNib(for: TextFieldTableViewCell.self)
136-
ghostTableView.registerNib(for: WooBasicTableViewCell.self)
137128
}
138129

139130
func observeViewModel() {
@@ -149,9 +140,9 @@ private extension AddAttributeOptionsViewController {
149140
tableView.reloadData()
150141

151142
if viewModel.showGhostTableView {
152-
displayGhostTableView()
143+
displayGhostContent()
153144
} else {
154-
removeGhostTableView()
145+
removeGhostContent()
155146
}
156147

157148
if viewModel.showSyncError {
@@ -331,27 +322,6 @@ private extension AddAttributeOptionsViewController {
331322
}
332323
}
333324

334-
// MARK: - Placeholders
335-
//
336-
private extension AddAttributeOptionsViewController {
337-
/// Renders ghost placeholder while options are being synched.
338-
///
339-
func displayGhostTableView() {
340-
let options = GhostOptions(displaysSectionHeader: false,
341-
reuseIdentifier: WooBasicTableViewCell.reuseIdentifier,
342-
rowsPerSection: [3])
343-
ghostTableView.displayGhostContent(options: options, style: .wooDefaultGhostStyle)
344-
ghostTableView.isHidden = false
345-
}
346-
347-
/// Removes ghost placeholder
348-
///
349-
func removeGhostTableView() {
350-
ghostTableView.removeGhostContent()
351-
ghostTableView.isHidden = true
352-
}
353-
}
354-
355325
// MARK: - Keyboard management
356326
//
357327
private extension AddAttributeOptionsViewController {

0 commit comments

Comments
 (0)