diff --git a/submodules/ContextUI/Sources/ContextActionNode.swift b/submodules/ContextUI/Sources/ContextActionNode.swift index 46ca6f16b0..470101545a 100644 --- a/submodules/ContextUI/Sources/ContextActionNode.swift +++ b/submodules/ContextUI/Sources/ContextActionNode.swift @@ -149,6 +149,29 @@ final class ContextActionNode: ASDisplayNode { } } + func updateTheme(theme: PresentationTheme) { + self.backgroundNode.backgroundColor = theme.contextMenu.itemBackgroundColor + self.highlightedBackgroundNode.backgroundColor = theme.contextMenu.itemHighlightedBackgroundColor + + let textColor: UIColor + switch action.textColor { + case .primary: + textColor = theme.contextMenu.primaryColor + case .destructive: + textColor = theme.contextMenu.destructiveColor + } + self.textNode.attributedText = NSAttributedString(string: self.action.text, font: textFont, textColor: textColor) + + switch self.action.textLayout { + case let .secondLineWithValue(value): + self.statusNode?.attributedText = NSAttributedString(string: value, font: textFont, textColor: theme.contextMenu.secondaryColor) + default: + break + } + + self.iconNode.image = self.action.icon(theme) + } + @objc private func buttonPressed() { self.performAction() } diff --git a/submodules/ContextUI/Sources/ContextActionsContainerNode.swift b/submodules/ContextUI/Sources/ContextActionsContainerNode.swift index 81802db9f0..4aecca23d1 100644 --- a/submodules/ContextUI/Sources/ContextActionsContainerNode.swift +++ b/submodules/ContextUI/Sources/ContextActionsContainerNode.swift @@ -114,6 +114,21 @@ final class ContextActionsContainerNode: ASDisplayNode { return CGSize(width: maxWidth, height: verticalOffset) } + func updateTheme(theme: PresentationTheme) { + for itemNode in self.itemNodes { + switch itemNode { + case let .action(action): + action.updateTheme(theme: theme) + case let .separator(separator): + separator.backgroundColor = theme.contextMenu.sectionSeparatorColor + case let .itemSeparator(itemSeparator): + itemSeparator.backgroundColor = theme.contextMenu.itemSeparatorColor + } + } + + self.backgroundColor = theme.contextMenu.backgroundColor + } + func actionNode(at point: CGPoint) -> ContextActionNode? { for itemNode in self.itemNodes { switch itemNode { diff --git a/submodules/ContextUI/Sources/ContextController.swift b/submodules/ContextUI/Sources/ContextController.swift index 8caa10449c..ce1ba04b65 100644 --- a/submodules/ContextUI/Sources/ContextController.swift +++ b/submodules/ContextUI/Sources/ContextController.swift @@ -47,6 +47,16 @@ public enum ContextMenuItem { case separator } +private func convertFrame(_ frame: CGRect, from fromView: UIView, to toView: UIView) -> CGRect { + let sourceWindowFrame = fromView.convert(frame, to: nil) + var targetWindowFrame = toView.convert(sourceWindowFrame, from: nil) + + if let fromWindow = fromView.window, let toWindow = toView.window { + targetWindowFrame.origin.x += toWindow.bounds.width - fromWindow.bounds.width + } + return targetWindowFrame +} + private final class ContextControllerNode: ViewControllerTracingNode, UIScrollViewDelegate { private var theme: PresentationTheme private var strings: PresentationStrings @@ -61,6 +71,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi private var propertyAnimator: AnyObject? private var displayLinkAnimator: DisplayLinkAnimator? private let dimNode: ASDisplayNode + private let dismissNode: ASDisplayNode private let clippingNode: ASDisplayNode private let scrollNode: ASScrollNode @@ -106,6 +117,8 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi self.dimNode.backgroundColor = theme.contextMenu.dimColor self.dimNode.alpha = 0.0 + self.dismissNode = ASDisplayNode() + self.clippingNode = ASDisplayNode() self.clippingNode.clipsToBounds = true @@ -143,6 +156,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi self.addSubnode(self.clippingNode) self.clippingNode.addSubnode(self.scrollNode) + self.scrollNode.addSubnode(self.dismissNode) self.scrollNode.addSubnode(self.actionsContainerNode) self.scrollNode.addSubnode(self.contentContainerNode) @@ -261,7 +275,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi override func didLoad() { super.didLoad() - self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimNodeTapped))) + self.dismissNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimNodeTapped))) } @objc private func dimNodeTapped() { @@ -283,7 +297,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi if strongSelf.isAnimatingOut { return } - strongSelf.originalProjectedContentViewFrame = (parentSupernode.view.convert(contentParentNode.frame, to: strongSelf.view), contentParentNode.view.convert(contentParentNode.contentRect, to: strongSelf.view)) + strongSelf.originalProjectedContentViewFrame = (convertFrame(contentParentNode.frame, from: parentSupernode.view, to: strongSelf.view), convertFrame(contentParentNode.contentRect, from: contentParentNode.view, to: strongSelf.view)) if let validLayout = strongSelf.validLayout { strongSelf.updateLayout(layout: validLayout, transition: .animated(duration: 0.2 * animationDurationFactor, curve: .easeInOut), previousActionsContainerNode: nil) } @@ -309,15 +323,20 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } } self.contentContainerNode.contentNode = takenViewInfo.contentContainingNode.contentNode + self.contentAreaInScreenSpace = takenViewInfo.contentAreaInScreenSpace self.contentContainerNode.addSubnode(takenViewInfo.contentContainingNode.contentNode) takenViewInfo.contentContainingNode.isExtractedToContextPreview = true takenViewInfo.contentContainingNode.isExtractedToContextPreviewUpdated?(true) - self.originalProjectedContentViewFrame = (parentSupernode.view.convert(takenViewInfo.contentContainingNode.frame, to: self.view), takenViewInfo.contentContainingNode.view.convert(takenViewInfo.contentContainingNode.contentRect, to: self.view)) + self.originalProjectedContentViewFrame = (convertFrame(takenViewInfo.contentContainingNode.frame, from: parentSupernode.view, to: self.view), convertFrame(takenViewInfo.contentContainingNode.contentRect, from: takenViewInfo.contentContainingNode.view, to: self.view)) - self.clippingNode.layer.animateFrame(from: takenViewInfo.contentAreaInScreenSpace, to: self.clippingNode.frame, duration: 0.18 * animationDurationFactor, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue) - self.clippingNode.layer.animateBoundsOriginYAdditive(from: takenViewInfo.contentAreaInScreenSpace.minY, to: 0.0, duration: 0.18 * animationDurationFactor, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue) + var updatedContentAreaInScreenSpace = takenViewInfo.contentAreaInScreenSpace + updatedContentAreaInScreenSpace.origin.x = 0.0 + updatedContentAreaInScreenSpace.size.width = self.bounds.width + + self.clippingNode.layer.animateFrame(from: updatedContentAreaInScreenSpace, to: self.clippingNode.frame, duration: 0.18 * animationDurationFactor, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue) + self.clippingNode.layer.animateBoundsOriginYAdditive(from: updatedContentAreaInScreenSpace.minY, to: 0.0, duration: 0.18 * animationDurationFactor, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue) } if let validLayout = self.validLayout { @@ -366,16 +385,23 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } self.actionsContainerNode.layer.animateSpring(from: NSValue(cgPoint: CGPoint(x: localSourceFrame.center.x - self.actionsContainerNode.position.x, y: localSourceFrame.center.y - self.actionsContainerNode.position.y)), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true) - let contentContainerOffset = CGPoint(x: localSourceFrame.center.x - self.contentContainerNode.frame.center.x - contentParentNode.contentRect.minX, y: localSourceFrame.center.y - self.contentContainerNode.frame.center.y - contentParentNode.contentRect.minY) + let contentContainerOffset = CGPoint(x: localSourceFrame.center.x - self.contentContainerNode.frame.center.x - contentParentNode.contentRect.minX, y: localSourceFrame.center.y - self.contentContainerNode.frame.center.y) self.contentContainerNode.layer.animateSpring(from: NSValue(cgPoint: contentContainerOffset), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true) contentParentNode.applyAbsoluteOffsetSpring?(-contentContainerOffset.y, springDuration, springDamping) } } - func animateOut(result: ContextMenuActionResult, completion: @escaping () -> Void) { + func animateOut(result initialResult: ContextMenuActionResult, completion: @escaping () -> Void) { var transitionDuration: Double = 0.2 var transitionCurve: ContainedViewLayoutTransitionCurve = .easeInOut + var result = initialResult + let putBackInfo = self.source.putBack() + + if putBackInfo == nil { + result = .dismissWithoutContent + } + switch result { case let .custom(value): switch value { @@ -398,13 +424,15 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi var completedContentNode = false var completedActionsNode = false - let putBackInfo = self.source.putBack() - if let putBackInfo = putBackInfo, let contentParentNode = self.contentParentNode, let parentSupernode = contentParentNode.supernode { - self.originalProjectedContentViewFrame = (parentSupernode.view.convert(contentParentNode.frame, to: self.view), contentParentNode.view.convert(contentParentNode.contentRect, to: self.view)) + self.originalProjectedContentViewFrame = (convertFrame(contentParentNode.frame, from: parentSupernode.view, to: self.view), convertFrame(contentParentNode.contentRect, from: contentParentNode.view, to: self.view)) - self.clippingNode.layer.animateFrame(from: self.clippingNode.frame, to: putBackInfo.contentAreaInScreenSpace, duration: transitionDuration * animationDurationFactor, timingFunction: transitionCurve.timingFunction, removeOnCompletion: false) - self.clippingNode.layer.animateBoundsOriginYAdditive(from: 0.0, to: putBackInfo.contentAreaInScreenSpace.minY, duration: transitionDuration * animationDurationFactor, timingFunction: transitionCurve.timingFunction, removeOnCompletion: false) + var updatedContentAreaInScreenSpace = putBackInfo.contentAreaInScreenSpace + updatedContentAreaInScreenSpace.origin.x = 0.0 + updatedContentAreaInScreenSpace.size.width = self.bounds.width + + self.clippingNode.layer.animateFrame(from: self.clippingNode.frame, to: updatedContentAreaInScreenSpace, duration: transitionDuration * animationDurationFactor, timingFunction: transitionCurve.timingFunction, removeOnCompletion: false) + self.clippingNode.layer.animateBoundsOriginYAdditive(from: 0.0, to: updatedContentAreaInScreenSpace.minY, duration: transitionDuration * animationDurationFactor, timingFunction: transitionCurve.timingFunction, removeOnCompletion: false) } let contentParentNode = self.contentParentNode @@ -466,7 +494,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi completedActionsNode = true intermediateCompletion() }) - self.actionsContainerNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2 * animationDurationFactor, removeOnCompletion: false) + self.actionsContainerNode.layer.animateScale(from: 1.0, to: 0.1, duration: transitionDuration * animationDurationFactor, timingFunction: transitionCurve.timingFunction, removeOnCompletion: false) let animateOutToItem: Bool switch result { @@ -564,6 +592,17 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } } + func updateTheme(theme: PresentationTheme) { + self.theme = theme + + self.dimNode.backgroundColor = theme.contextMenu.dimColor + self.actionsContainerNode.updateTheme(theme: theme) + + if let validLayout = self.validLayout { + self.updateLayout(layout: validLayout, transition: .immediate, previousActionsContainerNode: nil) + } + } + func updateLayout(layout: ContainerViewLayout, transition: ContainedViewLayoutTransition, previousActionsContainerNode: ContextActionsContainerNode?) { if self.isAnimatingOut { return @@ -657,6 +696,8 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi previousActionsContainerNode.removeFromSupernode() } } + + transition.updateFrame(node: self.dismissNode, frame: CGRect(origin: CGPoint(), size: scrollNode.view.contentSize)) } func scrollViewDidScroll(_ scrollView: UIScrollView) { @@ -690,7 +731,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } } - return self.dimNode.view + return self.dismissNode.view } } @@ -792,6 +833,13 @@ public final class ContextController: ViewController { } } + public func updateTheme(theme: PresentationTheme) { + self.theme = theme + if self.isNodeLoaded { + self.controllerNode.updateTheme(theme: theme) + } + } + private func dismiss(result: ContextMenuActionResult, completion: (() -> Void)?) { if !self.wasDismissed { self.wasDismissed = true diff --git a/submodules/Display/Display/GlobalOverlayPresentationContext.swift b/submodules/Display/Display/GlobalOverlayPresentationContext.swift index 1963e625f7..4794e0b8a8 100644 --- a/submodules/Display/Display/GlobalOverlayPresentationContext.swift +++ b/submodules/Display/Display/GlobalOverlayPresentationContext.swift @@ -23,6 +23,30 @@ private func isViewVisibleInHierarchy(_ view: UIView, _ initial: Bool = true) -> } } +private final class HierarchyTrackingNode: ASDisplayNode { + private let f: (Bool) -> Void + + init(_ f: @escaping (Bool) -> Void) { + self.f = f + + super.init() + + self.isLayerBacked = true + } + + override func didEnterHierarchy() { + super.didEnterHierarchy() + + self.f(true) + } + + override func didExitHierarchy() { + super.didExitHierarchy() + + self.f(false) + } +} + final class GlobalOverlayPresentationContext { private let statusBarHost: StatusBarHost? private weak var parentView: UIView? @@ -41,9 +65,34 @@ final class GlobalOverlayPresentationContext { self.parentView = parentView } + private var currentTrackingNode: HierarchyTrackingNode? + private func currentPresentationView(underStatusBar: Bool) -> UIView? { if let statusBarHost = self.statusBarHost { if let keyboardWindow = statusBarHost.keyboardWindow, let keyboardView = statusBarHost.keyboardView, !keyboardView.frame.height.isZero, isViewVisibleInHierarchy(keyboardView) { + var updateTrackingNode = false + if let trackingNode = self.currentTrackingNode { + if trackingNode.layer.superlayer !== keyboardView.layer { + updateTrackingNode = true + } + } else { + updateTrackingNode = true + } + + if updateTrackingNode { + self.currentTrackingNode?.removeFromSupernode() + let trackingNode = HierarchyTrackingNode({ [weak self] value in + guard let strongSelf = self else { + return + } + if !value { + strongSelf.addViews(justMove: true) + } + }) + + self.currentTrackingNode = trackingNode + keyboardView.layer.addSublayer(trackingNode.layer) + } return keyboardWindow } else { if underStatusBar, let view = self.parentView { @@ -69,8 +118,8 @@ final class GlobalOverlayPresentationContext { underStatusBar = true } } - if let _ = self.currentPresentationView(underStatusBar: underStatusBar), let initialLayout = self.layout { - controller.view.frame = CGRect(origin: CGPoint(), size: initialLayout.size) + if let presentationView = self.currentPresentationView(underStatusBar: underStatusBar), let initialLayout = self.layout { + controller.view.frame = CGRect(origin: CGPoint(x: presentationView.bounds.width - initialLayout.size.width, y: 0.0), size: initialLayout.size) controller.containerLayoutUpdated(initialLayout, transition: .immediate) self.presentationDisposables.add(controllerReady.start(next: { [weak self] _ in @@ -88,7 +137,7 @@ final class GlobalOverlayPresentationContext { }, rootController: nil) (controller as? UIViewController)?.setIgnoreAppearanceMethodInvocations(true) if layout != initialLayout { - controller.view.frame = CGRect(origin: CGPoint(), size: layout.size) + controller.view.frame = CGRect(origin: CGPoint(x: view.bounds.width - layout.size.width, y: 0.0), size: layout.size) view.addSubview(controller.view) controller.containerLayoutUpdated(layout, transition: .immediate) } else { @@ -134,13 +183,13 @@ final class GlobalOverlayPresentationContext { private func readyChanged(wasReady: Bool) { if !wasReady { - self.addViews() + self.addViews(justMove: false) } else { self.removeViews() } } - private func addViews() { + private func addViews(justMove: Bool) { if let layout = self.layout { for controller in self.controllers { var underStatusBar = false @@ -150,11 +199,15 @@ final class GlobalOverlayPresentationContext { } } if let view = self.currentPresentationView(underStatusBar: underStatusBar) { - controller.viewWillAppear(false) + if !justMove { + controller.viewWillAppear(false) + } view.addSubview(controller.view) - controller.view.frame = CGRect(origin: CGPoint(), size: layout.size) - controller.containerLayoutUpdated(layout, transition: .immediate) - controller.viewDidAppear(false) + if !justMove { + controller.view.frame = CGRect(origin: CGPoint(x: view.bounds.width - layout.size.width, y: 0.0), size: layout.size) + controller.containerLayoutUpdated(layout, transition: .immediate) + controller.viewDidAppear(false) + } } } } diff --git a/submodules/Display/Display/WindowContent.swift b/submodules/Display/Display/WindowContent.swift index 181fd6f4ca..25daaa5769 100644 --- a/submodules/Display/Display/WindowContent.swift +++ b/submodules/Display/Display/WindowContent.swift @@ -1054,6 +1054,14 @@ public class Window1 { } } + public func simulateKeyboardDismiss(transition: ContainedViewLayoutTransition) { + if self.windowLayout.inputHeight != nil { + self.updateLayout { + $0.update(upperKeyboardInputPositionBound: self.windowLayout.size.height, transition: transition, overrideTransition: false) + } + } + } + private func panGestureEnded(location: CGPoint, velocity: CGPoint?) { if self.keyboardGestureBeginLocation == nil { return diff --git a/submodules/TelegramCore/TelegramCore/Log.swift b/submodules/TelegramCore/TelegramCore/Log.swift index 97db36e7c1..7d9cf8a649 100644 --- a/submodules/TelegramCore/TelegramCore/Log.swift +++ b/submodules/TelegramCore/TelegramCore/Log.swift @@ -2,9 +2,11 @@ import Foundation #if os(macOS) import SwiftSignalKitMac import PostboxMac + import TelegramApiMac #else import SwiftSignalKit import Postbox + import TelegramApi #endif private let queue = DispatchQueue(label: "org.telegram.Telegram.trace", qos: .utility) @@ -64,6 +66,9 @@ public func registerLoggingFunctions() { } } }) + setTelegramApiLogger({ what in + Logger.shared.shortLog("Api", what as String) + }) } private var sharedLogger: Logger? diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift index a04952e884..5af2e366cc 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift @@ -173,7 +173,7 @@ public final class PrincipalThemeEssentialGraphics { } var outgoingGradientColors: (UIColor, UIColor)? - if let baseColor = presentationTheme.baseColor { + if false, let baseColor = presentationTheme.baseColor { if presentationTheme.baseColor == .custom { } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index c786c8214d..419822ed41 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -2315,6 +2315,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G state = state.updatedChatWallpaper(self.presentationData.chatWallpaper) return state }) + + self.currentContextController?.updateTheme(theme: self.presentationData.theme) } override public func loadDisplayNode() { diff --git a/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift index a37570e606..f03d95b54e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift @@ -568,8 +568,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { var immediatelyLayoutInputNodeAndAnimateAppearance = false var inputNodeHeightAndOverflow: (CGFloat, CGFloat)? if let inputNode = inputNodeForChatPresentationIntefaceState(self.chatPresentationInterfaceState, context: self.context, currentNode: self.inputNode, interfaceInteraction: self.interfaceInteraction, inputMediaNode: self.inputMediaNode, controllerInteraction: self.controllerInteraction, inputPanelNode: self.inputPanelNode) { - if let inputTextPanelNode = self.inputPanelNode as? ChatTextInputPanelNode { - inputTextPanelNode.ensureUnfocused() + if let _ = self.inputPanelNode as? ChatTextInputPanelNode { + self.context.sharedContext.mainWindow?.simulateKeyboardDismiss(transition: .animated(duration: 0.5, curve: .spring)) + //inputTextPanelNode.ensureUnfocused() } if let inputMediaNode = inputNode as? ChatMediaInputNode, self.inputMediaNode == nil { self.inputMediaNode = inputMediaNode @@ -645,7 +646,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { if let inputPanelNode = inputPanelForChatPresentationIntefaceState(self.chatPresentationInterfaceState, context: self.context, currentPanel: self.inputPanelNode, textInputPanelNode: self.textInputPanelNode, interfaceInteraction: self.interfaceInteraction), !previewing { if inputPanelNode !== self.inputPanelNode { if let inputTextPanelNode = self.inputPanelNode as? ChatTextInputPanelNode { - inputTextPanelNode.ensureUnfocused() + self.context.sharedContext.mainWindow?.simulateKeyboardDismiss(transition: .animated(duration: 0.5, curve: .spring)) + //inputTextPanelNode.ensureUnfocused() let _ = inputTextPanelNode.updateLayout(width: layout.size.width, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right, maxHeight: layout.size.height - insets.top - insets.bottom, transition: transition, interfaceState: self.chatPresentationInterfaceState, metrics: layout.metrics) } dismissedInputPanelNode = self.inputPanelNode @@ -1280,6 +1282,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { } self.derivedLayoutState = ChatControllerNodeDerivedLayoutState(inputContextPanelsFrame: inputContextPanelsFrame, inputContextPanelsOverMainPanelFrame: inputContextPanelsOverMainPanelFrame, inputNodeHeight: inputNodeHeightAndOverflow?.0, upperInputPositionBound: inputNodeHeightAndOverflow?.0 != nil ? self.upperInputPositionBound : nil) + + //self.notifyTransitionCompletionListeners(transition: transition) } private func notifyTransitionCompletionListeners(transition: ContainedViewLayoutTransition) { @@ -1423,8 +1427,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { if self.chatPresentationInterfaceStateRequiresInputFocus(chatPresentationInterfaceState) { self.ensureInputViewFocused() } else { - if let inputTextPanelNode = self.inputPanelNode as? ChatTextInputPanelNode { - inputTextPanelNode.ensureUnfocused() + if let _ = self.inputPanelNode as? ChatTextInputPanelNode { + self.context.sharedContext.mainWindow?.simulateKeyboardDismiss(transition: .animated(duration: 0.5, curve: .spring)) + //inputTextPanelNode.ensureUnfocused() } } } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift index 51db01809d..5bf7b86f9c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift @@ -306,7 +306,7 @@ public final class ChatHistoryGridNode: GridNode, ChatHistoryNode { let processedView = ChatHistoryView(originalView: view, filteredEntries: chatHistoryEntriesForView(location: .peer(peerId), view: view, includeUnreadEntry: false, includeEmptyEntry: false, includeChatInfoEntry: false, includeSearchEntry: false, reverse: false, groupMessages: false, selectedMessages: nil, presentationData: chatPresentationData, historyAppearsCleared: false, associatedData: associatedData), associatedData: associatedData, id: id) let previous = previousView.swap(processedView) - let rawTransition = preparedChatHistoryViewTransition(from: previous, to: processedView, reason: reason, reverse: false, chatLocation: .peer(peerId), controllerInteraction: controllerInteraction, scrollPosition: scrollPosition, initialData: nil, keyboardButtonsMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil, flashIndicators: flashIndicators) + let rawTransition = preparedChatHistoryViewTransition(from: previous, to: processedView, reason: reason, reverse: false, chatLocation: .peer(peerId), controllerInteraction: controllerInteraction, scrollPosition: scrollPosition, initialData: nil, keyboardButtonsMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil, flashIndicators: flashIndicators, updatedMessageSelection: false) let mappedTransition = mappedChatHistoryViewListTransition(context: context, peerId: peerId, controllerInteraction: controllerInteraction, transition: rawTransition, from: previous, presentationData: chatPresentationData) return .single(mappedTransition) } diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift index c69e4d0815..7d22680efb 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift @@ -538,7 +538,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { return (view, version) } - let previousView = Atomic<(ChatHistoryView, Int)?>(value: nil) + let previousView = Atomic<(ChatHistoryView, Int, Set?)?>(value: nil) let automaticDownloadNetworkType = context.account.networkType |> map { type -> MediaAutoDownloadNetworkType in switch type { @@ -647,8 +647,9 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { let associatedData = extractAssociatedData(chatLocation: chatLocation, view: view, automaticDownloadNetworkType: networkType, animatedEmojiStickers: animatedEmojiStickers, isScheduledMessages: isScheduledMessages) let processedView = ChatHistoryView(originalView: view, filteredEntries: chatHistoryEntriesForView(location: chatLocation, view: view, includeUnreadEntry: mode == .bubbles, includeEmptyEntry: mode == .bubbles && tagMask == nil, includeChatInfoEntry: mode == .bubbles, includeSearchEntry: includeSearchEntry && tagMask != nil, reverse: reverse, groupMessages: mode == .bubbles, selectedMessages: selectedMessages, presentationData: chatPresentationData, historyAppearsCleared: historyAppearsCleared, associatedData: associatedData), associatedData: associatedData, id: id) - let previousValueAndVersion = previousView.swap((processedView, update.1)) + let previousValueAndVersion = previousView.swap((processedView, update.1, selectedMessages)) let previous = previousValueAndVersion?.0 + let previousSelectedMessages = previousValueAndVersion?.2 if let previousVersion = previousValueAndVersion?.1 { if !GlobalExperimentalSettings.isAppStoreBuild { @@ -695,7 +696,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { } } } - let rawTransition = preparedChatHistoryViewTransition(from: previous, to: processedView, reason: reason, reverse: reverse, chatLocation: chatLocation, controllerInteraction: controllerInteraction, scrollPosition: updatedScrollPosition, initialData: initialData?.initialData, keyboardButtonsMessage: view.topTaggedMessages.first, cachedData: initialData?.cachedData, cachedDataMessages: initialData?.cachedDataMessages, readStateData: initialData?.readStateData, flashIndicators: flashIndicators) + let rawTransition = preparedChatHistoryViewTransition(from: previous, to: processedView, reason: reason, reverse: reverse, chatLocation: chatLocation, controllerInteraction: controllerInteraction, scrollPosition: updatedScrollPosition, initialData: initialData?.initialData, keyboardButtonsMessage: view.topTaggedMessages.first, cachedData: initialData?.cachedData, cachedDataMessages: initialData?.cachedDataMessages, readStateData: initialData?.readStateData, flashIndicators: flashIndicators, updatedMessageSelection: previousSelectedMessages != selectedMessages) let mappedTransition = mappedChatHistoryViewListTransition(context: context, chatLocation: chatLocation, associatedData: associatedData, controllerInteraction: controllerInteraction, mode: mode, transition: rawTransition) Queue.mainQueue().async { guard let strongSelf = self else { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index 0254aee299..73704f4df0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -1890,7 +1890,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode strongSelf.backgroundWallpaperNode.updateFrame(backgroundFrame, transition: transition) } else { strongSelf.backgroundNode.frame = backgroundFrame - strongSelf.backgroundWallpaperNode.frame = backgroundFrame + strongSelf.backgroundWallpaperNode.frame = backgroundFrame//.insetBy(dx: 1.0, dy: 1.0) } if let (rect, size) = strongSelf.absoluteRect { strongSelf.updateAbsoluteRect(rect, within: size) @@ -2081,7 +2081,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode if let backgroundFrameTransition = self.backgroundFrameTransition { let backgroundFrame = CGRect.interpolator()(backgroundFrameTransition.0, backgroundFrameTransition.1, progress) as! CGRect self.backgroundNode.frame = backgroundFrame - self.backgroundWallpaperNode.frame = backgroundFrame + self.backgroundWallpaperNode.frame = backgroundFrame//.insetBy(dx: 1.0, dy: 1.0) if let type = self.backgroundNode.type { var incomingOffset: CGFloat = 0.0 diff --git a/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift b/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift index d3b7c1d8f8..e78538264f 100644 --- a/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift +++ b/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift @@ -5,7 +5,7 @@ import TelegramCore import Display import MergeLists -func preparedChatHistoryViewTransition(from fromView: ChatHistoryView?, to toView: ChatHistoryView, reason: ChatHistoryViewTransitionReason, reverse: Bool, chatLocation: ChatLocation, controllerInteraction: ChatControllerInteraction, scrollPosition: ChatHistoryViewScrollPosition?, initialData: InitialMessageHistoryData?, keyboardButtonsMessage: Message?, cachedData: CachedPeerData?, cachedDataMessages: [MessageId: Message]?, readStateData: [PeerId: ChatHistoryCombinedInitialReadStateData]?, flashIndicators: Bool) -> ChatHistoryViewTransition { +func preparedChatHistoryViewTransition(from fromView: ChatHistoryView?, to toView: ChatHistoryView, reason: ChatHistoryViewTransitionReason, reverse: Bool, chatLocation: ChatLocation, controllerInteraction: ChatControllerInteraction, scrollPosition: ChatHistoryViewScrollPosition?, initialData: InitialMessageHistoryData?, keyboardButtonsMessage: Message?, cachedData: CachedPeerData?, cachedDataMessages: [MessageId: Message]?, readStateData: [PeerId: ChatHistoryCombinedInitialReadStateData]?, flashIndicators: Bool, updatedMessageSelection: Bool) -> ChatHistoryViewTransition { let mergeResult: (deleteIndices: [Int], indicesAndItems: [(Int, ChatHistoryEntry, Int?)], updateIndices: [(Int, ChatHistoryEntry, Int)]) let allUpdated = fromView?.associatedData != toView.associatedData if reverse { @@ -58,31 +58,6 @@ func preparedChatHistoryViewTransition(from fromView: ChatHistoryView?, to toVie stationaryItemRange = (0, Int.max) case .HoleReload: stationaryItemRange = (0, Int.max) - /*if let (_, removeDirection) = removeHoleDirections.first { - switch removeDirection { - case .LowerToUpper: - var holeIndex: MessageIndex? - for (index, _) in filledHoleDirections { - if holeIndex == nil || index < holeIndex! { - holeIndex = index - } - } - - if let holeIndex = holeIndex { - for i in 0 ..< toView.filteredEntries.count { - if toView.filteredEntries[i].index >= holeIndex { - let index = toView.filteredEntries.count - 1 - (i - 1) - stationaryItemRange = (index, Int.max) - break - } - } - } - case .UpperToLower: - break - case .AroundId, .AroundIndex: - break - } - }*/ } for (index, entry, previousIndex) in mergeResult.indicesAndItems { @@ -192,5 +167,9 @@ func preparedChatHistoryViewTransition(from fromView: ChatHistoryView?, to toVie } } + if updatedMessageSelection { + options.insert(.Synchronous) + } + return ChatHistoryViewTransition(historyView: toView, deleteItems: adjustedDeleteIndices, insertEntries: adjustedIndicesAndItems, updateEntries: adjustedUpdateItems, options: options, scrollToItem: scrollToItem, stationaryItemRange: stationaryItemRange, initialData: initialData, keyboardButtonsMessage: keyboardButtonsMessage, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData, scrolledToIndex: scrolledToIndex, animateIn: animateIn, reason: reason, flashIndicators: flashIndicators) }