Video avatar fixes

This commit is contained in:
Ilya Laktyushin 2020-07-09 00:26:16 +03:00
parent 5795542022
commit c4229494e8
10 changed files with 3308 additions and 3259 deletions

View File

@ -5679,6 +5679,8 @@ Any member of this group will be able to see messages in the channel.";
"Settings.EditAccount" = "Edit Account";
"Settings.EditPhoto" = "Edit Photo";
"Settings.EditVideo" = "Edit Video";
"Settings.CancelUpload" = "Cancel Upload";
"Settings.FrequentlyAskedQuestions" = "Frequently Asked Questions";
@ -5690,3 +5692,5 @@ Any member of this group will be able to see messages in the channel.";
"Conversation.Dice.u26BD" = "Send a football emoji to do a free kick.";
"SettingsSearch_Synonyms_ChatFolders" = "";
"EditProfile.NameAndPhotoOrVideoHelp" = "Enter your name and add an optional profile photo or video.";

View File

@ -3,6 +3,7 @@ import UIKit
import AsyncDisplayKit
public enum ContainedViewLayoutTransitionCurve {
case linear
case easeInOut
case spring
case custom(Float, Float, Float, Float)
@ -15,6 +16,8 @@ public enum ContainedViewLayoutTransitionCurve {
public extension ContainedViewLayoutTransitionCurve {
var timingFunction: String {
switch self {
case .linear:
return CAMediaTimingFunctionName.linear.rawValue
case .easeInOut:
return CAMediaTimingFunctionName.easeInEaseOut.rawValue
case .spring:
@ -26,6 +29,8 @@ public extension ContainedViewLayoutTransitionCurve {
var mediaTimingFunction: CAMediaTimingFunction? {
switch self {
case .linear:
return nil
case .easeInOut:
return nil
case .spring:
@ -38,6 +43,8 @@ public extension ContainedViewLayoutTransitionCurve {
#if os(iOS)
var viewAnimationOptions: UIView.AnimationOptions {
switch self {
case .linear:
return [.curveLinear]
case .easeInOut:
return [.curveEaseInOut]
case .spring:

View File

@ -3231,6 +3231,8 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
offset = -offset
}
switch curve {
case .linear:
headerNode.layer.animateBoundsOriginYAdditive(from: offset, to: 0.0, duration: duration, mediaTimingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear))
case .spring:
transition.0.animateOffsetAdditive(node: headerNode, offset: offset)
case let .custom(p1, p2, p3, p4):

View File

@ -187,7 +187,7 @@ public func listViewAnimationDurationAndCurve(transition: ContainedViewLayoutTra
case let .animated(animationDuration, animationCurve):
duration = animationDuration
switch animationCurve {
case .easeInOut, .custom:
case .linear, .easeInOut, .custom:
break
case .spring:
curve = 7

View File

@ -707,7 +707,7 @@ public class AvatarGalleryController: ViewController, StandalonePresentableContr
})
}))
if let position = rawEntry.indexData?.position, position > 0 {
if self.peer.id == self.context.account.peerId, let position = rawEntry.indexData?.position, position > 0 {
let title: String
if let _ = rawEntry.videoRepresentations.last {
title = self.presentationData.strings.ProfilePhoto_SetMainVideo

View File

@ -19,6 +19,7 @@ import ItemListPeerItem
import ItemListPeerActionItem
private let maxUsersDisplayedLimit: Int32 = 10
private let maxUsersDisplayedHighLimit: Int32 = 12
private final class GroupStatsControllerArguments {
let context: AccountContext
@ -525,7 +526,7 @@ private func groupStatsControllerEntries(state: GroupStatsState, data: GroupStat
var topPosters = data.topPosters
var effectiveExpanded = state.topPostersExpanded
if topPosters.count > maxUsersDisplayedLimit && !effectiveExpanded {
if topPosters.count > maxUsersDisplayedHighLimit && !effectiveExpanded {
topPosters = Array(topPosters.prefix(Int(maxUsersDisplayedLimit)))
} else {
effectiveExpanded = true
@ -548,7 +549,7 @@ private func groupStatsControllerEntries(state: GroupStatsState, data: GroupStat
var topAdmins = data.topAdmins
var effectiveExpanded = state.topAdminsExpanded
if topAdmins.count > maxUsersDisplayedLimit && !effectiveExpanded {
if topAdmins.count > maxUsersDisplayedHighLimit && !effectiveExpanded {
topAdmins = Array(topAdmins.prefix(Int(maxUsersDisplayedLimit)))
} else {
effectiveExpanded = true
@ -571,7 +572,7 @@ private func groupStatsControllerEntries(state: GroupStatsState, data: GroupStat
var topInviters = data.topInviters
var effectiveExpanded = state.topInvitersExpanded
if topInviters.count > maxUsersDisplayedLimit && !effectiveExpanded {
if topInviters.count > maxUsersDisplayedHighLimit && !effectiveExpanded {
topInviters = Array(topInviters.prefix(Int(maxUsersDisplayedLimit)))
} else {
effectiveExpanded = true

View File

@ -1019,6 +1019,11 @@ final class PeerInfoAvatarTransformContainerNode: ASDisplayNode {
if case .immediate = transition, fraction == 1.0 {
return
}
if fraction > 0.0 {
self.videoNode?.pause()
} else {
self.videoNode?.play()
}
transition.updateAlpha(node: videoNode, alpha: 1.0 - fraction)
}
}
@ -1199,8 +1204,7 @@ final class PeerInfoEditingAvatarNode: ASDisplayNode {
private var videoContent: NativeVideoContent?
private var videoStartTimestamp: Double?
var tapped: (() -> Void)?
var cancel: (() -> Void)?
var tapped: ((Bool) -> Void)?
var canAttachVideo = true
@ -1219,7 +1223,7 @@ final class PeerInfoEditingAvatarNode: ASDisplayNode {
@objc private func tapGesture(_ recognizer: UITapGestureRecognizer) {
if case .ended = recognizer.state {
self.tapped?()
self.tapped?(false)
}
}
@ -1931,7 +1935,7 @@ final class PeerInfoHeaderEditingContentNode: ASDisplayNode {
}
@objc private func textPressed() {
self.avatarNode.tapped?()
self.avatarNode.tapped?(true)
}
func editingTextForKey(_ key: PeerInfoHeaderTextFieldNodeKey) -> String? {
@ -2093,7 +2097,7 @@ final class PeerInfoHeaderNode: ASDisplayNode {
var performButtonAction: ((PeerInfoHeaderButtonKey) -> Void)?
var requestAvatarExpansion: ((Bool, [AvatarGalleryEntry], AvatarGalleryEntry?, (ASDisplayNode, CGRect, () -> (UIView?, UIView?))?) -> Void)?
var requestOpenAvatarForEditing: (() -> Void)?
var requestOpenAvatarForEditing: ((Bool) -> Void)?
var requestUpdateLayout: (() -> Void)?
var navigationTransition: PeerInfoHeaderNavigationTransition?
@ -2176,11 +2180,11 @@ final class PeerInfoHeaderNode: ASDisplayNode {
self.avatarListNode.avatarContainerNode.tapped = { [weak self] in
self?.initiateAvatarExpansion()
}
self.editingContentNode.avatarNode.tapped = { [weak self] in
self.editingContentNode.avatarNode.tapped = { [weak self] confirm in
guard let strongSelf = self else {
return
}
strongSelf.requestOpenAvatarForEditing?()
strongSelf.requestOpenAvatarForEditing?(confirm)
}
}

View File

@ -819,7 +819,7 @@ private func settingsEditingItems(data: PeerInfoScreenData?, state: PeerInfoStat
let ItemAddAccountHelp = 6
let ItemLogout = 7
items[.help]!.append(PeerInfoScreenCommentItem(id: ItemNameHelp, text: presentationData.strings.EditProfile_NameAndPhotoHelp))
items[.help]!.append(PeerInfoScreenCommentItem(id: ItemNameHelp, text: presentationData.strings.EditProfile_NameAndPhotoOrVideoHelp))
if let cachedData = data.cachedData as? CachedUserData {
items[.bio]!.append(PeerInfoScreenMultilineInputItem(id: ItemBio, text: state.updatingBio ?? (cachedData.about ?? ""), placeholder: presentationData.strings.UserInfo_About_Placeholder, textUpdated: { updatedText in
@ -2110,15 +2110,36 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}))
}
self.headerNode.requestOpenAvatarForEditing = { [weak self] in
self.headerNode.requestOpenAvatarForEditing = { [weak self] confirm in
guard let strongSelf = self else {
return
}
if strongSelf.state.updatingAvatar != nil {
strongSelf.updateAvatarDisposable.set(nil)
strongSelf.state = strongSelf.state.withUpdatingAvatar(nil)
if let (layout, navigationHeight) = strongSelf.validLayout {
strongSelf.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false)
let proceed = {
strongSelf.updateAvatarDisposable.set(nil)
strongSelf.state = strongSelf.state.withUpdatingAvatar(nil)
if let (layout, navigationHeight) = strongSelf.validLayout {
strongSelf.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false)
}
}
if confirm {
let controller = ActionSheetController(presentationData: strongSelf.presentationData)
let dismissAction: () -> Void = { [weak controller] in
controller?.dismissAnimated()
}
var items: [ActionSheetItem] = []
items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.Settings_CancelUpload, color: .destructive, action: { [weak self] in
dismissAction()
proceed()
}))
controller.setItemGroups([
ActionSheetItemGroup(items: items),
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, action: { dismissAction() })])
])
strongSelf.controller?.present(controller, in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
} else {
proceed()
}
} else {
strongSelf.openAvatarForEditing()
@ -2140,7 +2161,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}
switch key {
case .edit:
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(true, transition: .animated(duration: 0.2, curve: .easeInOut))
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(true, transition: .animated(duration: 0.3, curve: .linear))
strongSelf.state = strongSelf.state.withIsEditing(true)
var updateOnCompletion = false
if strongSelf.headerNode.isAvatarExpanded {
@ -2166,7 +2187,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
})
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))
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(false, transition: .animated(duration: 0.3, curve: .linear))
strongSelf.view.endEditing(true)
if case .done = key {
guard let data = strongSelf.data else {
@ -3880,13 +3901,13 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
if let item = item, case let .image(image) = item {
if index > 0 {
let title: String
let setMainTitle: String
if image.2.isEmpty {
title = self.presentationData.strings.ProfilePhoto_SetMainPhoto
setMainTitle = self.presentationData.strings.ProfilePhoto_SetMainPhoto
} else {
title = self.presentationData.strings.ProfilePhoto_SetMainVideo
setMainTitle = self.presentationData.strings.ProfilePhoto_SetMainVideo
}
items.append(ActionSheetButtonItem(title: title, color: .accent, action: { [weak self] in
items.append(ActionSheetButtonItem(title: setMainTitle, color: .accent, action: { [weak self] in
dismissAction()
self?.setMainAvatar(item)
}))
@ -3897,7 +3918,14 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
self?.editAvatarItem(item)
}))
items.append(ActionSheetButtonItem(title: self.presentationData.strings.GroupInfo_SetGroupPhotoDelete, color: .destructive, action: { [weak self] in
let deleteTitle: String
if image.2.isEmpty {
deleteTitle = self.presentationData.strings.GroupInfo_SetGroupPhotoDelete
} else {
deleteTitle = self.presentationData.strings.Settings_RemoveVideo
}
items.append(ActionSheetButtonItem(title: deleteTitle, color: .destructive, action: { [weak self] in
dismissAction()
self?.deleteAvatar(item)
}))