Skip to content

Commit

Permalink
Merge pull request #815 from Infomaniak/loadingStateIssues
Browse files Browse the repository at this point in the history
feat: fix glitchy loading view
  • Loading branch information
PhilippeWeidmann committed Jun 16, 2023
2 parents 607b358 + cb616b5 commit 83bf55c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 83bf55c

Please sign in to comment.