mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Stories improvements
This commit is contained in:
@@ -20,6 +20,7 @@ public final class TextFieldComponent: Component {
|
||||
public final class ExternalState {
|
||||
public fileprivate(set) var isEditing: Bool = false
|
||||
public fileprivate(set) var hasText: Bool = false
|
||||
public var initialText: NSAttributedString?
|
||||
|
||||
public init() {
|
||||
}
|
||||
@@ -92,6 +93,17 @@ public final class TextFieldComponent: Component {
|
||||
public struct InputState {
|
||||
public var inputText: NSAttributedString
|
||||
public var selectionRange: Range<Int>
|
||||
|
||||
public init(inputText: NSAttributedString, selectionRange: Range<Int>) {
|
||||
self.inputText = inputText
|
||||
self.selectionRange = selectionRange
|
||||
}
|
||||
|
||||
public init(inputText: NSAttributedString) {
|
||||
self.inputText = inputText
|
||||
let length = inputText.length
|
||||
self.selectionRange = length ..< length
|
||||
}
|
||||
}
|
||||
|
||||
public final class View: UIView, UITextViewDelegate, UIScrollViewDelegate {
|
||||
@@ -104,8 +116,6 @@ public final class TextFieldComponent: Component {
|
||||
private var customEmojiContainerView: CustomEmojiContainerView?
|
||||
private var emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)?
|
||||
|
||||
//private var inputState = InputState(inputText: NSAttributedString(), selectionRange: 0 ..< 0)
|
||||
|
||||
private var inputState: InputState {
|
||||
let selectionRange: Range<Int> = self.textView.selectedRange.location ..< (self.textView.selectedRange.location + self.textView.selectedRange.length)
|
||||
return InputState(inputText: stateAttributedStringForText(self.textView.attributedText ?? NSAttributedString()), selectionRange: selectionRange)
|
||||
@@ -445,6 +455,13 @@ public final class TextFieldComponent: Component {
|
||||
self.component = component
|
||||
self.state = state
|
||||
|
||||
if let initialText = component.externalState.initialText {
|
||||
component.externalState.initialText = nil
|
||||
self.updateInputState { _ in
|
||||
return TextFieldComponent.InputState(inputText: initialText)
|
||||
}
|
||||
}
|
||||
|
||||
if self.emojiViewProvider == nil {
|
||||
self.emojiViewProvider = { [weak self] emoji in
|
||||
guard let component = self?.component else {
|
||||
|
||||
Reference in New Issue
Block a user