Video avatar fixes

This commit is contained in:
Ilya Laktyushin
2020-07-08 19:01:41 +03:00
parent 9f294c415a
commit c704a143dd
4 changed files with 38 additions and 5 deletions

View File

@@ -493,13 +493,18 @@ final class PeerAvatarImageGalleryItemNode: ZoomableContentGalleryItemNode {
intermediateCompletion()
})
if let _ = self.videoNode {
self.contentNode.view.superview?.bringSubviewToFront(self.contentNode.view)
} else {
self.contentNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25 * durationFactor, removeOnCompletion: false)
}
self.contentNode.layer.animatePosition(from: self.contentNode.layer.position, to: CGPoint(x: transformedSuperFrame.midX, y: transformedSuperFrame.midY), duration: 0.25 * durationFactor, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { _ in
positionCompleted = true
intermediateCompletion()
})
self.contentNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25 * durationFactor, removeOnCompletion: false)
transformedFrame.origin = CGPoint()
let transform = CATransform3DScale(self.contentNode.layer.transform, transformedFrame.size.width / self.contentNode.layer.bounds.size.width, transformedFrame.size.height / self.contentNode.layer.bounds.size.height, 1.0)

View File

@@ -26,6 +26,8 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
let labelNode: TextNode
let filledBackgroundNode: LinkHighlightingNode
var linkHighlightingNode: LinkHighlightingNode?
private let mediaBackgroundNode: ASImageNode
fileprivate var imageNode: TransformImageNode?
fileprivate var videoNode: UniversalVideoNode?
private var videoContent: NativeVideoContent?
@@ -39,6 +41,10 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
self.filledBackgroundNode = LinkHighlightingNode(color: .clear)
self.mediaBackgroundNode = ASImageNode()
self.mediaBackgroundNode.displaysAsynchronously = false
self.mediaBackgroundNode.displayWithoutProcessing = true
super.init()
self.addSubnode(self.filledBackgroundNode)
@@ -104,6 +110,8 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
return { item, layoutConstants, _, _, _ in
let contentProperties = ChatMessageBubbleContentProperties(hidesSimpleAuthorHeader: true, headerSpacing: 0.0, hidesBackground: .always, forceFullCorners: false, forceAlignment: .center)
let instantVideoBackgroundImage = PresentationResourcesChat.chatInstantVideoBackgroundImage(item.presentationData.theme.theme, wallpaper: !item.presentationData.theme.wallpaper.isEmpty)
return (contentProperties, nil, CGFloat.greatestFiniteMagnitude, { constrainedSize, position in
let attributedString = attributedServiceMessageString(theme: item.presentationData.theme, strings: item.presentationData.strings, nameDisplayOrder: item.presentationData.nameDisplayOrder, message: item.message, accountPeerId: item.context.account.peerId)
@@ -173,6 +181,7 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
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))
@@ -180,10 +189,13 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode {
imageNode.setSignal(updateImageSignal)
imageNode.frame = imageFrame
strongSelf.mediaBackgroundNode.frame = imageFrame.insetBy(dx: -2.0, dy: -2.0)
} else if let imageNode = strongSelf.imageNode {
strongSelf.mediaBackgroundNode.removeFromSupernode()
imageNode.removeFromSupernode()
strongSelf.imageNode = nil
}
strongSelf.mediaBackgroundNode.image = instantVideoBackgroundImage
if let image = image, let video = image.videoRepresentations.last, let id = image.id?.id {
let videoFileReference = FileMediaReference.standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 0), partialReference: nil, resource: video.resource, previewRepresentations: image.representations, videoThumbnails: [], immediateThumbnailData: image.immediateThumbnailData, mimeType: "video/mp4", size: nil, attributes: [.Animated, .Video(duration: 0, size: video.dimensions, flags: [])]))

View File

@@ -974,6 +974,8 @@ final class PeerInfoAvatarTransformContainerNode: ASDisplayNode {
private var videoContent: NativeVideoContent?
private var videoStartTimestamp: Double?
var canAttachVideo = true
var tapped: (() -> Void)?
private var isFirstAvatarLoading = true
@@ -1069,7 +1071,7 @@ final class PeerInfoAvatarTransformContainerNode: ASDisplayNode {
if isExpanded == videoNode.canAttachContent {
let update = {
videoNode.canAttachContent = !isExpanded
videoNode.canAttachContent = !isExpanded && self.canAttachVideo
if videoNode.canAttachContent {
if let videoStartTimestamp = self.videoStartTimestamp {
videoNode.seek(videoStartTimestamp)
@@ -1105,6 +1107,8 @@ final class PeerInfoEditingAvatarNode: ASDisplayNode {
var tapped: (() -> Void)?
var cancel: (() -> Void)?
var canAttachVideo = true
init(context: AccountContext) {
self.context = context
let avatarFont = avatarPlaceholderFont(size: floor(100.0 * 16.0 / 37.0))
@@ -1208,7 +1212,7 @@ final class PeerInfoEditingAvatarNode: ASDisplayNode {
videoNode.frame = self.avatarNode.frame
if isEditing != videoNode.canAttachContent {
videoNode.canAttachContent = isEditing
videoNode.canAttachContent = isEditing && self.canAttachVideo
}
}
}

View File

@@ -2133,7 +2133,11 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
case .edit:
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(true, transition: .animated(duration: 0.2, curve: .easeInOut))
strongSelf.state = strongSelf.state.withIsEditing(true)
var updateOnCompletion = false
if strongSelf.headerNode.isAvatarExpanded {
updateOnCompletion = true
strongSelf.headerNode.avatarListNode.avatarContainerNode.canAttachVideo = false
strongSelf.headerNode.editingContentNode.avatarNode.canAttachVideo = false
strongSelf.headerNode.updateIsAvatarExpanded(false, transition: .immediate)
strongSelf.updateNavigationExpansionPresentation(isExpanded: false, animated: true)
}
@@ -2142,7 +2146,15 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
strongSelf.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false)
}
UIView.transition(with: strongSelf.view, duration: 0.3, options: [.transitionCrossDissolve], animations: {
}, completion: nil)
}, completion: { _ in
if updateOnCompletion {
strongSelf.headerNode.avatarListNode.avatarContainerNode.canAttachVideo = true
strongSelf.headerNode.editingContentNode.avatarNode.canAttachVideo = true
if let (layout, navigationHeight) = strongSelf.validLayout {
strongSelf.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false)
}
}
})
strongSelf.controller?.navigationItem.setLeftBarButton(UIBarButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, style: .plain, target: strongSelf, action: #selector(strongSelf.editingCancelPressed)), animated: true)
case .done, .cancel:
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(false, transition: .animated(duration: 0.2, curve: .easeInOut))