mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Don't focus on option text when losing focus
This commit is contained in:
parent
8d64864f5e
commit
8be897ea6c
@ -148,7 +148,7 @@ private func processPollText(_ text: String) -> String {
|
|||||||
|
|
||||||
private final class CreatePollControllerArguments {
|
private final class CreatePollControllerArguments {
|
||||||
let updatePollText: (String) -> Void
|
let updatePollText: (String) -> Void
|
||||||
let updateOptionText: (Int, String) -> Void
|
let updateOptionText: (Int, String, Bool) -> Void
|
||||||
let moveToNextOption: (Int) -> Void
|
let moveToNextOption: (Int) -> Void
|
||||||
let moveToPreviousOption: (Int) -> Void
|
let moveToPreviousOption: (Int) -> Void
|
||||||
let removeOption: (Int, Bool) -> Void
|
let removeOption: (Int, Bool) -> Void
|
||||||
@ -160,7 +160,7 @@ private final class CreatePollControllerArguments {
|
|||||||
let displayMultipleChoiceDisabled: () -> Void
|
let displayMultipleChoiceDisabled: () -> Void
|
||||||
let updateQuiz: (Bool) -> Void
|
let updateQuiz: (Bool) -> Void
|
||||||
|
|
||||||
init(updatePollText: @escaping (String) -> Void, updateOptionText: @escaping (Int, String) -> Void, moveToNextOption: @escaping (Int) -> Void, moveToPreviousOption: @escaping (Int) -> Void, removeOption: @escaping (Int, Bool) -> Void, optionFocused: @escaping (Int, Bool) -> Void, setItemIdWithRevealedOptions: @escaping (Int?, Int?) -> Void, toggleOptionSelected: @escaping (Int) -> Void, updateAnonymous: @escaping (Bool) -> Void, updateMultipleChoice: @escaping (Bool) -> Void, displayMultipleChoiceDisabled: @escaping () -> Void, updateQuiz: @escaping (Bool) -> Void) {
|
init(updatePollText: @escaping (String) -> Void, updateOptionText: @escaping (Int, String, Bool) -> Void, moveToNextOption: @escaping (Int) -> Void, moveToPreviousOption: @escaping (Int) -> Void, removeOption: @escaping (Int, Bool) -> Void, optionFocused: @escaping (Int, Bool) -> Void, setItemIdWithRevealedOptions: @escaping (Int?, Int?) -> Void, toggleOptionSelected: @escaping (Int) -> Void, updateAnonymous: @escaping (Bool) -> Void, updateMultipleChoice: @escaping (Bool) -> Void, displayMultipleChoiceDisabled: @escaping () -> Void, updateQuiz: @escaping (Bool) -> Void) {
|
||||||
self.updatePollText = updatePollText
|
self.updatePollText = updatePollText
|
||||||
self.updateOptionText = updateOptionText
|
self.updateOptionText = updateOptionText
|
||||||
self.moveToNextOption = moveToNextOption
|
self.moveToNextOption = moveToNextOption
|
||||||
@ -317,8 +317,8 @@ private enum CreatePollEntry: ItemListNodeEntry {
|
|||||||
case let .option(id, _, placeholder, text, revealed, hasNext, isLast, isSelected):
|
case let .option(id, _, placeholder, text, revealed, hasNext, isLast, isSelected):
|
||||||
return CreatePollOptionItem(presentationData: presentationData, id: id, placeholder: placeholder, value: text, isSelected: isSelected, maxLength: maxOptionLength, editing: CreatePollOptionItemEditing(editable: true, hasActiveRevealControls: revealed), sectionId: self.section, setItemIdWithRevealedOptions: { id, fromId in
|
return CreatePollOptionItem(presentationData: presentationData, id: id, placeholder: placeholder, value: text, isSelected: isSelected, maxLength: maxOptionLength, editing: CreatePollOptionItemEditing(editable: true, hasActiveRevealControls: revealed), sectionId: self.section, setItemIdWithRevealedOptions: { id, fromId in
|
||||||
arguments.setItemIdWithRevealedOptions(id, fromId)
|
arguments.setItemIdWithRevealedOptions(id, fromId)
|
||||||
}, updated: { value in
|
}, updated: { value, isFocused in
|
||||||
arguments.updateOptionText(id, value)
|
arguments.updateOptionText(id, value, isFocused)
|
||||||
}, next: hasNext ? {
|
}, next: hasNext ? {
|
||||||
arguments.moveToNextOption(id)
|
arguments.moveToNextOption(id)
|
||||||
} : nil, delete: { focused in
|
} : nil, delete: { focused in
|
||||||
@ -456,13 +456,15 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
ensureTextVisibleImpl?()
|
ensureTextVisibleImpl?()
|
||||||
}, updateOptionText: { id, value in
|
}, updateOptionText: { id, value, isFocused in
|
||||||
var ensureVisibleId = id
|
var ensureVisibleId = id
|
||||||
updateState { state in
|
updateState { state in
|
||||||
var state = state
|
var state = state
|
||||||
for i in 0 ..< state.options.count {
|
for i in 0 ..< state.options.count {
|
||||||
if state.options[i].item.id == id {
|
if state.options[i].item.id == id {
|
||||||
state.focusOptionId = id
|
if isFocused {
|
||||||
|
state.focusOptionId = id
|
||||||
|
}
|
||||||
state.options.update(at: i, { option in
|
state.options.update(at: i, { option in
|
||||||
option.text = value
|
option.text = value
|
||||||
})
|
})
|
||||||
@ -478,7 +480,9 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
ensureOptionVisibleImpl?(ensureVisibleId)
|
if isFocused {
|
||||||
|
ensureOptionVisibleImpl?(ensureVisibleId)
|
||||||
|
}
|
||||||
}, moveToNextOption: { id in
|
}, moveToNextOption: { id in
|
||||||
var resetFocusOptionId: Int?
|
var resetFocusOptionId: Int?
|
||||||
updateState { state in
|
updateState { state in
|
||||||
|
@ -23,7 +23,7 @@ class CreatePollOptionItem: ListViewItem, ItemListItem {
|
|||||||
let editing: CreatePollOptionItemEditing
|
let editing: CreatePollOptionItemEditing
|
||||||
let sectionId: ItemListSectionId
|
let sectionId: ItemListSectionId
|
||||||
let setItemIdWithRevealedOptions: (Int?, Int?) -> Void
|
let setItemIdWithRevealedOptions: (Int?, Int?) -> Void
|
||||||
let updated: (String) -> Void
|
let updated: (String, Bool) -> Void
|
||||||
let next: (() -> Void)?
|
let next: (() -> Void)?
|
||||||
let delete: (Bool) -> Void
|
let delete: (Bool) -> Void
|
||||||
let canDelete: Bool
|
let canDelete: Bool
|
||||||
@ -31,7 +31,7 @@ class CreatePollOptionItem: ListViewItem, ItemListItem {
|
|||||||
let toggleSelected: () -> Void
|
let toggleSelected: () -> Void
|
||||||
let tag: ItemListItemTag?
|
let tag: ItemListItemTag?
|
||||||
|
|
||||||
init(presentationData: ItemListPresentationData, id: Int, placeholder: String, value: String, isSelected: Bool?, maxLength: Int, editing: CreatePollOptionItemEditing, sectionId: ItemListSectionId, setItemIdWithRevealedOptions: @escaping (Int?, Int?) -> Void, updated: @escaping (String) -> Void, next: (() -> Void)?, delete: @escaping (Bool) -> Void, canDelete: Bool, focused: @escaping (Bool) -> Void, toggleSelected: @escaping () -> Void, tag: ItemListItemTag?) {
|
init(presentationData: ItemListPresentationData, id: Int, placeholder: String, value: String, isSelected: Bool?, maxLength: Int, editing: CreatePollOptionItemEditing, sectionId: ItemListSectionId, setItemIdWithRevealedOptions: @escaping (Int?, Int?) -> Void, updated: @escaping (String, Bool) -> Void, next: (() -> Void)?, delete: @escaping (Bool) -> Void, canDelete: Bool, focused: @escaping (Bool) -> Void, toggleSelected: @escaping () -> Void, tag: ItemListItemTag?) {
|
||||||
self.presentationData = presentationData
|
self.presentationData = presentationData
|
||||||
self.id = id
|
self.id = id
|
||||||
self.placeholder = placeholder
|
self.placeholder = placeholder
|
||||||
@ -182,7 +182,7 @@ class CreatePollOptionItemNode: ItemListRevealOptionsItemNode, ItemListItemNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func editableTextNodeDidFinishEditing(_ editableTextNode: ASEditableTextNode) {
|
func editableTextNodeDidFinishEditing(_ editableTextNode: ASEditableTextNode) {
|
||||||
self.editableTextNodeDidUpdateText(editableTextNode)
|
self.internalEditableTextNodeDidUpdateText(editableTextNode, isLosingFocus: true)
|
||||||
self.item?.focused(false)
|
self.item?.focused(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +213,10 @@ class CreatePollOptionItemNode: ItemListRevealOptionsItemNode, ItemListItemNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func editableTextNodeDidUpdateText(_ editableTextNode: ASEditableTextNode) {
|
func editableTextNodeDidUpdateText(_ editableTextNode: ASEditableTextNode) {
|
||||||
|
self.internalEditableTextNodeDidUpdateText(editableTextNode, isLosingFocus: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func internalEditableTextNodeDidUpdateText(_ editableTextNode: ASEditableTextNode, isLosingFocus: Bool) {
|
||||||
if let item = self.item {
|
if let item = self.item {
|
||||||
let text = self.textNode.attributedText ?? NSAttributedString()
|
let text = self.textNode.attributedText ?? NSAttributedString()
|
||||||
|
|
||||||
@ -226,11 +230,11 @@ class CreatePollOptionItemNode: ItemListRevealOptionsItemNode, ItemListItemNode,
|
|||||||
if text.string != updatedAttributedText.string {
|
if text.string != updatedAttributedText.string {
|
||||||
self.textNode.attributedText = updatedAttributedText
|
self.textNode.attributedText = updatedAttributedText
|
||||||
}
|
}
|
||||||
item.updated(updatedText)
|
item.updated(updatedText, !isLosingFocus && editableTextNode.isFirstResponder())
|
||||||
if hadReturn {
|
if hadReturn {
|
||||||
if let next = item.next {
|
if let next = item.next {
|
||||||
next()
|
next()
|
||||||
} else {
|
} else if !isLosingFocus {
|
||||||
editableTextNode.resignFirstResponder()
|
editableTextNode.resignFirstResponder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user