Make article rendering stop flashing!

This commit is contained in:
Maurice Parker 2020-07-16 11:14:05 -05:00
parent 9836fb781c
commit 5f573fc985
4 changed files with 18 additions and 9 deletions

View File

@ -12,10 +12,9 @@ import Articles
struct ArticleContainerView: View { struct ArticleContainerView: View {
@EnvironmentObject private var sceneModel: SceneModel @EnvironmentObject private var sceneModel: SceneModel
var articles: [Article]
@ViewBuilder var body: some View { @ViewBuilder var body: some View {
ArticleView(sceneModel: sceneModel, articles: articles) ArticleView(sceneModel: sceneModel)
.modifier(ArticleToolbarModifier()) .modifier(ArticleToolbarModifier())
} }

View File

@ -36,7 +36,7 @@ struct TimelineView: View {
.help(timelineModel.isReadFiltered ?? false ? "Show Read Articles" : "Filter Read Articles") .help(timelineModel.isReadFiltered ?? false ? "Show Read Articles" : "Filter Read Articles")
} }
ZStack { ZStack {
NavigationLink(destination: ArticleContainerView(articles: timelineModel.selectedArticles), isActive: $navigate) { NavigationLink(destination: ArticleContainerView(), isActive: $navigate) {
EmptyView() EmptyView()
}.hidden() }.hidden()
List(timelineModel.timelineItems, selection: $timelineModel.selectedArticleIDs) { timelineItem in List(timelineModel.timelineItems, selection: $timelineModel.selectedArticleIDs) { timelineItem in

View File

@ -12,17 +12,14 @@ import Articles
struct ArticleView: NSViewControllerRepresentable { struct ArticleView: NSViewControllerRepresentable {
var sceneModel: SceneModel var sceneModel: SceneModel
var articles: [Article]
func makeNSViewController(context: Context) -> WebViewController { func makeNSViewController(context: Context) -> WebViewController {
let controller = WebViewController() let controller = WebViewController()
controller.sceneModel = sceneModel controller.sceneModel = sceneModel
controller.articles = articles
return controller return controller
} }
func updateNSViewController(_ uiViewController: WebViewController, context: Context) { func updateNSViewController(_ controller: WebViewController, context: Context) {
} }
} }

View File

@ -7,6 +7,7 @@
// //
import AppKit import AppKit
import Combine
import RSCore import RSCore
import Articles import Articles
@ -46,7 +47,15 @@ class WebViewController: NSViewController {
var sceneModel: SceneModel? var sceneModel: SceneModel?
weak var delegate: WebViewControllerDelegate? weak var delegate: WebViewControllerDelegate?
var articles: [Article]? var articles: [Article]? {
didSet {
if oldValue != articles {
loadWebView()
}
}
}
private var selectedArticlesCancellable: AnyCancellable?
override func loadView() { override func loadView() {
view = NSView() view = NSView()
@ -71,7 +80,9 @@ class WebViewController: NSViewController {
statusBarView.heightAnchor.constraint(equalToConstant: 20) statusBarView.heightAnchor.constraint(equalToConstant: 20)
]) ])
loadWebView() selectedArticlesCancellable = sceneModel?.timelineModel.$selectedArticles.sink { [weak self] articles in
self?.articles = articles
}
} }
// MARK: Notifications // MARK: Notifications
@ -235,6 +246,8 @@ private extension WebViewController {
sceneModel?.webViewProvider?.dequeueWebView() { webView in sceneModel?.webViewProvider?.dequeueWebView() { webView in
// Add the webview // Add the webview
self.webView = webView
webView.translatesAutoresizingMaskIntoConstraints = false webView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(webView, positioned: .below, relativeTo: self.statusBarView) self.view.addSubview(webView, positioned: .below, relativeTo: self.statusBarView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([