Eliminate popping when scrolling
This commit makes a few changes: - Link preview views are no longer cached, only the metadata. This fixes a memory leak when preview videos. It will keep playing the video forever eventually leading to a crash. This is fixed! - Cache the intrinsic height of previews, when loading notes it looks for the cached height so that things don't pop-in after the fact - Note artifacts and previews are set in the constructor instead of onAppear, this prevents the size from changing and popping after it has been loaded into the lazyvstack Changelog-Fixed: Fix memory leak with inline videos Changelog-Fixed: Eliminate popping when scrolling
This commit is contained in:
@@ -10,10 +10,11 @@ import LinkPresentation
|
||||
|
||||
class CustomLinkView: LPLinkView {
|
||||
override var intrinsicContentSize: CGSize { CGSize(width: 0, height: super.intrinsicContentSize.height) }
|
||||
|
||||
}
|
||||
|
||||
enum Metadata {
|
||||
case linkmeta(LPLinkMetadata)
|
||||
case linkmeta(CachedMetadata)
|
||||
case url(URL)
|
||||
}
|
||||
|
||||
@@ -26,12 +27,19 @@ struct LinkViewRepresentable: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> CustomLinkView {
|
||||
switch meta {
|
||||
case .linkmeta(let linkmeta):
|
||||
return CustomLinkView(metadata: linkmeta)
|
||||
return CustomLinkView(metadata: linkmeta.meta)
|
||||
case .url(let url):
|
||||
return CustomLinkView(url: url)
|
||||
}
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: CustomLinkView, context: Context) {
|
||||
switch meta {
|
||||
case .linkmeta(let cached):
|
||||
cached.intrinsic_height = uiView.intrinsicContentSize.height
|
||||
case .url:
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,18 @@
|
||||
import Foundation
|
||||
import LinkPresentation
|
||||
|
||||
class CachedMetadata {
|
||||
let meta: LPLinkMetadata
|
||||
var intrinsic_height: CGFloat?
|
||||
|
||||
init(meta: LPLinkMetadata) {
|
||||
self.meta = meta
|
||||
self.intrinsic_height = nil
|
||||
}
|
||||
}
|
||||
|
||||
enum Preview {
|
||||
case value(LinkViewRepresentable)
|
||||
case value(CachedMetadata)
|
||||
case failed
|
||||
}
|
||||
|
||||
@@ -20,12 +30,12 @@ class PreviewCache {
|
||||
return previews[evid]
|
||||
}
|
||||
|
||||
func store(evid: String, preview: LinkViewRepresentable?) {
|
||||
func store(evid: String, preview: LPLinkMetadata?) {
|
||||
switch preview {
|
||||
case .none:
|
||||
previews[evid] = .failed
|
||||
case .some(let meta):
|
||||
previews[evid] = .value(meta)
|
||||
previews[evid] = .value(CachedMetadata(meta: meta))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user