Merge branch 'master' of gitlab.com:peter-iakovlev/TelegramUI

This commit is contained in:
Ilya Laktyushin 2019-04-29 19:57:15 +04:00
commit b023f900b5
4 changed files with 84 additions and 45 deletions

View File

@ -424,8 +424,16 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
state.peerIdWithRevealedOptions = nil
return state
}
var hadCurrent = false
strongSelf.window?.forEachController({ controller in
if let controller = controller as? UndoOverlayController {
hadCurrent = true
controller.dismissWithReplacementAnimation()
}
})
if value {
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .hidArchive(title: strongSelf.presentationData.strings.ChatList_UndoArchiveHiddenTitle, text: strongSelf.presentationData.strings.ChatList_UndoArchiveHiddenText, undo: true), elevatedLayout: strongSelf.groupId == .root, action: { [weak self] shouldCommit in
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .hidArchive(title: strongSelf.presentationData.strings.ChatList_UndoArchiveHiddenTitle, text: strongSelf.presentationData.strings.ChatList_UndoArchiveHiddenText, undo: true), elevatedLayout: strongSelf.groupId == .root, animateInAsReplacement: hadCurrent, action: { [weak self] shouldCommit in
guard let strongSelf = self else {
return
}
@ -443,7 +451,7 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
}
}), in: .window(.root))
} else {
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .hidArchive(title: strongSelf.presentationData.strings.ChatList_UndoArchiveRevealedTitle, text: strongSelf.presentationData.strings.ChatList_UndoArchiveRevealedText, undo: false), elevatedLayout: strongSelf.groupId == .root, action: { _ in
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .hidArchive(title: strongSelf.presentationData.strings.ChatList_UndoArchiveRevealedTitle, text: strongSelf.presentationData.strings.ChatList_UndoArchiveRevealedText, undo: false), elevatedLayout: strongSelf.groupId == .root, animateInAsReplacement: hadCurrent, action: { _ in
}), in: .window(.root))
}
})
@ -533,7 +541,16 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
state.pendingClearHistoryPeerIds.insert(peer.peerId)
return state
})
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .removedChat(text: strongSelf.presentationData.strings.Undo_ChatCleared), elevatedLayout: strongSelf.groupId == .root, action: { shouldCommit in
var hadCurrent = false
strongSelf.window?.forEachController({ controller in
if let controller = controller as? UndoOverlayController {
hadCurrent = true
controller.dismissWithReplacementAnimation()
}
})
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .removedChat(text: strongSelf.presentationData.strings.Undo_ChatCleared), elevatedLayout: strongSelf.groupId == .root, animateInAsReplacement: hadCurrent, action: { shouldCommit in
guard let strongSelf = self else {
return
}
@ -1455,17 +1472,14 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
}
}
var foundExisting = false
var hadCurrent = false
strongSelf.window?.forEachController({ controller in
if let controller = controller as? UndoOverlayController {
if case .archivedChat = controller.content {
foundExisting = true
controller.renewWithCurrentContent(action: action)
}
hadCurrent = true
controller.dismissWithReplacementAnimation()
}
})
if !foundExisting {
let title: String
let text: String
let undo: Bool
@ -1491,8 +1505,7 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
text = strongSelf.presentationData.strings.ChatList_UndoArchiveTitle
undo = true
}
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .archivedChat(title: title, text: text, undo: undo), elevatedLayout: strongSelf.groupId == .root, action: action), in: .window(.root))
}
strongSelf.present(UndoOverlayController(context: strongSelf.context, content: .archivedChat(title: title, text: text, undo: undo), elevatedLayout: strongSelf.groupId == .root, animateInAsReplacement: hadCurrent, action: action), in: .window(.root))
strongSelf.chatListDisplayNode.playArchiveAnimation()
})
@ -1547,7 +1560,16 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
statusText = self.presentationData.strings.Undo_ChatDeleted
}
}
self.present(UndoOverlayController(context: self.context, content: .removedChat(text: statusText), elevatedLayout: self.groupId == .root, action: { [weak self] shouldCommit in
var hadCurrent = false
self.window?.forEachController({ controller in
if let controller = controller as? UndoOverlayController {
hadCurrent = true
controller.dismissWithReplacementAnimation()
}
})
self.present(UndoOverlayController(context: self.context, content: .removedChat(text: statusText), elevatedLayout: self.groupId == .root, animateInAsReplacement: hadCurrent, action: { [weak self] shouldCommit in
guard let strongSelf = self else {
return
}

View File

@ -95,7 +95,7 @@ func preparedChatListNodeViewTransition(from fromView: ChatListNodeView?, to toV
}
}
if let minTimestamp = minTimestamp, let maxTimestamp = maxTimestamp, abs(maxTimestamp - minTimestamp) > 60 * 60 {
if false, let minTimestamp = minTimestamp, let maxTimestamp = maxTimestamp, abs(maxTimestamp - minTimestamp) > 60 * 60 {
let _ = options.insert(.AnimateCrossfade)
} else {
let _ = options.insert(.AnimateAlpha)

View File

@ -13,15 +13,17 @@ final class UndoOverlayController: ViewController {
private let presentationData: PresentationData
let content: UndoOverlayContent
private let elevatedLayout: Bool
private let animateInAsReplacement: Bool
private var action: (Bool) -> Void
private var didPlayPresentationAnimation = false
init(context: AccountContext, content: UndoOverlayContent, elevatedLayout: Bool, action: @escaping (Bool) -> Void) {
init(context: AccountContext, content: UndoOverlayContent, elevatedLayout: Bool, animateInAsReplacement: Bool = false, action: @escaping (Bool) -> Void) {
self.context = context
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
self.content = content
self.elevatedLayout = elevatedLayout
self.animateInAsReplacement = animateInAsReplacement
self.action = action
super.init(navigationBarPresentationData: nil)
@ -47,9 +49,10 @@ final class UndoOverlayController: ViewController {
self.dismiss()
}
func renewWithCurrentContent(action: @escaping (Bool) -> Void) {
self.action = action
(self.displayNode as! UndoOverlayControllerNode).renewWithCurrentContent()
func dismissWithReplacementAnimation() {
(self.displayNode as! UndoOverlayControllerNode).animateOutWithReplacement(completion: { [weak self] in
self?.presentingViewController?.dismiss(animated: false, completion: nil)
})
}
override func viewDidAppear(_ animated: Bool) {
@ -57,7 +60,7 @@ final class UndoOverlayController: ViewController {
if !self.didPlayPresentationAnimation {
self.didPlayPresentationAnimation = true
(self.displayNode as! UndoOverlayControllerNode).animateIn()
(self.displayNode as! UndoOverlayControllerNode).animateIn(asReplacement: self.animateInAsReplacement)
}
}

View File

@ -266,9 +266,15 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode {
}
}
func animateIn() {
func animateIn(asReplacement: Bool) {
if asReplacement {
let offset = self.bounds.width
self.panelWrapperNode.layer.animatePosition(from: CGPoint(x: offset, y: 0.0), to: CGPoint(), duration: 0.35, delay: 0.0, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: nil)
self.panelNode.layer.animatePosition(from: CGPoint(x: offset, y: 0.0), to: CGPoint(), duration: 0.35, delay: 0.0, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: nil)
} else {
self.panelNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3)
self.panelWrapperNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3)
}
if let iconCheckNode = self.iconCheckNode, self.iconNode != nil {
Queue.mainQueue().after(0.2, { [weak iconCheckNode] in
@ -292,6 +298,14 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode {
}
}
func animateOutWithReplacement(completion: @escaping () -> Void) {
let offset = -self.bounds.width
self.panelWrapperNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: offset, y: 0.0), duration: 0.35, delay: 0.0, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: { _ in
completion()
})
self.panelNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: offset, y: 0.0), duration: 0.35, delay: 0.0, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: nil)
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if !self.panelNode.frame.insetBy(dx: -60.0, dy: 0.0).contains(point) {
return nil