reload web view if article highlights had been mutated from the highlits list modal
This commit is contained in:
@ -70,6 +70,7 @@ struct WebReader: PlatformViewRepresentable {
|
||||
context.coordinator.linkHandler = openLinkAction
|
||||
context.coordinator.webViewActionHandler = webViewActionHandler
|
||||
context.coordinator.updateNavBarVisibilityRatio = navBarVisibilityRatioUpdater
|
||||
context.coordinator.articleContentID = articleContent.id
|
||||
loadContent(webView: webView)
|
||||
|
||||
return webView
|
||||
@ -101,8 +102,10 @@ struct WebReader: PlatformViewRepresentable {
|
||||
}
|
||||
|
||||
// If the webview had been terminated `needsReload` will have been set to true
|
||||
if context.coordinator.needsReload {
|
||||
// Or if the articleContent value has changed then it's id will be different from the coordinator's
|
||||
if context.coordinator.needsReload || context.coordinator.articleContentID != articleContent.id {
|
||||
loadContent(webView: webView)
|
||||
context.coordinator.articleContentID = articleContent.id
|
||||
context.coordinator.needsReload = false
|
||||
return
|
||||
}
|
||||
|
||||
@ -46,8 +46,20 @@ struct WebReaderContainerView: View {
|
||||
}
|
||||
|
||||
func onHighlightListViewDismissal() {
|
||||
print("has mutations: \(hasPerformedHighlightMutations)")
|
||||
hasPerformedHighlightMutations = false
|
||||
// Reload the web view if mutation happened in highlights list modal
|
||||
guard hasPerformedHighlightMutations else { return }
|
||||
|
||||
hasPerformedHighlightMutations.toggle()
|
||||
|
||||
Task {
|
||||
if let username = dataService.currentViewer?.username {
|
||||
await viewModel.loadContent(
|
||||
dataService: dataService,
|
||||
username: username,
|
||||
itemID: item.unwrappedID
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleHighlightAction(message: WKScriptMessage) {
|
||||
|
||||
@ -19,6 +19,7 @@ final class WebReaderCoordinator: NSObject {
|
||||
var previousShowNavBarActionID: UUID?
|
||||
var previousShareActionID: UUID?
|
||||
var updateNavBarVisibilityRatio: (Double) -> Void = { _ in }
|
||||
var articleContentID = UUID()
|
||||
private var yOffsetAtStartOfDrag: Double?
|
||||
private var lastYOffset: Double = 0
|
||||
private var hasDragged = false
|
||||
|
||||
@ -9,6 +9,7 @@ public enum ArticleContentStatus: String {
|
||||
}
|
||||
|
||||
public struct ArticleContent {
|
||||
public let id = UUID()
|
||||
public let title: String
|
||||
public let htmlContent: String
|
||||
public let highlightsJSONString: String
|
||||
|
||||
Reference in New Issue
Block a user