diff --git a/Mail/Views/Thread/MessageBodyView.swift b/Mail/Views/Thread/MessageBodyView.swift index b649f4734..337a04350 100644 --- a/Mail/Views/Thread/MessageBodyView.swift +++ b/Mail/Views/Thread/MessageBodyView.swift @@ -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() } } diff --git a/Mail/Views/Thread/WebViewModel.swift b/Mail/Views/Thread/WebViewModel.swift index 4efe0d6fb..e357dc8b4 100644 --- a/Mail/Views/Thread/WebViewModel.swift +++ b/Mail/Views/Thread/WebViewModel.swift @@ -17,6 +17,7 @@ */ import CocoaLumberjackSwift +import Combine import MailCore import Sentry import SwiftSoup @@ -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 @@ -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) }