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.contentsGravity = layer.contentsGravity
view.layer.masksToBounds = layer.masksToBounds view.layer.masksToBounds = layer.masksToBounds
if let mask = layer.mask { if let mask = layer.mask {
let maskLayer = CALayer() if let shapeMask = mask as? CAShapeLayer {
maskLayer.contents = mask.contents let maskLayer = CAShapeLayer()
maskLayer.contentsRect = mask.contentsRect maskLayer.path = shapeMask.path
maskLayer.contentsScale = mask.contentsScale view.layer.mask = maskLayer
maskLayer.contentsCenter = mask.contentsCenter } else {
maskLayer.contentsGravity = mask.contentsGravity let maskLayer = CALayer()
maskLayer.frame = mask.frame maskLayer.contents = mask.contents
maskLayer.bounds = mask.bounds maskLayer.contentsRect = mask.contentsRect
view.layer.mask = maskLayer 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.cornerRadius = layer.cornerRadius
view.layer.backgroundColor = layer.backgroundColor 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?))? { override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? {
if let imageNode = self.imageNode, self.item?.message.id == messageId { if let imageNode = self.imageNode, self.item?.message.id == messageId {
return (imageNode, imageNode.bounds, { [weak imageNode] in 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 { } else {
return nil return nil
@ -164,10 +165,14 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
} }
return (backgroundSize.width, { boundingWidth in return (backgroundSize.width, { boundingWidth in
return (backgroundSize, { [weak self] animation, _ in return (backgroundSize, { [weak self] animation, synchronousLoads in
if let strongSelf = self { if let strongSelf = self {
strongSelf.item = item 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) 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 { if let image = image {
let imageNode: TransformImageNode let imageNode: TransformImageNode
@ -175,18 +180,19 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
imageNode = current imageNode = current
} else { } else {
imageNode = TransformImageNode() imageNode = TransformImageNode()
imageNode.layer.mask = shape
strongSelf.imageNode = imageNode strongSelf.imageNode = imageNode
strongSelf.insertSubnode(imageNode, at: 0) 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.insertSubnode(strongSelf.mediaBackgroundNode, at: 0)
} }
strongSelf.fetchDisposable.set(chatMessagePhotoInteractiveFetched(context: item.context, photoReference: .message(message: MessageReference(item.message), media: image), storeToDownloadsPeerType: nil).start()) 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 imageNode.frame = imageFrame
strongSelf.mediaBackgroundNode.frame = imageFrame.insetBy(dx: -2.0, dy: -2.0) 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.updateLayout(size: imageSize, transition: .immediate)
videoNode.frame = imageFrame videoNode.frame = imageFrame
let maskPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(), size: imageSize))
let shape = CAShapeLayer()
shape.path = maskPath.cgPath
videoNode.layer.mask = shape videoNode.layer.mask = shape
strongSelf.addSubnode(videoNode) 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.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 self.updatingAvatarOverlay.frame = self.avatarNode.frame
let radialStatusSize: CGFloat = true ? 50.0 : 32.0 let radialStatusSize: CGFloat = 32.0
let imagePosition = self.avatarNode.position 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)) 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))