forked from zelo72/mastodon-ios
feat: [WIP] try LinkPresentation
This commit is contained in:
parent
51e8db0c0b
commit
17932dc0fe
|
@ -12,6 +12,7 @@ import os.log
|
||||||
import UIKit
|
import UIKit
|
||||||
import AVKit
|
import AVKit
|
||||||
import Nuke
|
import Nuke
|
||||||
|
import LinkPresentation
|
||||||
|
|
||||||
#if ASDK
|
#if ASDK
|
||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
|
@ -598,6 +599,39 @@ extension StatusSection {
|
||||||
|
|
||||||
let isSingleMosaicLayout = mosaics.count == 1
|
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
|
// set image
|
||||||
let imageSize = CGSize(
|
let imageSize = CGSize(
|
||||||
width: mosaic.imageViewSize.width * imageView.traitCollection.displayScale,
|
width: mosaic.imageViewSize.width * imageView.traitCollection.displayScale,
|
||||||
|
|
|
@ -12,6 +12,7 @@ import AVKit
|
||||||
import ActiveLabel
|
import ActiveLabel
|
||||||
import AlamofireImage
|
import AlamofireImage
|
||||||
import FLAnimatedImage
|
import FLAnimatedImage
|
||||||
|
import LinkPresentation
|
||||||
|
|
||||||
protocol StatusViewDelegate: AnyObject {
|
protocol StatusViewDelegate: AnyObject {
|
||||||
func statusView(_ statusView: StatusView, headerInfoLabelDidPressed label: UILabel)
|
func statusView(_ statusView: StatusView, headerInfoLabelDidPressed label: UILabel)
|
||||||
|
@ -203,7 +204,9 @@ final class StatusView: UIView {
|
||||||
private let headerInfoLabelTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
|
private let headerInfoLabelTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
|
||||||
|
|
||||||
var isRevealing = true
|
var isRevealing = true
|
||||||
|
|
||||||
|
let linkPreview = LPLinkView()
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
_init()
|
_init()
|
||||||
|
@ -357,6 +360,10 @@ extension StatusView {
|
||||||
statusContainerStackView.addArrangedSubview(activeTextLabel)
|
statusContainerStackView.addArrangedSubview(activeTextLabel)
|
||||||
activeTextLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
activeTextLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
||||||
|
|
||||||
|
// link preview
|
||||||
|
statusContainerStackView.addArrangedSubview(linkPreview)
|
||||||
|
linkPreview.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||||
|
|
||||||
// image
|
// image
|
||||||
statusContainerStackView.addArrangedSubview(statusMosaicImageViewContainer)
|
statusContainerStackView.addArrangedSubview(statusMosaicImageViewContainer)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue