Support link pattern

This commit is contained in:
Isaac 2023-12-19 20:14:15 +04:00
parent c6c459c870
commit 5193b54aa9
2 changed files with 62 additions and 21 deletions

View File

@ -875,26 +875,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
animation.animator.updateFrame(layer: self.transformContainer.layer, frame: CGRect(origin: CGPoint(), size: actualSize), completion: nil)
let backgroundFrame = CGRect(origin: CGPoint(x: backgroundInsets.left, y: backgroundInsets.top), size: CGSize(width: actualSize.width - backgroundInsets.left - backgroundInsets.right, height: actualSize.height - backgroundInsets.top - backgroundInsets.bottom))
if displayLine {
let backgroundView: MessageInlineBlockBackgroundView
if let current = self.backgroundView {
backgroundView = current
animation.animator.updateFrame(layer: backgroundView.layer, frame: backgroundFrame, completion: nil)
backgroundView.update(size: backgroundFrame.size, isTransparent: false, primaryColor: mainColor, secondaryColor: secondaryColor, thirdColor: tertiaryColor, backgroundColor: nil, pattern: nil, animation: animation)
} else {
backgroundView = MessageInlineBlockBackgroundView()
self.backgroundView = backgroundView
backgroundView.frame = backgroundFrame
self.transformContainer.view.insertSubview(backgroundView, at: 0)
backgroundView.update(size: backgroundFrame.size, isTransparent: false, primaryColor: mainColor, secondaryColor: secondaryColor, thirdColor: tertiaryColor, backgroundColor: nil, pattern: nil, animation: .None)
}
} else {
if let backgroundView = self.backgroundView {
self.backgroundView = nil
backgroundView.removeFromSuperview()
}
}
var patternTopRightPosition = CGPoint()
if let (inlineMediaValue, inlineMediaSize) = inlineMediaAndSize {
var inlineMediaFrame = CGRect(origin: CGPoint(x: actualSize.width - insets.right - inlineMediaSize.width, y: backgroundInsets.top + inlineMediaEdgeInset), size: inlineMediaSize)
@ -902,6 +883,8 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
inlineMediaFrame.origin.x = insets.left
}
patternTopRightPosition.x = insets.right + inlineMediaSize.width - 6.0
let inlineMedia: TransformImageNode
var updateMedia = false
if let current = self.inlineMedia {
@ -1134,6 +1117,21 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
if let item = contentDisplayOrder.first(where: { $0.item == .media }), let (contentMediaSize, contentMediaApply) = contentMediaSizeAndApply {
let contentMediaFrame = CGRect(origin: CGPoint(x: insets.left, y: item.offsetY), size: contentMediaSize)
var offsetPatternForMedia = false
if let index = contentLayoutOrder.firstIndex(where: { $0 == .media }), index != contentLayoutOrder.count - 1 {
for i in (index + 1) ..< contentLayoutOrder.count {
switch contentLayoutOrder[i] {
case .title, .subtitle, .text:
offsetPatternForMedia = true
default:
break
}
}
}
if offsetPatternForMedia {
patternTopRightPosition.y = contentMediaFrame.maxY + 6.0
}
let contentMedia = contentMediaApply(animation, synchronousLoads)
if self.contentMedia !== contentMedia {
self.contentMedia?.removeFromSupernode()
@ -1303,6 +1301,38 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
self.view.removeGestureRecognizer(tapRecognizer)
}
}
if displayLine {
var pattern: MessageInlineBlockBackgroundView.Pattern?
if let backgroundEmojiId = author?.backgroundEmojiId {
pattern = MessageInlineBlockBackgroundView.Pattern(
context: context,
fileId: backgroundEmojiId,
file: message.associatedMedia[MediaId(
namespace: Namespaces.Media.CloudFile,
id: backgroundEmojiId
)] as? TelegramMediaFile
)
}
let backgroundView: MessageInlineBlockBackgroundView
if let current = self.backgroundView {
backgroundView = current
animation.animator.updateFrame(layer: backgroundView.layer, frame: backgroundFrame, completion: nil)
backgroundView.update(size: backgroundFrame.size, isTransparent: false, primaryColor: mainColor, secondaryColor: secondaryColor, thirdColor: tertiaryColor, backgroundColor: nil, pattern: pattern, patternTopRightPosition: patternTopRightPosition, animation: animation)
} else {
backgroundView = MessageInlineBlockBackgroundView()
self.backgroundView = backgroundView
backgroundView.frame = backgroundFrame
self.transformContainer.view.insertSubview(backgroundView, at: 0)
backgroundView.update(size: backgroundFrame.size, isTransparent: false, primaryColor: mainColor, secondaryColor: secondaryColor, thirdColor: tertiaryColor, backgroundColor: nil, pattern: pattern, patternTopRightPosition: patternTopRightPosition, animation: .None)
}
} else {
if let backgroundView = self.backgroundView {
self.backgroundView = nil
backgroundView.removeFromSuperview()
}
}
})
})
})

View File

@ -459,6 +459,7 @@ public final class MessageInlineBlockBackgroundView: UIView {
var thirdColor: UIColor?
var backgroundColor: UIColor?
var pattern: Pattern?
var patternTopRightPosition: CGPoint?
var displayProgress: Bool
init(
@ -469,6 +470,7 @@ public final class MessageInlineBlockBackgroundView: UIView {
thirdColor: UIColor?,
backgroundColor: UIColor?,
pattern: Pattern?,
patternTopRightPosition: CGPoint?,
displayProgress: Bool
) {
self.size = size
@ -478,6 +480,7 @@ public final class MessageInlineBlockBackgroundView: UIView {
self.thirdColor = thirdColor
self.backgroundColor = backgroundColor
self.pattern = pattern
self.patternTopRightPosition = patternTopRightPosition
self.displayProgress = displayProgress
}
}
@ -608,6 +611,7 @@ public final class MessageInlineBlockBackgroundView: UIView {
thirdColor: UIColor?,
backgroundColor: UIColor?,
pattern: Pattern?,
patternTopRightPosition: CGPoint? = nil,
animation: ListViewItemUpdateAnimation
) {
let params = Params(
@ -618,6 +622,7 @@ public final class MessageInlineBlockBackgroundView: UIView {
thirdColor: thirdColor,
backgroundColor: backgroundColor,
pattern: pattern,
patternTopRightPosition: patternTopRightPosition,
displayProgress: self.displayProgress
)
if self.params == params {
@ -751,8 +756,14 @@ public final class MessageInlineBlockBackgroundView: UIView {
}
patternContentLayer.contents = self.patternContentsTarget?.contents
var patternOrigin = CGPoint(x: size.width, y: 0.0)
if let patternTopRightPosition {
patternOrigin.x -= patternTopRightPosition.x
patternOrigin.y += patternTopRightPosition.y
}
let itemSize = CGSize(width: placement.size / 3.0, height: placement.size / 3.0)
patternContentLayer.frame = CGRect(origin: CGPoint(x: size.width - placement.position.x / 3.0 - itemSize.width * 0.5, y: placement.position.y / 3.0 - itemSize.height * 0.5), size: itemSize)
patternContentLayer.frame = CGRect(origin: CGPoint(x: patternOrigin.x - placement.position.x / 3.0 - itemSize.width * 0.5, y: patternOrigin.y + placement.position.y / 3.0 - itemSize.height * 0.5), size: itemSize)
var alphaFraction = abs(placement.position.x / 3.0) / min(500.0, size.width)
alphaFraction = min(1.0, max(0.0, alphaFraction))
patternContentLayer.opacity = 0.3 * Float(1.0 - alphaFraction)