Video avatar fixes

This commit is contained in:
Ilya Laktyushin 2020-07-08 21:29:56 +03:00
parent b09e92719b
commit b4e7fcf004
3 changed files with 31 additions and 21 deletions

View File

@ -377,15 +377,21 @@ private func makeSubtreeSnapshot(layer: CALayer, keepTransform: Bool = false) ->
view.layer.contentsGravity = layer.contentsGravity
view.layer.masksToBounds = layer.masksToBounds
if let mask = layer.mask {
let maskLayer = CALayer()
maskLayer.contents = mask.contents
maskLayer.contentsRect = mask.contentsRect
maskLayer.contentsScale = mask.contentsScale
maskLayer.contentsCenter = mask.contentsCenter
maskLayer.contentsGravity = mask.contentsGravity
maskLayer.frame = mask.frame
maskLayer.bounds = mask.bounds
view.layer.mask = maskLayer
if let shapeMask = mask as? CAShapeLayer {
let maskLayer = CAShapeLayer()
maskLayer.path = shapeMask.path
view.layer.mask = maskLayer
} else {
let maskLayer = CALayer()
maskLayer.contents = mask.contents
maskLayer.contentsRect = mask.contentsRect
maskLayer.contentsScale = mask.contentsScale
maskLayer.contentsCenter = mask.contentsCenter
maskLayer.contentsGravity = mask.contentsGravity
maskLayer.frame = mask.frame
maskLayer.bounds = mask.bounds
view.layer.mask = maskLayer
}
}
view.layer.cornerRadius = layer.cornerRadius
view.layer.backgroundColor = layer.backgroundColor

View File

@ -66,7 +66,8 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? {
if let imageNode = self.imageNode, self.item?.message.id == messageId {
return (imageNode, imageNode.bounds, { [weak imageNode] in
return (imageNode?.view.snapshotContentTree(unhide: true), nil)
let snapshot = imageNode?.view.snapshotContentTree(unhide: true)
return (snapshot, nil)
})
} else {
return nil
@ -164,10 +165,14 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
}
return (backgroundSize.width, { boundingWidth in
return (backgroundSize, { [weak self] animation, _ in
return (backgroundSize, { [weak self] animation, synchronousLoads in
if let strongSelf = self {
strongSelf.item = item
let maskPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(), size: imageSize))
let shape = CAShapeLayer()
shape.path = maskPath.cgPath
let imageFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((backgroundSize.width - imageSize.width) / 2.0), y: labelLayout.size.height + 10 + 2), size: imageSize)
if let image = image {
let imageNode: TransformImageNode
@ -175,18 +180,19 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
imageNode = current
} else {
imageNode = TransformImageNode()
imageNode.layer.mask = shape
strongSelf.imageNode = imageNode
strongSelf.insertSubnode(imageNode, at: 0)
let arguments = TransformImageArguments(corners: ImageCorners(radius: imageSize.width / 2), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets())
let apply = imageNode.asyncLayout()(arguments)
apply()
strongSelf.insertSubnode(strongSelf.mediaBackgroundNode, at: 0)
}
strongSelf.fetchDisposable.set(chatMessagePhotoInteractiveFetched(context: item.context, photoReference: .message(message: MessageReference(item.message), media: image), storeToDownloadsPeerType: nil).start())
let updateImageSignal = chatMessagePhoto(postbox: item.context.account.postbox, photoReference: .message(message: MessageReference(item.message), media: image))
let updateImageSignal = chatMessagePhoto(postbox: item.context.account.postbox, photoReference: .message(message: MessageReference(item.message), media: image), synchronousLoad: synchronousLoads)
imageNode.setSignal(updateImageSignal)
imageNode.setSignal(updateImageSignal, attemptSynchronously: synchronousLoads)
let arguments = TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets())
let apply = imageNode.asyncLayout()(arguments)
apply()
imageNode.frame = imageFrame
strongSelf.mediaBackgroundNode.frame = imageFrame.insetBy(dx: -2.0, dy: -2.0)
@ -215,9 +221,7 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
videoNode.updateLayout(size: imageSize, transition: .immediate)
videoNode.frame = imageFrame
let maskPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(), size: imageSize))
let shape = CAShapeLayer()
shape.path = maskPath.cgPath
videoNode.layer.mask = shape
strongSelf.addSubnode(videoNode)

View File

@ -1130,7 +1130,7 @@ final class PeerInfoEditingAvatarNode: ASDisplayNode {
self.avatarNode.frame = CGRect(origin: CGPoint(x: -50.0, y: -50.0), size: CGSize(width: 100.0, height: 100.0))
self.updatingAvatarOverlay.frame = self.avatarNode.frame
let radialStatusSize: CGFloat = true ? 50.0 : 32.0
let radialStatusSize: CGFloat = 32.0
let imagePosition = self.avatarNode.position
statusNode.frame = CGRect(origin: CGPoint(x: floor(imagePosition.x - radialStatusSize / 2.0), y: floor(imagePosition.y - radialStatusSize / 2.0)), size: CGSize(width: radialStatusSize, height: radialStatusSize))