Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix glitchy loading view #815

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Mail/Views/Thread/MessageBodyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ struct MessageBodyView: View {
}
}
}
.opacity(model.contentLoading ? 0 : 1)
.opacity(model.initialContentLoading ? 0 : 1)

if isMessagePreprocessed && !model.contentLoading {
if model.initialContentLoading {
ShimmerView()
}
}
Expand Down
13 changes: 13 additions & 0 deletions Mail/Views/Thread/WebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import CocoaLumberjackSwift
import Combine
import MailCore
import Sentry
import SwiftSoup
Expand All @@ -29,6 +30,10 @@ final class WebViewModel: NSObject, ObservableObject {
@Published var showBlockQuote = false
@Published var contentLoading = true

/// Only true the first time the content loads, then false. Eg. when loading subsequent images.
@Published var initialContentLoading = true
private var contentLoadingSubscriber: AnyCancellable?

let webView: WKWebView
let contentBlocker: ContentBlocker

Expand All @@ -49,6 +54,14 @@ final class WebViewModel: NSObject, ObservableObject {

super.init()

// only register the first flip of contentLoading to false
contentLoadingSubscriber = $contentLoading
.filter { $0 == false }
.prefix(1)
.sink { _ in
self.initialContentLoading = false
}

setUpWebViewConfiguration()
loadScripts(configuration: webView.configuration)
}
Expand Down