mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Update API
This commit is contained in:
@@ -142,6 +142,8 @@ public class DrawingStickerEntityView: DrawingEntityView {
|
||||
return image
|
||||
} else if case .message = self.stickerEntity.content {
|
||||
return self.animatedImageView?.image
|
||||
} else if case .gift = self.stickerEntity.content {
|
||||
return self.animatedImageView?.image
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
@@ -167,7 +169,7 @@ public class DrawingStickerEntityView: DrawingEntityView {
|
||||
return file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0)
|
||||
case .dualVideoReference:
|
||||
return CGSize(width: 512.0, height: 512.0)
|
||||
case let .message(_, size, _, _, _):
|
||||
case let .message(_, size, _, _, _), let .gift(_, size):
|
||||
return size
|
||||
}
|
||||
}
|
||||
@@ -296,6 +298,43 @@ public class DrawingStickerEntityView: DrawingEntityView {
|
||||
if let file, let _ = mediaRect {
|
||||
self.setupWithVideo(file)
|
||||
}
|
||||
} else if case let .gift(gift, _) = self.stickerEntity.content {
|
||||
if let image = self.stickerEntity.renderImage {
|
||||
self.setupWithImage(image, overlayImage: self.stickerEntity.overlayRenderImage)
|
||||
}
|
||||
|
||||
var file: TelegramMediaFile?
|
||||
for attribute in gift.attributes {
|
||||
if case let .model(_, fileValue, _) = attribute {
|
||||
file = fileValue
|
||||
break
|
||||
}
|
||||
}
|
||||
guard let file, let dimensions = file.dimensions else {
|
||||
return
|
||||
}
|
||||
if self.animationNode == nil {
|
||||
let animationNode = DefaultAnimatedStickerNodeImpl()
|
||||
animationNode.clipsToBounds = true
|
||||
animationNode.autoplay = false
|
||||
self.animationNode = animationNode
|
||||
animationNode.started = { [weak self, weak animationNode] in
|
||||
self?.imageNode.isHidden = true
|
||||
|
||||
if let animationNode = animationNode {
|
||||
let _ = (animationNode.status
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||
self?.started?(status.duration)
|
||||
})
|
||||
}
|
||||
}
|
||||
self.addSubnode(self.imageNode)
|
||||
self.addSubnode(animationNode)
|
||||
}
|
||||
self.imageNode.setSignal(chatMessageAnimatedSticker(postbox: self.context.account.postbox, userLocation: .other, file: file, small: false, size: dimensions.cgSize.aspectFitted(CGSize(width: 256.0, height: 256.0))))
|
||||
self.stickerFetchedDisposable.set(freeMediaFileResourceInteractiveFetched(account: self.context.account, userLocation: .other, fileReference: stickerPackFileReference(file), resource: file.resource).start())
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +457,18 @@ public class DrawingStickerEntityView: DrawingEntityView {
|
||||
if self.isPlaying != isPlaying {
|
||||
self.isPlaying = isPlaying
|
||||
|
||||
if let file = self.file {
|
||||
var file: TelegramMediaFile?
|
||||
if let fileValue = self.file {
|
||||
file = fileValue
|
||||
} else if case let .gift(gift, _) = self.stickerEntity.content {
|
||||
for attribute in gift.attributes {
|
||||
if case let .model(_, fileValue, _) = attribute {
|
||||
file = fileValue
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if let file {
|
||||
if isPlaying && !self.didSetUpAnimationNode {
|
||||
self.didSetUpAnimationNode = true
|
||||
let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512)
|
||||
@@ -596,15 +646,22 @@ public class DrawingStickerEntityView: DrawingEntityView {
|
||||
|
||||
let imageSize = self.dimensions.aspectFitted(boundingSize)
|
||||
let imageFrame = CGRect(origin: CGPoint(x: floor((size.width - imageSize.width) / 2.0), y: (size.height - imageSize.height) / 2.0), size: imageSize)
|
||||
|
||||
self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))()
|
||||
self.imageNode.frame = imageFrame
|
||||
|
||||
var animationSize = CGSize(width: imageSize.width, height: imageSize.width)
|
||||
var animationFrame = imageFrame
|
||||
if case .gift = self.stickerEntity.content {
|
||||
animationSize = CGSize(width: animationSize.width * 0.48, height: animationSize.height * 0.48)
|
||||
animationFrame = CGRect(origin: CGPoint(x: floor((size.width - animationSize.width) / 2.0), y: 22.0), size: animationSize)
|
||||
}
|
||||
|
||||
self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: animationSize, boundingSize: animationSize, intrinsicInsets: UIEdgeInsets()))()
|
||||
self.imageNode.frame = animationFrame
|
||||
if let animationNode = self.animationNode {
|
||||
if self.isReaction {
|
||||
animationNode.cornerRadius = floor(imageSize.width * 0.1)
|
||||
animationNode.cornerRadius = floor(animationSize.width * 0.1)
|
||||
}
|
||||
animationNode.frame = imageFrame
|
||||
animationNode.updateLayout(size: imageSize)
|
||||
animationNode.frame = animationFrame
|
||||
animationNode.updateLayout(size: animationSize)
|
||||
|
||||
if !self.didApplyVisibility {
|
||||
self.didApplyVisibility = true
|
||||
@@ -818,6 +875,35 @@ public class DrawingStickerEntityView: DrawingEntityView {
|
||||
|
||||
return entities
|
||||
}
|
||||
} else if case let .gift(gift, _) = self.stickerEntity.content {
|
||||
var file: TelegramMediaFile?
|
||||
for attribute in gift.attributes {
|
||||
if case let .model(_, fileValue, _) = attribute {
|
||||
file = fileValue
|
||||
break
|
||||
}
|
||||
}
|
||||
if let file, let animationNode = self.animationNode {
|
||||
let stickerSize = self.bounds.size
|
||||
let stickerPosition = self.stickerEntity.position
|
||||
let videoSize = animationNode.frame.size
|
||||
let scale = self.stickerEntity.scale
|
||||
let rotation = self.stickerEntity.rotation
|
||||
|
||||
let videoPosition = animationNode.position.offsetBy(dx: -stickerSize.width / 2.0, dy: -stickerSize.height / 2.0)
|
||||
let videoScale = videoSize.width / stickerSize.width
|
||||
|
||||
let videoEntity = DrawingStickerEntity(content: .file(.standalone(media: file), .sticker))
|
||||
videoEntity.referenceDrawingSize = self.stickerEntity.referenceDrawingSize
|
||||
videoEntity.position = stickerPosition.offsetBy(
|
||||
dx: (videoPosition.x * cos(rotation) - videoPosition.y * sin(rotation)) * scale,
|
||||
dy: (videoPosition.y * cos(rotation) + videoPosition.x * sin(rotation)) * scale
|
||||
)
|
||||
videoEntity.scale = scale * videoScale
|
||||
videoEntity.rotation = rotation
|
||||
|
||||
return [videoEntity]
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
@@ -1103,6 +1189,9 @@ final class DrawingStickerEntitySelectionView: DrawingEntitySelectionView {
|
||||
if case .message = entity.content {
|
||||
cornerRadius *= 2.1
|
||||
count = 24
|
||||
} else if case .gift = entity.content {
|
||||
cornerRadius *= 2.1
|
||||
count = 24
|
||||
} else if case .image = entity.content {
|
||||
count = 24
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user