mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Various improvements
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldCopy)();
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldPaste)();
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldRespondToAction)(SEL _Nullable);
|
||||
@property (nonatomic, copy) ChatInputTextViewImplTargetForAction * _Nullable (^ _Nullable targetForAction)(SEL _Nullable);
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldReturn)();
|
||||
@property (nonatomic, copy) void (^ _Nullable backspaceWhileEmpty)();
|
||||
@property (nonatomic, copy) void (^ _Nullable dropAutocorrectioniOS16)();
|
||||
|
||||
@@ -68,6 +68,13 @@
|
||||
|
||||
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
|
||||
{
|
||||
if (_targetForAction) {
|
||||
ChatInputTextViewImplTargetForAction *result = _targetForAction(action);
|
||||
if (result) {
|
||||
return result.target != nil;
|
||||
}
|
||||
}
|
||||
|
||||
if (_shouldRespondToAction) {
|
||||
if (!_shouldRespondToAction(action)) {
|
||||
return false;
|
||||
@@ -102,6 +109,13 @@
|
||||
}
|
||||
|
||||
- (id)targetForAction:(SEL)action withSender:(id)__unused sender {
|
||||
if (_targetForAction) {
|
||||
ChatInputTextViewImplTargetForAction *result = _targetForAction(action);
|
||||
if (result) {
|
||||
return result.target;
|
||||
}
|
||||
}
|
||||
|
||||
return [super targetForAction:action withSender:sender];
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,18 @@ public protocol ChatInputTextNodeDelegate: AnyObject {
|
||||
func chatInputTextNodeShouldPaste() -> Bool
|
||||
|
||||
func chatInputTextNodeShouldRespondToAction(action: Selector) -> Bool
|
||||
func chatInputTextNodeTargetForAction(action: Selector) -> ChatInputTextNode.TargetForAction?
|
||||
}
|
||||
|
||||
open class ChatInputTextNode: ASDisplayNode, UITextViewDelegate {
|
||||
public final class TargetForAction {
|
||||
public let target: Any?
|
||||
|
||||
public init(target: Any?) {
|
||||
self.target = target
|
||||
}
|
||||
}
|
||||
|
||||
public weak var delegate: ChatInputTextNodeDelegate? {
|
||||
didSet {
|
||||
self.textView.customDelegate = self.delegate
|
||||
@@ -124,6 +133,18 @@ open class ChatInputTextNode: ASDisplayNode, UITextViewDelegate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
self.textView.targetForAction = { [weak self] action in
|
||||
guard let self, let action else {
|
||||
return nil
|
||||
}
|
||||
if let delegate = self.delegate {
|
||||
return delegate.chatInputTextNodeTargetForAction(action: action).flatMap { value in
|
||||
return ChatInputTextViewImplTargetForAction(target: value.target)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func resetInitialPrimaryLanguage() {
|
||||
|
||||
Reference in New Issue
Block a user