feat: [WIP] try LinkPresentation
This commit is contained in:
parent
51e8db0c0b
commit
17932dc0fe
@ -12,6 +12,7 @@ import os.log
|
||||
import UIKit
|
||||
import AVKit
|
||||
import Nuke
|
||||
import LinkPresentation
|
||||
|
||||
#if ASDK
|
||||
import AsyncDisplayKit
|
||||
@ -598,6 +599,39 @@ extension StatusSection {
|
||||
|
||||
let isSingleMosaicLayout = mosaics.count == 1
|
||||
|
||||
// set link preview
|
||||
cell.statusView.linkPreview.isHidden = true
|
||||
|
||||
var _firstURL: URL? = {
|
||||
for entity in cell.statusView.activeTextLabel.activeEntities {
|
||||
guard case let .url(_, _, url, _) = entity.type else { continue }
|
||||
return URL(string: url)
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
|
||||
if let url = _firstURL {
|
||||
Future<LPLinkMetadata?, Error> { promise in
|
||||
LPMetadataProvider().startFetchingMetadata(for: url) { meta, error in
|
||||
if let error = error {
|
||||
promise(.failure(error))
|
||||
} else {
|
||||
promise(.success(meta))
|
||||
}
|
||||
}
|
||||
}
|
||||
.receive(on: RunLoop.main)
|
||||
.sink { _ in
|
||||
// do nothing
|
||||
} receiveValue: { [weak cell] meta in
|
||||
guard let meta = meta else { return }
|
||||
guard let cell = cell else { return }
|
||||
cell.statusView.linkPreview.metadata = meta
|
||||
cell.statusView.linkPreview.isHidden = false
|
||||
}
|
||||
.store(in: &cell.disposeBag)
|
||||
}
|
||||
|
||||
// set image
|
||||
let imageSize = CGSize(
|
||||
width: mosaic.imageViewSize.width * imageView.traitCollection.displayScale,
|
||||
|
@ -12,6 +12,7 @@ import AVKit
|
||||
import ActiveLabel
|
||||
import AlamofireImage
|
||||
import FLAnimatedImage
|
||||
import LinkPresentation
|
||||
|
||||
protocol StatusViewDelegate: AnyObject {
|
||||
func statusView(_ statusView: StatusView, headerInfoLabelDidPressed label: UILabel)
|
||||
@ -203,7 +204,9 @@ final class StatusView: UIView {
|
||||
private let headerInfoLabelTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
|
||||
|
||||
var isRevealing = true
|
||||
|
||||
|
||||
let linkPreview = LPLinkView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
_init()
|
||||
@ -357,6 +360,10 @@ extension StatusView {
|
||||
statusContainerStackView.addArrangedSubview(activeTextLabel)
|
||||
activeTextLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
||||
|
||||
// link preview
|
||||
statusContainerStackView.addArrangedSubview(linkPreview)
|
||||
linkPreview.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
|
||||
// image
|
||||
statusContainerStackView.addArrangedSubview(statusMosaicImageViewContainer)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user