From b6db0715d01dc99b40f16588b38f03db9196f803 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 15 May 2025 17:43:33 +0400 Subject: [PATCH] Various fixes --- .../Sources/DrawingEntitiesView.swift | 1 + .../DrawingUI/Sources/DrawingScreen.swift | 6 +++- .../Sources/DrawingTextEntityView.swift | 2 ++ .../Sources/ChatTextInputPanelNode.swift | 31 ++++++------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/submodules/DrawingUI/Sources/DrawingEntitiesView.swift b/submodules/DrawingUI/Sources/DrawingEntitiesView.swift index 01b660ad8d..108b0dcfba 100644 --- a/submodules/DrawingUI/Sources/DrawingEntitiesView.swift +++ b/submodules/DrawingUI/Sources/DrawingEntitiesView.swift @@ -109,6 +109,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView { public var onInteractionUpdated: (Bool) -> Void = { _ in } public var edgePreviewUpdated: (Bool) -> Void = { _ in } + public var onTextEditingEnded: (Bool) -> Void = { _ in } private let hapticFeedback = HapticFeedback() diff --git a/submodules/DrawingUI/Sources/DrawingScreen.swift b/submodules/DrawingUI/Sources/DrawingScreen.swift index 3da8876d9c..225cc6ed66 100644 --- a/submodules/DrawingUI/Sources/DrawingScreen.swift +++ b/submodules/DrawingUI/Sources/DrawingScreen.swift @@ -3078,6 +3078,11 @@ public final class DrawingToolsInteraction { self.onInteractionUpdated(isInteracting) } } + self.entitiesView.onTextEditingEnded = { [weak self] reset in + if let self { + self.onTextEditingEnded(reset) + } + } self.entitiesView.requestedMenuForEntityView = { [weak self] entityView, isTopmost in guard let self, let node = self.getControllerNode() else { return @@ -3267,7 +3272,6 @@ public final class DrawingToolsInteraction { public func endTextEditing(reset: Bool) { if let entityView = self.entitiesView.selectedEntityView as? DrawingTextEntityView { entityView.endEditing(reset: reset) - self.onTextEditingEnded(reset) } } diff --git a/submodules/DrawingUI/Sources/DrawingTextEntityView.swift b/submodules/DrawingUI/Sources/DrawingTextEntityView.swift index ce68e000e1..98a3d0cbf7 100644 --- a/submodules/DrawingUI/Sources/DrawingTextEntityView.swift +++ b/submodules/DrawingUI/Sources/DrawingTextEntityView.swift @@ -357,6 +357,8 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate selectionView.alpha = 1.0 selectionView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) } + + parentView.onTextEditingEnded(reset) } func suspendEditing() { diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index e900a5c165..40818b355d 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -1273,27 +1273,8 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch } } } - recognizer.waitForTouchUp = { [weak self] in - guard let strongSelf = self, let textInputNode = strongSelf.textInputNode else { - return true - } - - if textInputNode.textView.isFirstResponder { - return true - } else if let (_, _, _, bottomInset, _, _, metrics, _, _) = strongSelf.validLayout { - let textFieldWaitsForTouchUp: Bool - if case .regular = metrics.widthClass, bottomInset.isZero { - textFieldWaitsForTouchUp = true - } else if !textInputNode.textView.text.isEmpty { - textFieldWaitsForTouchUp = true - } else { - textFieldWaitsForTouchUp = false - } - - return textFieldWaitsForTouchUp - } else { - return false - } + recognizer.waitForTouchUp = { + return true } textInputNode.view.addGestureRecognizer(recognizer) self.touchDownGestureRecognizer = recognizer @@ -4086,6 +4067,10 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch } self.inputMenu.activate() + + if let touchDownGestureRecognizer = self.touchDownGestureRecognizer { + self.textInputNode?.view.addGestureRecognizer(touchDownGestureRecognizer) + } } @objc func editableTextNodeDidBeginEditing(_ editableTextNode: ASEditableTextNode) { @@ -4120,6 +4105,10 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch } } } + + if let touchDownGestureRecognizer = self.touchDownGestureRecognizer { + self.textInputNode?.view.removeGestureRecognizer(touchDownGestureRecognizer) + } } func editableTextNodeDidFinishEditing(_ editableTextNode: ASEditableTextNode) {