mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 05:51:42 +00:00
Fix quiz explanation focus issues
This commit is contained in:
parent
4df2968d33
commit
32f4540fca
@ -205,6 +205,7 @@ private enum CreatePollEntryTag: Equatable, ItemListItemTag {
|
|||||||
case text
|
case text
|
||||||
case option(Int)
|
case option(Int)
|
||||||
case optionsInfo
|
case optionsInfo
|
||||||
|
case solution
|
||||||
|
|
||||||
func isEqual(to other: ItemListItemTag) -> Bool {
|
func isEqual(to other: ItemListItemTag) -> Bool {
|
||||||
if let other = other as? CreatePollEntryTag {
|
if let other = other as? CreatePollEntryTag {
|
||||||
@ -381,7 +382,7 @@ private enum CreatePollEntry: ItemListNodeEntry {
|
|||||||
case let .quizSolutionText(placeholder, text):
|
case let .quizSolutionText(placeholder, text):
|
||||||
return ItemListMultilineInputItem(presentationData: presentationData, text: text, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: 200, display: true), sectionId: self.section, style: .blocks, textUpdated: { text in
|
return ItemListMultilineInputItem(presentationData: presentationData, text: text, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: 200, display: true), sectionId: self.section, style: .blocks, textUpdated: { text in
|
||||||
arguments.updateSolutionText(text)
|
arguments.updateSolutionText(text)
|
||||||
})
|
}, tag: CreatePollEntryTag.solution)
|
||||||
case let .quizSolutionInfo(text):
|
case let .quizSolutionInfo(text):
|
||||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||||
}
|
}
|
||||||
@ -404,6 +405,7 @@ private struct CreatePollControllerState: Equatable {
|
|||||||
var isMultipleChoice: Bool = false
|
var isMultipleChoice: Bool = false
|
||||||
var isQuiz: Bool = false
|
var isQuiz: Bool = false
|
||||||
var solutionText: String = ""
|
var solutionText: String = ""
|
||||||
|
var isEditingSolution: Bool = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createPollControllerEntries(presentationData: PresentationData, peer: Peer, state: CreatePollControllerState, limitsConfiguration: LimitsConfiguration, defaultIsQuiz: Bool?) -> [CreatePollEntry] {
|
private func createPollControllerEntries(presentationData: PresentationData, peer: Peer, state: CreatePollControllerState, limitsConfiguration: LimitsConfiguration, defaultIsQuiz: Bool?) -> [CreatePollEntry] {
|
||||||
@ -481,6 +483,7 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
var dismissImpl: (() -> Void)?
|
var dismissImpl: (() -> Void)?
|
||||||
var ensureTextVisibleImpl: (() -> Void)?
|
var ensureTextVisibleImpl: (() -> Void)?
|
||||||
var ensureOptionVisibleImpl: ((Int) -> Void)?
|
var ensureOptionVisibleImpl: ((Int) -> Void)?
|
||||||
|
var ensureSolutionVisibleImpl: (() -> Void)?
|
||||||
var displayQuizTooltipImpl: ((Bool) -> Void)?
|
var displayQuizTooltipImpl: ((Bool) -> Void)?
|
||||||
var attemptNavigationImpl: (() -> Bool)?
|
var attemptNavigationImpl: (() -> Bool)?
|
||||||
|
|
||||||
@ -497,6 +500,7 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
var state = state
|
var state = state
|
||||||
state.focusOptionId = nil
|
state.focusOptionId = nil
|
||||||
state.text = value
|
state.text = value
|
||||||
|
state.isEditingSolution = false
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
ensureTextVisibleImpl?()
|
ensureTextVisibleImpl?()
|
||||||
@ -710,8 +714,11 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
updateState { state in
|
updateState { state in
|
||||||
var state = state
|
var state = state
|
||||||
state.solutionText = text
|
state.solutionText = text
|
||||||
|
state.focusOptionId = nil
|
||||||
|
state.isEditingSolution = true
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
ensureSolutionVisibleImpl?()
|
||||||
})
|
})
|
||||||
|
|
||||||
let previousOptionIds = Atomic<[Int]?>(value: nil)
|
let previousOptionIds = Atomic<[Int]?>(value: nil)
|
||||||
@ -818,6 +825,9 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
} else {
|
} else {
|
||||||
ensureVisibleItemTag = focusItemTag
|
ensureVisibleItemTag = focusItemTag
|
||||||
}
|
}
|
||||||
|
} else if state.isEditingSolution {
|
||||||
|
focusItemTag = CreatePollEntryTag.solution
|
||||||
|
ensureVisibleItemTag = focusItemTag
|
||||||
} else {
|
} else {
|
||||||
focusItemTag = CreatePollEntryTag.text
|
focusItemTag = CreatePollEntryTag.text
|
||||||
ensureVisibleItemTag = focusItemTag
|
ensureVisibleItemTag = focusItemTag
|
||||||
@ -869,6 +879,27 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
ensureSolutionVisibleImpl = { [weak controller] in
|
||||||
|
controller?.afterLayout({
|
||||||
|
guard let controller = controller else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultItemNode: ListViewItemNode?
|
||||||
|
let _ = controller.frameForItemNode({ itemNode in
|
||||||
|
if let itemNode = itemNode as? ItemListItemNode {
|
||||||
|
if let tag = itemNode.tag, tag.isEqual(to: CreatePollEntryTag.solution) {
|
||||||
|
resultItemNode = itemNode as? ListViewItemNode
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
if let resultItemNode = resultItemNode {
|
||||||
|
controller.ensureItemNodeVisible(resultItemNode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
ensureOptionVisibleImpl = { [weak controller] id in
|
ensureOptionVisibleImpl = { [weak controller] id in
|
||||||
controller?.afterLayout({
|
controller?.afterLayout({
|
||||||
guard let controller = controller else {
|
guard let controller = controller else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user