Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 52592f2

Browse files
authored
Merge pull request #1734 from GitHawkApp/empty-loading
Less movement on initial load with small spinner
2 parents bce5b4a + 4475729 commit 52592f2

File tree

8 files changed

+65
-34
lines changed

8 files changed

+65
-34
lines changed

Classes/Issues/IssuesViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ final class IssuesViewController:
169169

170170
override func viewDidAppear(_ animated: Bool) {
171171
super.viewDidAppear(animated)
172-
feed.viewDidAppear(animated)
173172
let informator = HandoffInformator(
174173
activityName: "viewIssue",
175174
activityTitle: "\(model.owner)/\(model.repo)#\(model.number)",

Classes/Labels/LabelsViewController.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ final class LabelsViewController: UITableViewController {
2020
override func viewDidLoad() {
2121
super.viewDidLoad()
2222

23-
let emptyView = EmptyView()
24-
emptyView.label.text = NSLocalizedString("No labels found", comment: "")
25-
emptyView.isHidden = true
26-
tableView.backgroundView = emptyView
23+
tableView.backgroundView = EmptyLoadingView()
2724

2825
tableView.refreshControl = feedRefresh.refreshControl
2926
feedRefresh.refreshControl.addTarget(self, action: #selector(LabelsViewController.onRefresh), for: .valueChanged)
3027

31-
feedRefresh.beginRefreshing()
3228
fetch()
3329

3430
preferredContentSize = CGSize(width: 200, height: 240)
@@ -61,7 +57,14 @@ final class LabelsViewController: UITableViewController {
6157
self.labels = labels.sorted { $0.name < $1.name }
6258
tableView.reloadData()
6359
tableView.layoutIfNeeded()
64-
tableView.backgroundView?.isHidden = labels.count > 0
60+
61+
tableView.backgroundView?.removeFromSuperview()
62+
tableView.backgroundView = nil
63+
if labels.count == 0 {
64+
let emptyView = EmptyView()
65+
emptyView.label.text = NSLocalizedString("No labels found", comment: "")
66+
tableView.backgroundView = emptyView
67+
}
6568
}
6669

6770
// MARK: UITableViewDataSource

Classes/Milestones/MilestonesViewController.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ final class MilestonesViewController: UITableViewController {
2121
override func viewDidLoad() {
2222
super.viewDidLoad()
2323

24-
let emptyView = EmptyView()
25-
emptyView.label.text = NSLocalizedString("No open milestones", comment: "")
26-
emptyView.isHidden = true
27-
tableView.backgroundView = emptyView
24+
tableView.backgroundView = EmptyLoadingView()
2825

2926
tableView.refreshControl = feedRefresh.refreshControl
3027
feedRefresh.refreshControl.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
3128

32-
feedRefresh.beginRefreshing()
3329
fetch()
3430

3531
preferredContentSize = CGSize(width: 200, height: 240)
@@ -64,8 +60,15 @@ final class MilestonesViewController: UITableViewController {
6460
case .error:
6561
ToastManager.showGenericError()
6662
}
67-
self?.tableView.backgroundView?.isHidden = (self?.milestones.count ?? 0) > 0
6863
self?.feedRefresh.endRefreshing()
64+
65+
self?.tableView.backgroundView?.removeFromSuperview()
66+
self?.tableView.backgroundView = nil
67+
if self?.milestones.count == 0 {
68+
let emptyView = EmptyView()
69+
emptyView.label.text = NSLocalizedString("No labels found", comment: "")
70+
self?.tableView.backgroundView = emptyView
71+
}
6972
}
7073
}
7174

Classes/PullRequestReviews/PullRequestReviewCommentsViewController.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ final class PullRequestReviewCommentsViewController: MessageViewController,
8080
messageView.add(contentView: actions)
8181
}
8282

83-
override func viewDidAppear(_ animated: Bool) {
84-
super.viewDidAppear(animated)
85-
feed.viewDidAppear(animated)
86-
}
87-
8883
override func viewWillLayoutSubviews() {
8984
super.viewWillLayoutSubviews()
9085
feed.viewWillLayoutSubviews(view: view)
@@ -188,8 +183,10 @@ final class PullRequestReviewCommentsViewController: MessageViewController,
188183
let emptyView = EmptyView()
189184
emptyView.label.text = NSLocalizedString("Error loading review comments.", comment: "")
190185
return emptyView
191-
case .loading, .loadingNext:
186+
case .loadingNext:
192187
return nil
188+
case .loading:
189+
return EmptyLoadingView()
193190
}
194191
}
195192

Classes/Systems/Feed.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final class Feed: NSObject, UIScrollViewDelegate {
2929
private weak var delegate: FeedDelegate?
3030
private let feedRefresh = FeedRefresh()
3131
private let managesLayout: Bool
32+
private let loadingView = EmptyLoadingView()
3233

3334
init(
3435
viewController: UIViewController,
@@ -58,6 +59,10 @@ final class Feed: NSObject, UIScrollViewDelegate {
5859
feedRefresh.beginRefreshing()
5960
}
6061

62+
func showEmptyLoadingView() {
63+
loadingView.isHidden = false
64+
}
65+
6166
func viewDidLoad() {
6267
guard let view = adapter.viewController?.view else { return }
6368

@@ -70,21 +75,15 @@ final class Feed: NSObject, UIScrollViewDelegate {
7075
if collectionView.superview == nil {
7176
view.addSubview(collectionView)
7277
}
73-
}
7478

75-
func viewDidAppear(_ animated: Bool) {
76-
// put in a small delay to let container finish laying out
77-
// prevents a bug from double-insetting the refresh control
78-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: {
79-
if self.status == .loading {
80-
self.feedRefresh.beginRefreshing()
81-
}
82-
})
79+
view.addSubview(loadingView)
8380
}
8481

8582
func viewWillLayoutSubviews(view: UIView) {
8683
let bounds = view.bounds
8784

85+
loadingView.frame = bounds
86+
8887
let changed = bounds != collectionView.frame
8988
if managesLayout && changed {
9089
collectionView.frame = bounds
@@ -96,6 +95,7 @@ final class Feed: NSObject, UIScrollViewDelegate {
9695

9796
func finishLoading(dismissRefresh: Bool, animated: Bool = true, completion: (() -> Void)? = nil) {
9897
status = .idle
98+
loadingView.isHidden = true
9999

100100
adapter.performUpdates(animated: animated) { _ in
101101
if dismissRefresh {

Classes/View Controllers/BaseListViewController.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ LoadMoreSectionControllerDelegate {
6363
rz_smoothlyDeselectRows(collectionView: feed.collectionView)
6464
}
6565

66-
override func viewDidAppear(_ animated: Bool) {
67-
super.viewDidAppear(animated)
68-
feed.viewDidAppear(animated)
69-
}
70-
7166
override func viewWillLayoutSubviews() {
7267
super.viewWillLayoutSubviews()
7368
feed.viewWillLayoutSubviews(view: view)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// EmptyLoadingView.swift
3+
// Freetime
4+
//
5+
// Created by Ryan Nystrom on 4/15/18.
6+
// Copyright © 2018 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
final class EmptyLoadingView: UIView {
12+
13+
private let activity = UIActivityIndicatorView(activityIndicatorStyle: .gray)
14+
15+
override init(frame: CGRect) {
16+
super.init(frame: frame)
17+
activity.startAnimating()
18+
addSubview(activity)
19+
}
20+
21+
required init?(coder aDecoder: NSCoder) {
22+
fatalError("init(coder:) has not been implemented")
23+
}
24+
25+
override func layoutSubviews() {
26+
super.layoutSubviews()
27+
activity.center = CGPoint(x: bounds.width/2, y: bounds.height/2)
28+
}
29+
30+
}

Freetime.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
294B11221F7B0B9500E04F2D /* UIScrollView+ScrollToTop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294B11211F7B0B9500E04F2D /* UIScrollView+ScrollToTop.swift */; };
161161
294B11241F7B37D300E04F2D /* ImageCellHeightCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294B11231F7B37D200E04F2D /* ImageCellHeightCache.swift */; };
162162
2950AB1B2082E47200C6F19A /* AppSplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2950AB1A2082E47200C6F19A /* AppSplitViewController.swift */; };
163+
2950AB1D2083B1E400C6F19A /* EmptyLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2950AB1C2083B1E400C6F19A /* EmptyLoadingView.swift */; };
163164
2957777B200129EB00DDD785 /* Int+Abbreviated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2957777A200129EB00DDD785 /* Int+Abbreviated.swift */; };
164165
295840651EE89F28007723C6 /* IssueStatusEventModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 295840641EE89F28007723C6 /* IssueStatusEventModel.swift */; };
165166
295840671EE89FE4007723C6 /* IssueStatusEventCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 295840661EE89FE4007723C6 /* IssueStatusEventCell.swift */; };
@@ -591,6 +592,7 @@
591592
294B11211F7B0B9500E04F2D /* UIScrollView+ScrollToTop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScrollView+ScrollToTop.swift"; sourceTree = "<group>"; };
592593
294B11231F7B37D200E04F2D /* ImageCellHeightCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCellHeightCache.swift; sourceTree = "<group>"; };
593594
2950AB1A2082E47200C6F19A /* AppSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSplitViewController.swift; sourceTree = "<group>"; };
595+
2950AB1C2083B1E400C6F19A /* EmptyLoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyLoadingView.swift; sourceTree = "<group>"; };
594596
2957777A200129EB00DDD785 /* Int+Abbreviated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+Abbreviated.swift"; sourceTree = "<group>"; };
595597
295840641EE89F28007723C6 /* IssueStatusEventModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueStatusEventModel.swift; sourceTree = "<group>"; };
596598
295840661EE89FE4007723C6 /* IssueStatusEventCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueStatusEventCell.swift; sourceTree = "<group>"; };
@@ -1508,6 +1510,7 @@
15081510
29A4768D1ED07A23005D0953 /* DateDetailsFormatter.swift */,
15091511
291929601F3FD2960012067B /* DiffString.swift */,
15101512
D8C2AEF41F9AA94600A95945 /* DotListView.swift */,
1513+
2950AB1C2083B1E400C6F19A /* EmptyLoadingView.swift */,
15111514
29C167681ECA016500439D62 /* EmptyView.swift */,
15121515
291929541F3FAADF0012067B /* FeedRefresh.swift */,
15131516
29136BDA200A626D007317BE /* FixedRefreshControl.swift */,
@@ -1520,6 +1523,7 @@
15201523
D8BAD05F1FDA0A1A00C41071 /* LabelListCell.swift */,
15211524
D8BAD0631FDF221900C41071 /* LabelListView.swift */,
15221525
299F63D3205DA24A0015D901 /* MarkdownAttributeHandling.swift */,
1526+
299F63E920603FB80015D901 /* MarkdownStyledTextView.swift */,
15231527
297A6CE52027880C0027E03B /* MessageView+Styles.swift */,
15241528
29136BE0200A7D3D007317BE /* NavigationTitleDropdownView.swift */,
15251529
2963A9331EE2118E0066509C /* ResponderButton.swift */,
@@ -1549,7 +1553,6 @@
15491553
292FF8B11F302FE7009E63F7 /* UITextView+SelectedRange.swift */,
15501554
298BA08E1EC90FEE00B01946 /* UIView+BottomBorder.swift */,
15511555
299F63E1205DE1470015D901 /* UIView+DateDetails.swift */,
1552-
299F63E920603FB80015D901 /* MarkdownStyledTextView.swift */,
15531556
);
15541557
path = Views;
15551558
sourceTree = "<group>";
@@ -2657,6 +2660,7 @@
26572660
29AC90E51F00A7C8000B80E4 /* SplitViewControllerDelegate.swift in Sources */,
26582661
65A3152B2044376D0074E3B6 /* Route.swift in Sources */,
26592662
29DB264A1FCA10A800C3D0C9 /* GithubHighlighting.swift in Sources */,
2663+
2950AB1D2083B1E400C6F19A /* EmptyLoadingView.swift in Sources */,
26602664
29A08FC11F12F08100C5368E /* String+HashDisplay.swift in Sources */,
26612665
29B0EF871F93DF6C00870291 /* RepositoryCodeBlobViewController.swift in Sources */,
26622666
2931EA471EF7734B00AEE0FF /* String+NSRange.swift in Sources */,

0 commit comments

Comments
 (0)