From fa57a05bcbfb6dabc3c280c1634efddb470fddbb Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 9 Sep 2023 20:49:46 +0400 Subject: [PATCH] Media editor improvements --- .../Sources/AttachmentTextInputPanelNode.swift | 5 +++-- .../TGPhotoPaintStickersContext.h | 2 +- .../Sources/TGPhotoCaptionInputMixin.m | 15 ++++++++------- .../Sources/LegacyMessageInputPanel.swift | 18 +++++++++++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift b/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift index 744a83953f..dc68e2f27f 100644 --- a/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift +++ b/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift @@ -476,8 +476,9 @@ public class AttachmentTextInputPanelNode: ASDisplayNode, TGCaptionPanelView, AS public func onAnimateOut() { } - public func dismissInput() { + public func dismissInput() -> Bool { self.ensureUnfocused() + return true } public func baseHeight() -> CGFloat { @@ -1695,7 +1696,7 @@ public class AttachmentTextInputPanelNode: ASDisplayNode, TGCaptionPanelView, AS } } if let sendPressed = self.sendPressed, let presentationInterfaceState = self.effectivePresentationInterfaceState?() { - self.dismissInput() + let _ = self.dismissInput() let effectiveInputText = presentationInterfaceState.interfaceState.composeInputState.inputText sendPressed(effectiveInputText) return diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h index edfd7b7a28..61ae441820 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h @@ -26,7 +26,7 @@ - (NSAttributedString * _Nonnull)caption; - (void)setCaption:(NSAttributedString * _Nullable)caption; -- (void)dismissInput; +- (bool)dismissInput; - (void)animateView:(UIView * _Nonnull)view frame:(CGRect)frame; diff --git a/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m b/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m index 7393ad99e0..1a0bc8ce62 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m +++ b/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m @@ -170,13 +170,14 @@ if (gestureRecognizer.state != UIGestureRecognizerStateRecognized) return; - _editing = false; - - [self.inputPanel dismissInput]; - [_dismissView removeFromSuperview]; - - if (self.finishedWithCaption != nil) - self.finishedWithCaption([_inputPanel caption]); + if ([self.inputPanel dismissInput]) { + _editing = false; + + [_dismissView removeFromSuperview]; + + if (self.finishedWithCaption != nil) + self.finishedWithCaption([_inputPanel caption]); + } } #pragma mark - Input Panel Delegate diff --git a/submodules/TelegramUI/Components/LegacyMessageInputPanel/Sources/LegacyMessageInputPanel.swift b/submodules/TelegramUI/Components/LegacyMessageInputPanel/Sources/LegacyMessageInputPanel.swift index 5745644894..15312be8a7 100644 --- a/submodules/TelegramUI/Components/LegacyMessageInputPanel/Sources/LegacyMessageInputPanel.swift +++ b/submodules/TelegramUI/Components/LegacyMessageInputPanel/Sources/LegacyMessageInputPanel.swift @@ -106,11 +106,19 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView { self.currentIsVideo = isVideo } - public func dismissInput() { + public func dismissInput() -> Bool { if let view = self.inputPanel.view as? MessageInputPanelComponent.View { - self.isEmojiKeyboardActive = false - self.inputView = nil - view.deactivateInput(force: true) + if view.canDeactivateInput() { + self.isEmojiKeyboardActive = false + self.inputView = nil + view.deactivateInput(force: true) + return true + } else { + view.animateError() + return false + } + } else { + return true } } @@ -198,7 +206,7 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView { sendMessageAction: { [weak self] in if let self { self.sendPressed?(self.caption()) - self.dismissInput() + let _ = self.dismissInput() } }, sendMessageOptionsAction: nil,