fix(ios): select Quick Question draft after focus
TestFlight / Build and upload (push) Successful in 1m52s
TestFlight / Build and upload (push) Successful in 1m52s
This commit is contained in:
@@ -9,6 +9,7 @@ struct SybilQuickQuestionView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@FocusState private var promptFocused: Bool
|
||||
@State private var promptSelection: TextSelection?
|
||||
@State private var selectionAppliedForFocusRequest: Int?
|
||||
|
||||
private var hasAnswerContent: Bool {
|
||||
!viewModel.quickQuestionMessages.isEmpty || viewModel.quickQuestionError != nil
|
||||
@@ -36,9 +37,15 @@ struct SybilQuickQuestionView: View {
|
||||
guard !Task.isCancelled else {
|
||||
return
|
||||
}
|
||||
promptFocused = true
|
||||
let prompt = viewModel.quickQuestionPrompt
|
||||
promptSelection = TextSelection(range: prompt.startIndex..<prompt.endIndex)
|
||||
if promptFocused {
|
||||
selectPromptForCurrentFocusRequest()
|
||||
} else {
|
||||
promptFocused = true
|
||||
}
|
||||
}
|
||||
.onChange(of: promptFocused) { _, isFocused in
|
||||
guard isFocused else { return }
|
||||
selectPromptForCurrentFocusRequest()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +213,13 @@ struct SybilQuickQuestionView: View {
|
||||
promptFocused = false
|
||||
_ = viewModel.sendQuickQuestion()
|
||||
}
|
||||
|
||||
private func selectPromptForCurrentFocusRequest() {
|
||||
guard selectionAppliedForFocusRequest != focusRequest else { return }
|
||||
let prompt = viewModel.quickQuestionPrompt
|
||||
promptSelection = TextSelection(range: prompt.startIndex..<prompt.endIndex)
|
||||
selectionAppliedForFocusRequest = focusRequest
|
||||
}
|
||||
}
|
||||
|
||||
private struct QuickQuestionPickerPill: View {
|
||||
|
||||
@@ -37,7 +37,7 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
XCTAssertEqual(prompt.value as? String, "abc")
|
||||
}
|
||||
|
||||
func testQuickQuestionReappearanceSelectsRetainedDraftForReplacement() {
|
||||
func testQuickQuestionDismissalAndReappearanceSelectsRetainedDraftForReplacement() {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
@@ -47,8 +47,12 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
prompt.typeText("retained draft")
|
||||
XCTAssertEqual(prompt.value as? String, "retained draft")
|
||||
|
||||
// A second real home-screen Quick Question action advances the existing
|
||||
// focus request. The original TextSelection binding selects the draft.
|
||||
dismissQuickQuestion()
|
||||
let dismissed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == false"), object: prompt)
|
||||
wait(for: [dismissed], timeout: 5)
|
||||
|
||||
// Reopen through the same home-screen Quick Question route after the
|
||||
// sheet has actually disappeared.
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
@@ -62,6 +66,14 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
app.textFields["Ask anything..."]
|
||||
}
|
||||
|
||||
private func dismissQuickQuestion() {
|
||||
let header = app.staticTexts["Quick question"]
|
||||
XCTAssertTrue(header.waitForExistence(timeout: 5))
|
||||
let dismissStart = header.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
|
||||
let dismissEnd = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.9))
|
||||
dismissStart.press(forDuration: 0.1, thenDragTo: dismissEnd)
|
||||
}
|
||||
|
||||
private func openQuickQuestionFromHomeScreen() {
|
||||
XCUIDevice.shared.press(.home)
|
||||
let sybilIcon = springboard.icons.matching(identifier: "Sybil").firstMatch
|
||||
|
||||
Reference in New Issue
Block a user