Clean up link preview UI a bit more.

This commit is contained in:
Igor Solomennikov 2026-03-04 22:04:37 -08:00 committed by GitHub
parent 0fbd5b8702
commit d3da4e132e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 53 deletions

View File

@ -62,8 +62,8 @@ class CVLinkPreviewView: ManualStackViewWithLayer {
for linkPreview: LinkPreviewState,
isIncoming: Bool,
) -> CVLinkPreviewViewAdapter {
if linkPreview.isGroupInviteLink {
return CVLinkPreviewViewAdapterGroupLink(linkPreview: linkPreview, isIncoming: isIncoming)
if linkPreview.isGroupInviteLink || linkPreview.isCallLink {
return CVLinkPreviewViewAdapterSignalLink(linkPreview: linkPreview, isIncoming: isIncoming)
}
if linkPreview.hasLoadedImageOrBlurHash, sentIsHero(linkPreview: linkPreview) {
return CVLinkPreviewViewAdapterLarge(linkPreview: linkPreview, isIncoming: isIncoming)
@ -197,9 +197,9 @@ private class CVLinkPreviewViewAdapter {
var rootStackConfig: ManualStackView.Config {
ManualStackView.Config(
axis: .horizontal,
alignment: .center,
spacing: 8,
layoutMargins: UIEdgeInsets(margin: 12),
alignment: .top,
spacing: 12,
layoutMargins: UIEdgeInsets(margin: 10),
)
}
@ -383,7 +383,7 @@ private class CVLinkPreviewViewAdapter {
// MARK: -
// Does not have domain name. Image is round.
private class CVLinkPreviewViewAdapterGroupLink: CVLinkPreviewViewAdapter {
private class CVLinkPreviewViewAdapterSignalLink: CVLinkPreviewViewAdapter {
override func rootStackSubviewInfos(
maxWidth: CGFloat,
@ -420,7 +420,7 @@ private class CVLinkPreviewViewAdapterGroupLink: CVLinkPreviewViewAdapter {
if linkPreview.hasLoadedImageOrBlurHash {
let linkPreviewImageView = linkPreviewView.linkPreviewImageView
if let imageView = linkPreviewImageView.configure(linkPreview: linkPreview, rounding: .circular) {
if let imageView = linkPreviewImageView.configure(linkPreview: linkPreview, cornerStyle: .capsule) {
imageView.clipsToBounds = true
rootStackSubviews.append(imageView)
} else {
@ -437,36 +437,6 @@ private class CVLinkPreviewViewAdapterGroupLink: CVLinkPreviewViewAdapter {
return rootStackSubviews
}
// Only title and description.
override func textStackSubviewInfos(maxWidth: CGFloat) -> [ManualStackSubviewInfo] {
var subviewInfos = [ManualStackSubviewInfo]()
if let labelConfig = sentTitleLabelConfig() {
let labelSize = CVText.measureLabel(config: labelConfig, maxWidth: maxWidth)
subviewInfos.append(labelSize.asManualSubviewInfo)
}
if let labelConfig = sentDescriptionLabelConfig() {
let labelSize = CVText.measureLabel(config: labelConfig, maxWidth: maxWidth)
subviewInfos.append(labelSize.asManualSubviewInfo)
}
return subviewInfos
}
// Only title and description.
override func textStackSubviews() -> [CVLabel] {
var subviews = [CVLabel]()
if let titleLabel = sentTitleLabel() {
subviews.append(titleLabel)
}
if let descriptionLabel = sentDescriptionLabel() {
subviews.append(descriptionLabel)
}
return subviews
}
}
// MARK: -
@ -526,7 +496,7 @@ private class CVLinkPreviewViewAdapterLarge: CVLinkPreviewViewAdapter {
var rootStackSubviews = [UIView]()
let linkPreviewImageView = linkPreviewView.linkPreviewImageView
if let imageView = linkPreviewImageView.configure(linkPreview: linkPreview) {
if let imageView = linkPreviewImageView.configure(linkPreview: linkPreview, cornerStyle: .square) {
imageView.clipsToBounds = true
rootStackSubviews.append(imageView)
} else {
@ -601,7 +571,7 @@ private class CVLinkPreviewViewAdapterCompact: CVLinkPreviewViewAdapter {
if linkPreview.hasLoadedImageOrBlurHash {
let linkPreviewImageView = linkPreviewView.linkPreviewImageView
if let imageView = linkPreviewImageView.configure(linkPreview: linkPreview) {
if let imageView = linkPreviewImageView.configure(linkPreview: linkPreview, cornerStyle: .rounded(radius: 6)) {
imageView.clipsToBounds = true
rootStackSubviews.append(imageView)
} else {
@ -624,12 +594,13 @@ private class CVLinkPreviewViewAdapterCompact: CVLinkPreviewViewAdapter {
private class CVLinkPreviewImageView: ManualLayoutViewWithLayer {
enum Rounding: UInt {
case none
case circular
enum CornerStyle {
case square
case rounded(radius: CGFloat)
case capsule
}
var rounding: Rounding = .none {
var cornerStyle: CornerStyle = .square {
didSet {
updateCornerRounding()
}
@ -669,17 +640,20 @@ private class CVLinkPreviewImageView: ManualLayoutViewWithLayer {
imageView.reset()
iconView.reset()
rounding = .none
cornerStyle = .square
isHero = false
configurationId = 0
}
private func updateCornerRounding() {
switch rounding {
case .none:
switch cornerStyle {
case .square:
layer.cornerRadius = 0
case .circular:
case .rounded(let radius):
layer.cornerRadius = radius
case .capsule:
layer.cornerRadius = bounds.size.smallerAxis / 2
}
}
@ -689,7 +663,7 @@ private class CVLinkPreviewImageView: ManualLayoutViewWithLayer {
shouldEvacuateInBackground: true,
)
func configure(linkPreview: LinkPreviewState, rounding: Rounding = .none) -> UIView? {
func configure(linkPreview: LinkPreviewState, cornerStyle: CornerStyle) -> UIView? {
switch linkPreview.imageState {
case .loaded:
break
@ -708,7 +682,7 @@ private class CVLinkPreviewImageView: ManualLayoutViewWithLayer {
addSubviewToFillSuperviewEdges(imageView)
addSubviewToCenterOnSuperview(iconView, size: .square(36))
}
self.rounding = rounding
self.cornerStyle = cornerStyle
isHero = CVLinkPreviewView.sentIsHero(linkPreview: linkPreview)
let configurationId = Self.configurationIdCounter.increment()
self.configurationId = configurationId

View File

@ -109,7 +109,9 @@ public class LinkPreviewCallLink: LinkPreviewState {
}
}
public let isGroupInviteLink = false
public var isGroupInviteLink: Bool { false }
public var isCallLink: Bool { true }
}
public class CommonCallLinksUI {

View File

@ -117,7 +117,9 @@ class LinkPreviewGroupLink: LinkPreviewState {
var date: Date? { linkPreview.date }
let isGroupInviteLink = true
var isGroupInviteLink: Bool { true }
var isCallLink: Bool { false }
}
// MARK: -

View File

@ -49,6 +49,7 @@ public protocol LinkPreviewState: AnyObject {
var previewDescription: String? { get }
var date: Date? { get }
var isGroupInviteLink: Bool { get }
var isCallLink: Bool { get }
var conversationStyle: ConversationStyle? { get }
}
@ -130,6 +131,8 @@ public class LinkPreviewLoading: LinkPreviewState {
}
}
public var isCallLink: Bool { false }
public var conversationStyle: ConversationStyle? { nil }
}
@ -215,7 +218,9 @@ public class LinkPreviewDraft: LinkPreviewState {
public var date: Date? { linkPreviewDraft.date }
public let isGroupInviteLink = false
public var isGroupInviteLink: Bool { false }
public var isCallLink: Bool { false }
public var conversationStyle: ConversationStyle? { nil }
}
@ -371,5 +376,7 @@ public class LinkPreviewSent: LinkPreviewState {
public var date: Date? { linkPreview.date }
public let isGroupInviteLink = false
public var isGroupInviteLink: Bool { false }
public var isCallLink: Bool { false }
}