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

Commit 4986fd7

Browse files
viktoraslBasThomas
authored andcommitted
Dismiss spinner only after code view is rendered (#2611)
1 parent f0a62aa commit 4986fd7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Classes/Repository/RepositoryCodeBlobViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ final class RepositoryCodeBlobViewController: UIViewController, EmptyViewDelegat
159159
branch: branch,
160160
path: path.path
161161
) { [weak self] (result) in
162-
self?.feedRefresh.endRefreshing()
163162
switch result {
164163
case .success(let text):
165164
self?.handle(text: text)
@@ -172,17 +171,20 @@ final class RepositoryCodeBlobViewController: UIViewController, EmptyViewDelegat
172171
}
173172
}
174173

175-
func error(cannotLoad: Bool) {
174+
private func error(cannotLoad: Bool) {
175+
feedRefresh.endRefreshing()
176176
emptyView.isHidden = false
177177
emptyView.label.text = cannotLoad
178178
? NSLocalizedString("Cannot display file as text", comment: "")
179179
: NSLocalizedString("Error loading file", comment: "")
180180
}
181181

182-
func handle(text: String) {
182+
private func handle(text: String) {
183183
emptyView.isHidden = true
184184
didFetchPayload(text)
185-
codeView.set(code: text)
185+
codeView.set(code: text) { [weak self] in
186+
self?.feedRefresh.endRefreshing()
187+
}
186188
}
187189

188190
// MARK: EmptyViewDelegate

Classes/Views/CodeView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class CodeView: UITextView {
3131
}
3232

3333
// MARK: Public API
34-
func set(code: String, language: String? = nil) {
34+
func set(code: String, language: String? = nil, completion: @escaping () -> Void) {
3535
DispatchQueue.global().async {
3636
let maybeHighlighted: NSAttributedString?
3737
if let language = language {
@@ -40,9 +40,13 @@ final class CodeView: UITextView {
4040
// Automatic language detection
4141
maybeHighlighted = GithubHighlighting.highlight(code)
4242
}
43-
guard let highlighted = maybeHighlighted else { return }
43+
guard let highlighted = maybeHighlighted else {
44+
DispatchQueue.main.async(execute: completion)
45+
return
46+
}
4447
DispatchQueue.main.async { [weak self] in
4548
self?.set(attributedCode: highlighted)
49+
completion()
4650
}
4751
}
4852
}

0 commit comments

Comments
 (0)