WIP Attachment toolbar

This commit is contained in:
Kylmakalle
2025-01-24 00:48:41 +02:00
parent 1cc7419e8c
commit 7194cdc6d2
3 changed files with 140 additions and 2 deletions

View File

@@ -289,6 +289,9 @@ public final class TextFieldComponent: Component {
return InputState(inputText: stateAttributedStringForText(self.textView.attributedText ?? NSAttributedString()), selectionRange: selectionRange)
}
// MARK: Swiftgram
var sgToolbarActionObserver: NSObjectProtocol? = nil
private var component: TextFieldComponent?
private weak var state: EmptyComponentState?
private var isUpdating: Bool = false
@@ -367,6 +370,21 @@ public final class TextFieldComponent: Component {
)
}
}
// MARK: Swiftgram
self.sgToolbarActionObserver = NotificationCenter.default.addObserver(forName: Notification.Name("sgToolbarAction"), object: nil, queue: .main, using: { [weak self] notification in
guard let self = self else { return }
if let action = notification.userInfo?["action"] as? String {
self.sgToolbarAction(action)
}
})
}
// MARK: Swiftgram
deinit {
if let sgToolbarActionObserver = self.sgToolbarActionObserver {
NotificationCenter.default.removeObserver(sgToolbarActionObserver)
}
}
required init?(coder: NSCoder) {
@@ -1681,3 +1699,16 @@ extension TextFieldComponent.InputState {
}
}
}
extension TextFieldComponent.View {
func sgToolbarAction(_ action: String) {
switch action {
default:
print("action: \(action)")
// assert(false, "Unhandled action \(action)")
}
}
}