mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Further attach menu refinements
This commit is contained in:
@@ -10,6 +10,7 @@ import AccountContext
|
||||
import AlertUI
|
||||
import PresentationDataUtils
|
||||
import TextFormat
|
||||
import AttachmentUI
|
||||
|
||||
private struct OrderedLinkedListItemOrderingId: RawRepresentable, Hashable {
|
||||
var rawValue: Int
|
||||
@@ -160,8 +161,9 @@ private final class CreatePollControllerArguments {
|
||||
let updateQuiz: (Bool) -> Void
|
||||
let updateSolutionText: (NSAttributedString) -> Void
|
||||
let solutionTextFocused: (Bool) -> Void
|
||||
let questionTextFocused: (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, updateSolutionText: @escaping (NSAttributedString) -> Void, solutionTextFocused: @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, updateSolutionText: @escaping (NSAttributedString) -> Void, solutionTextFocused: @escaping (Bool) -> Void, questionTextFocused: @escaping (Bool) -> Void) {
|
||||
self.updatePollText = updatePollText
|
||||
self.updateOptionText = updateOptionText
|
||||
self.moveToNextOption = moveToNextOption
|
||||
@@ -176,6 +178,7 @@ private final class CreatePollControllerArguments {
|
||||
self.updateQuiz = updateQuiz
|
||||
self.updateSolutionText = updateSolutionText
|
||||
self.solutionTextFocused = solutionTextFocused
|
||||
self.questionTextFocused = questionTextFocused
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,6 +351,8 @@ private enum CreatePollEntry: ItemListNodeEntry {
|
||||
case let .text(placeholder, text, maxLength):
|
||||
return ItemListMultilineInputItem(presentationData: presentationData, text: text, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: maxLength, display: false), sectionId: self.section, style: .blocks, textUpdated: { value in
|
||||
arguments.updatePollText(value)
|
||||
}, updatedFocus: { value in
|
||||
arguments.questionTextFocused(value)
|
||||
}, tag: CreatePollEntryTag.text)
|
||||
case let .optionsHeader(text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
@@ -511,7 +516,11 @@ public final class ComposedPoll {
|
||||
}
|
||||
}
|
||||
|
||||
public func createPollController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peer: EnginePeer, isQuiz: Bool? = nil, completion: @escaping (ComposedPoll) -> Void) -> ViewController {
|
||||
private class CreatePollControllerImpl: ItemListController, AttachmentContainable {
|
||||
public var requestAttachmentMenuExpansion: () -> Void = {}
|
||||
}
|
||||
|
||||
public func createPollController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peer: EnginePeer, isQuiz: Bool? = nil, completion: @escaping (ComposedPoll) -> Void) -> AttachmentContainable {
|
||||
var initialState = CreatePollControllerState()
|
||||
if let isQuiz = isQuiz {
|
||||
initialState.isQuiz = isQuiz
|
||||
@@ -528,6 +537,7 @@ public func createPollController(context: AccountContext, updatedPresentationDat
|
||||
var ensureTextVisibleImpl: (() -> Void)?
|
||||
var ensureOptionVisibleImpl: ((Int) -> Void)?
|
||||
var ensureSolutionVisibleImpl: (() -> Void)?
|
||||
var ensureQuestionVisibleImpl: (() -> Void)?
|
||||
var displayQuizTooltipImpl: ((Bool) -> Void)?
|
||||
var attemptNavigationImpl: (() -> Bool)?
|
||||
|
||||
@@ -767,6 +777,10 @@ public func createPollController(context: AccountContext, updatedPresentationDat
|
||||
if isFocused {
|
||||
ensureSolutionVisibleImpl?()
|
||||
}
|
||||
}, questionTextFocused: { isFocused in
|
||||
if isFocused {
|
||||
ensureQuestionVisibleImpl?()
|
||||
}
|
||||
})
|
||||
|
||||
let previousOptionIds = Atomic<[Int]?>(value: nil)
|
||||
@@ -905,7 +919,7 @@ public func createPollController(context: AccountContext, updatedPresentationDat
|
||||
}
|
||||
|
||||
weak var currentTooltipController: TooltipController?
|
||||
let controller = ItemListController(context: context, state: signal)
|
||||
let controller = CreatePollControllerImpl(context: context, state: signal)
|
||||
controller.navigationPresentation = .modal
|
||||
presentControllerImpl = { [weak controller] c, a in
|
||||
controller?.present(c, in: .window(.root), with: a)
|
||||
@@ -940,6 +954,8 @@ public func createPollController(context: AccountContext, updatedPresentationDat
|
||||
return
|
||||
}
|
||||
|
||||
controller.requestAttachmentMenuExpansion()
|
||||
|
||||
var resultItemNode: ListViewItemNode?
|
||||
let _ = controller.frameForItemNode({ itemNode in
|
||||
if let itemNode = itemNode as? ItemListItemNode {
|
||||
@@ -955,12 +971,22 @@ public func createPollController(context: AccountContext, updatedPresentationDat
|
||||
}
|
||||
})
|
||||
}
|
||||
ensureQuestionVisibleImpl = { [weak controller] in
|
||||
controller?.afterLayout({
|
||||
guard let controller = controller else {
|
||||
return
|
||||
}
|
||||
controller.requestAttachmentMenuExpansion()
|
||||
})
|
||||
}
|
||||
ensureOptionVisibleImpl = { [weak controller] id in
|
||||
controller?.afterLayout({
|
||||
guard let controller = controller else {
|
||||
return
|
||||
}
|
||||
|
||||
controller.requestAttachmentMenuExpansion()
|
||||
|
||||
var resultItemNode: ListViewItemNode?
|
||||
let state = stateValue.with({ $0 })
|
||||
var isLast = false
|
||||
|
||||
Reference in New Issue
Block a user