Various fixes

This commit is contained in:
Ilya Laktyushin 2022-11-12 12:51:07 +04:00
parent de5d52ea48
commit 1311ee7de6
4 changed files with 99 additions and 84 deletions

View File

@ -38,6 +38,7 @@ open class OverlayMediaItemNode: ASDisplayNode {
} }
open var customTransition: Bool = false open var customTransition: Bool = false
open var isRemoved: Bool = false
open func setShouldAcquireContext(_ value: Bool) { open func setShouldAcquireContext(_ value: Bool) {
} }

View File

@ -3276,90 +3276,94 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
self?.donePressed() self?.donePressed()
completion?() completion?()
}) })
} else if case .right = action, !peerIds.isEmpty { } else if case .right = action {
let actionSheet = ActionSheetController(presentationData: self.presentationData) if !threadIds.isEmpty {
var items: [ActionSheetItem] = []
items.append(ActionSheetButtonItem(title: self.presentationData.strings.ChatList_DeleteConfirmation(Int32(peerIds.count)), color: .destructive, action: { [weak self, weak actionSheet] in
actionSheet?.dismissAnimated()
guard let strongSelf = self else { } else if !peerIds.isEmpty {
return let actionSheet = ActionSheetController(presentationData: self.presentationData)
} var items: [ActionSheetItem] = []
items.append(ActionSheetButtonItem(title: self.presentationData.strings.ChatList_DeleteConfirmation(Int32(peerIds.count)), color: .destructive, action: { [weak self, weak actionSheet] in
strongSelf.chatListDisplayNode.containerNode.updateState(onlyCurrent: false, { state in actionSheet?.dismissAnimated()
var state = state
for peerId in peerIds {
state.pendingRemovalItemIds.insert(ChatListNodeState.ItemId(peerId: peerId, threadId: nil))
}
return state
})
let text = strongSelf.presentationData.strings.ChatList_DeletedChats(Int32(peerIds.count))
strongSelf.present(UndoOverlayController(presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, content: .removedChat(text: text), elevatedLayout: false, animateInAsReplacement: true, action: { value in
guard let strongSelf = self else { guard let strongSelf = self else {
return false return
} }
if value == .commit {
let presentationData = strongSelf.presentationData strongSelf.chatListDisplayNode.containerNode.updateState(onlyCurrent: false, { state in
let progressSignal = Signal<Never, NoError> { subscriber in var state = state
let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) for peerId in peerIds {
self?.present(controller, in: .window(.root)) state.pendingRemovalItemIds.insert(ChatListNodeState.ItemId(peerId: peerId, threadId: nil))
return ActionDisposable { [weak controller] in }
Queue.mainQueue().async() { return state
controller?.dismiss() })
let text = strongSelf.presentationData.strings.ChatList_DeletedChats(Int32(peerIds.count))
strongSelf.present(UndoOverlayController(presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, content: .removedChat(text: text), elevatedLayout: false, animateInAsReplacement: true, action: { value in
guard let strongSelf = self else {
return false
}
if value == .commit {
let presentationData = strongSelf.presentationData
let progressSignal = Signal<Never, NoError> { subscriber in
let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil))
self?.present(controller, in: .window(.root))
return ActionDisposable { [weak controller] in
Queue.mainQueue().async() {
controller?.dismiss()
}
} }
} }
|> runOn(Queue.mainQueue())
|> delay(0.8, queue: Queue.mainQueue())
let progressDisposable = progressSignal.start()
let signal: Signal<Never, NoError> = strongSelf.context.engine.peers.removePeerChats(peerIds: Array(peerIds))
|> afterDisposed {
Queue.mainQueue().async {
progressDisposable.dispose()
}
}
let _ = (signal
|> deliverOnMainQueue).start()
strongSelf.chatListDisplayNode.containerNode.updateState(onlyCurrent: false, { state in
var state = state
for peerId in peerIds {
state.selectedPeerIds.remove(peerId)
}
return state
})
return true
} else if value == .undo {
strongSelf.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingItemId(ChatListNodeState.ItemId(peerId: peerIds.first!, threadId: nil))
strongSelf.chatListDisplayNode.containerNode.updateState(onlyCurrent: false, { state in
var state = state
for peerId in peerIds {
state.pendingRemovalItemIds.remove(ChatListNodeState.ItemId(peerId: peerId, threadId: nil))
}
return state
})
self?.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingItemId(ChatListNodeState.ItemId(peerId: peerIds.first!, threadId: nil))
return true
} }
|> runOn(Queue.mainQueue()) return false
|> delay(0.8, queue: Queue.mainQueue()) }), in: .current)
let progressDisposable = progressSignal.start()
strongSelf.donePressed()
let signal: Signal<Never, NoError> = strongSelf.context.engine.peers.removePeerChats(peerIds: Array(peerIds)) }))
|> afterDisposed {
Queue.mainQueue().async {
progressDisposable.dispose()
}
}
let _ = (signal
|> deliverOnMainQueue).start()
strongSelf.chatListDisplayNode.containerNode.updateState(onlyCurrent: false, { state in
var state = state
for peerId in peerIds {
state.selectedPeerIds.remove(peerId)
}
return state
})
return true
} else if value == .undo {
strongSelf.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingItemId(ChatListNodeState.ItemId(peerId: peerIds.first!, threadId: nil))
strongSelf.chatListDisplayNode.containerNode.updateState(onlyCurrent: false, { state in
var state = state
for peerId in peerIds {
state.pendingRemovalItemIds.remove(ChatListNodeState.ItemId(peerId: peerId, threadId: nil))
}
return state
})
self?.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingItemId(ChatListNodeState.ItemId(peerId: peerIds.first!, threadId: nil))
return true
}
return false
}), in: .current)
strongSelf.donePressed() actionSheet.setItemGroups([
})) ActionSheetItemGroup(items: items),
ActionSheetItemGroup(items: [
actionSheet.setItemGroups([ ActionSheetButtonItem(title: self.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in
ActionSheetItemGroup(items: items), actionSheet?.dismissAnimated()
ActionSheetItemGroup(items: [ })
ActionSheetButtonItem(title: self.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in ])
actionSheet?.dismissAnimated()
})
]) ])
]) self.present(actionSheet, in: .window(.root))
self.present(actionSheet, in: .window(.root)) }
} else if case .middle = action { } else if case .middle = action {
switch self.location { switch self.location {
case let .chatList(groupId): case let .chatList(groupId):

View File

@ -145,8 +145,11 @@ final class AppIconsDemoComponent: Component {
from = CGPoint(x: availableSize.width * 0.5, y: availableSize.height * 0.5) from = CGPoint(x: availableSize.width * 0.5, y: availableSize.height * 0.5)
delay = 0.0 delay = 0.0
} }
view.layer.animateScale(from: 3.0, to: 1.0, duration: 0.5, delay: delay, timingFunction: kCAMediaTimingFunctionSpring)
view.layer.animatePosition(from: from, to: CGPoint(), duration: 0.5, delay: delay, timingFunction: kCAMediaTimingFunctionSpring, additive: true) Queue.mainQueue().after(delay) {
view.layer.animateScale(from: 3.0, to: 1.0, duration: 0.5, delay: 0.0, timingFunction: kCAMediaTimingFunctionSpring)
view.layer.animatePosition(from: from, to: CGPoint(), duration: 0.5, delay: 0.0, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
}
i += 1 i += 1
} }

View File

@ -293,10 +293,12 @@ final class OverlayMediaControllerNode: ASDisplayNode, UIGestureRecognizerDelega
if customTransition { if customTransition {
node.removeFromSupernode() node.removeFromSupernode()
} else { } else {
let nodeSize = self.videoNodes[index].currentSize if !node.isRemoved {
node.layer.animateFrame(from: node.layer.frame, to: CGRect(origin: self.nodePosition(layout: validLayout, size: nodeSize, location: self.videoNodes[index].location, hidden: true, isMinimized: self.videoNodes[index].isMinimized, tempExtendedTopInset: node.tempExtendedTopInset), size: nodeSize), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { [weak node] _ in let nodeSize = self.videoNodes[index].currentSize
node?.removeFromSupernode() node.layer.animateFrame(from: node.layer.frame, to: CGRect(origin: self.nodePosition(layout: validLayout, size: nodeSize, location: self.videoNodes[index].location, hidden: true, isMinimized: self.videoNodes[index].isMinimized, tempExtendedTopInset: node.tempExtendedTopInset), size: nodeSize), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { [weak node] _ in
}) node?.removeFromSupernode()
})
}
} }
} else { } else {
node.removeFromSupernode() node.removeFromSupernode()
@ -368,11 +370,16 @@ final class OverlayMediaControllerNode: ASDisplayNode, UIGestureRecognizerDelega
} }
self.videoNodes[index].location = updatedLocation self.videoNodes[index].location = updatedLocation
draggingNode.frame = CGRect(origin: self.nodePosition(layout: validLayout, size: nodeSize, location: updatedLocation, hidden: !draggingNode.hasAttachedContext, isMinimized: self.videoNodes[index].isMinimized, tempExtendedTopInset: draggingNode.tempExtendedTopInset), size: nodeSize) draggingNode.frame = CGRect(origin: self.nodePosition(layout: validLayout, size: nodeSize, location: updatedLocation, hidden: !draggingNode.hasAttachedContext || shouldDismiss, isMinimized: self.videoNodes[index].isMinimized, tempExtendedTopInset: draggingNode.tempExtendedTopInset), size: nodeSize)
draggingNode.layer.animateFrame(from: previousFrame, to: draggingNode.frame, duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring) draggingNode.layer.animateFrame(from: previousFrame, to: draggingNode.frame, duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, completion: { [weak draggingNode] _ in
if draggingNode?.isRemoved == true {
draggingNode?.removeFromSupernode()
}
})
self.draggingNode = nil self.draggingNode = nil
if shouldDismiss && !draggingNode.isMinimizeable { if shouldDismiss && !draggingNode.isMinimizeable {
draggingNode.isRemoved = true
draggingNode.dismiss() draggingNode.dismiss()
} }
} }