From 964ad7d0dcfca5f2f119b7998c166495b54c6133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Fri, 16 Jun 2023 14:20:17 +0200 Subject: [PATCH 1/2] feat: fix glitchy loading view --- Mail/Views/Thread/MessageBodyView.swift | 4 ++-- Mail/Views/Thread/WebViewModel.swift | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) 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..35ae494d4 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 keeps 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) } From cb616b5592edb62f5167d190276d382db4b7c423 Mon Sep 17 00:00:00 2001 From: adrien-coye <121806582+adrien-coye@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:04:20 +0200 Subject: [PATCH 2/2] chore: typo --- Mail/Views/Thread/WebViewModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mail/Views/Thread/WebViewModel.swift b/Mail/Views/Thread/WebViewModel.swift index 35ae494d4..e357dc8b4 100644 --- a/Mail/Views/Thread/WebViewModel.swift +++ b/Mail/Views/Thread/WebViewModel.swift @@ -30,7 +30,7 @@ final class WebViewModel: NSObject, ObservableObject { @Published var showBlockQuote = false @Published var contentLoading = true - /// Only true the first time the content loads, then keeps false. Eg. when loading subsequent images. + /// Only true the first time the content loads, then false. Eg. when loading subsequent images. @Published var initialContentLoading = true private var contentLoadingSubscriber: AnyCancellable? @@ -54,7 +54,7 @@ final class WebViewModel: NSObject, ObservableObject { super.init() - /// only register the first flip of contentLoading to false + // only register the first flip of contentLoading to false contentLoadingSubscriber = $contentLoading .filter { $0 == false } .prefix(1)