diff --git a/submodules/AttachmentUI/Sources/AttachmentContainer.swift b/submodules/AttachmentUI/Sources/AttachmentContainer.swift index c7bbfe8b2d..f2c7b88338 100644 --- a/submodules/AttachmentUI/Sources/AttachmentContainer.swift +++ b/submodules/AttachmentUI/Sources/AttachmentContainer.swift @@ -311,7 +311,7 @@ final class AttachmentContainer: ASDisplayNode, UIGestureRecognizerDelegate { } transition.updateFrame(node: self.wrappingNode, frame: CGRect(origin: CGPoint(x: 0.0, y: topInset), size: layout.size)) - let modalProgress = isLandscape ? 0.0 : (1.0 - topInset / defaultTopInset) + let modalProgress = isLandscape ? 0.0 : (1.0 - topInset / defaultTopInset) self.updateModalProgress?(modalProgress, transition) let containerLayout: ContainerViewLayout diff --git a/submodules/AttachmentUI/Sources/AttachmentController.swift b/submodules/AttachmentUI/Sources/AttachmentController.swift index 456c28ddd0..fda073fda2 100644 --- a/submodules/AttachmentUI/Sources/AttachmentController.swift +++ b/submodules/AttachmentUI/Sources/AttachmentController.swift @@ -66,15 +66,18 @@ public class AttachmentController: ViewController { private let container: AttachmentContainer let panel: AttachmentPanel - private var validLayout: ContainerViewLayout? - private var modalProgress: CGFloat = 0.0 - private var currentType: AttachmentButtonType? private var currentController: AttachmentContainable? + private var validLayout: ContainerViewLayout? + private var modalProgress: CGFloat = 0.0 + private var isDismissing = false + private let captionDisposable = MetaDisposable() - private let mediaSelectionCountDisposable = MetaDisposable() + + private var selectionCount: Int = 0 + fileprivate var mediaPickerContext: AttachmentMediaPickerContext? { didSet { if let mediaPickerContext = self.mediaPickerContext { @@ -113,7 +116,7 @@ public class AttachmentController: ViewController { self.addSubnode(self.dim) self.container.updateModalProgress = { [weak self] progress, transition in - if let strongSelf = self, let layout = strongSelf.validLayout { + if let strongSelf = self, let layout = strongSelf.validLayout, !strongSelf.isDismissing { strongSelf.controller?.updateModalStyleOverlayTransitionFactor(progress, transition: transition) strongSelf.modalProgress = progress @@ -195,7 +198,6 @@ public class AttachmentController: ViewController { self.switchToController(.gallery, false) } - private var selectionCount: Int = 0 private func updateSelectionCount(_ count: Int) { self.selectionCount = count if let layout = self.validLayout { @@ -209,29 +211,6 @@ public class AttachmentController: ViewController { } } - override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { - if let controller = self.controller, controller.isInteractionDisabled() { - return self.view - } else { - return super.hitTest(point, with: event) - } - } - - func dismiss(animated: Bool, completion: @escaping () -> Void = {}) { - if animated { - let positionTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut) - positionTransition.updatePosition(node: self.container, position: CGPoint(x: self.container.position.x, y: self.bounds.height + self.container.bounds.height / 2.0 + self.bounds.height), beginWithCurrentState: true, completion: { [weak self] _ in - let _ = self?.container.dismiss(transition: .immediate, completion: completion) - }) - let alphaTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut) - alphaTransition.updateAlpha(node: self.dim, alpha: 0.0) - - self.controller?.updateModalStyleOverlayTransitionFactor(0.0, transition: positionTransition) - } else { - self.controller?.dismiss(animated: false, completion: nil) - } - } - func switchToController(_ type: AttachmentButtonType, _ ascending: Bool) { guard self.currentType != type else { if let controller = self.currentController { @@ -286,16 +265,44 @@ public class AttachmentController: ViewController { }) } - func animateIn(transition: ContainedViewLayoutTransition) { + func animateIn() { ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear).updateAlpha(node: self.dim, alpha: 1.0) - transition.animatePositionAdditive(node: self.container, offset: CGPoint(x: 0.0, y: self.bounds.height + self.container.bounds.height / 2.0 - (self.container.position.y - self.bounds.height))) + let targetPosition = self.container.position + let startPosition = targetPosition.offsetBy(dx: 0.0, dy: self.bounds.height) + + self.container.position = startPosition + let transition = ContainedViewLayoutTransition.animated(duration: 0.4, curve: .spring) + transition.animateView({ + self.container.position = targetPosition + }) + } + + func animateOut(completion: @escaping () -> Void = {}) { + self.isDismissing = true + + let positionTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut) + positionTransition.updatePosition(node: self.container, position: CGPoint(x: self.container.position.x, y: self.bounds.height + self.container.bounds.height / 2.0), completion: { [weak self] _ in + let _ = self?.container.dismiss(transition: .immediate, completion: completion) + }) + let alphaTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut) + alphaTransition.updateAlpha(node: self.dim, alpha: 0.0) + + self.controller?.updateModalStyleOverlayTransitionFactor(0.0, transition: positionTransition) } func scrollToTop() { self.currentController?.scrollToTop?() } + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + if let controller = self.controller, controller.isInteractionDisabled() { + return self.view + } else { + return super.hitTest(point, with: event) + } + } + private var isCollapsed: Bool = false private var isUpdatingContainer = false private var switchingController = false @@ -318,7 +325,7 @@ public class AttachmentController: ViewController { } panelTransition.updateFrame(node: self.panel, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - panelHeight), size: CGSize(width: layout.size.width, height: panelHeight))) - if !self.isUpdatingContainer { + if !self.isUpdatingContainer && !self.isDismissing { self.isUpdatingContainer = true let containerTransition: ContainedViewLayoutTransition @@ -341,7 +348,7 @@ public class AttachmentController: ViewController { self.addSubnode(self.container) self.container.addSubnode(self.panel) - self.animateIn(transition: transition) + self.animateIn() } self.isUpdatingContainer = false @@ -387,8 +394,8 @@ public class AttachmentController: ViewController { public override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { self.view.endEditing(true) if flag { - self.node.dismiss(animated: true, completion: { - super.dismiss(animated: flag, completion: {}) + self.node.animateOut(completion: { + super.dismiss(animated: false, completion: {}) completion?() }) } else { diff --git a/submodules/CheckNode/Sources/CheckNode.swift b/submodules/CheckNode/Sources/CheckNode.swift index a0b076df5b..edc567d3f8 100644 --- a/submodules/CheckNode/Sources/CheckNode.swift +++ b/submodules/CheckNode/Sources/CheckNode.swift @@ -284,11 +284,9 @@ public class InteractiveCheckNode: CheckNode { return } if highlighted { - let transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .spring) - transition.updateTransformScale(node: strongSelf, scale: 0.85) - } else { - let transition: ContainedViewLayoutTransition = .animated(duration: 0.5, curve: .spring) - transition.updateTransformScale(node: strongSelf, scale: 1.0) + strongSelf.layer.animateScale(from: 1.0, to: 0.85, duration: 0.15, removeOnCompletion: false) + } else if let presentationLayer = strongSelf.layer.presentation() { + strongSelf.layer.animateScale(from: CGFloat((presentationLayer.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0), to: 1.0, duration: 0.25, removeOnCompletion: false) } } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index fb8216ee26..3b4d8d231a 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -11185,6 +11185,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G |> deliverOnMainQueue).start(next: { [weak self] configuration in if let strongSelf = self { let controller = WebSearchController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, peer: EnginePeer(peer), chatLocation: strongSelf.chatLocation, configuration: configuration, mode: .media(attachment: attachment, completion: { [weak self] results, selectionState, editingState, silentPosting in + self?.attachmentController?.dismiss(animated: true, completion: nil) legacyEnqueueWebSearchMessages(selectionState, editingState, enqueueChatContextResult: { [weak self] result in if let strongSelf = self { strongSelf.enqueueChatContextResult(results, result, hideVia: true) diff --git a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift index c2a32becc2..79ff528f97 100644 --- a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift +++ b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift @@ -65,7 +65,7 @@ private func preparedTransition(from fromEntries: [WebSearchEntry], to toEntries } private func gridNodeLayoutForContainerLayout(size: CGSize, insets: UIEdgeInsets) -> GridNodeLayoutType { - let side = floorToScreenPixels((size.width - insets.left - insets.right - 3.0) / 4.0) + let side = floorToScreenPixels((size.width - insets.left - insets.right - 2.0) / 3.0) return .fixed(itemSize: CGSize(width: side, height: side), fillWidth: true, lineSpacing: 1.0, itemSpacing: 1.0) }