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
|
@Environment(\.dismiss) private var dismiss
|
||||||
@FocusState private var promptFocused: Bool
|
@FocusState private var promptFocused: Bool
|
||||||
@State private var promptSelection: TextSelection?
|
@State private var promptSelection: TextSelection?
|
||||||
|
@State private var selectionAppliedForFocusRequest: Int?
|
||||||
|
|
||||||
private var hasAnswerContent: Bool {
|
private var hasAnswerContent: Bool {
|
||||||
!viewModel.quickQuestionMessages.isEmpty || viewModel.quickQuestionError != nil
|
!viewModel.quickQuestionMessages.isEmpty || viewModel.quickQuestionError != nil
|
||||||
@@ -36,9 +37,15 @@ struct SybilQuickQuestionView: View {
|
|||||||
guard !Task.isCancelled else {
|
guard !Task.isCancelled else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
promptFocused = true
|
if promptFocused {
|
||||||
let prompt = viewModel.quickQuestionPrompt
|
selectPromptForCurrentFocusRequest()
|
||||||
promptSelection = TextSelection(range: prompt.startIndex..<prompt.endIndex)
|
} else {
|
||||||
|
promptFocused = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: promptFocused) { _, isFocused in
|
||||||
|
guard isFocused else { return }
|
||||||
|
selectPromptForCurrentFocusRequest()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +213,13 @@ struct SybilQuickQuestionView: View {
|
|||||||
promptFocused = false
|
promptFocused = false
|
||||||
_ = viewModel.sendQuickQuestion()
|
_ = 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 {
|
private struct QuickQuestionPickerPill: View {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
|||||||
XCTAssertEqual(prompt.value as? String, "abc")
|
XCTAssertEqual(prompt.value as? String, "abc")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testQuickQuestionReappearanceSelectsRetainedDraftForReplacement() {
|
func testQuickQuestionDismissalAndReappearanceSelectsRetainedDraftForReplacement() {
|
||||||
app.launch()
|
app.launch()
|
||||||
openQuickQuestionFromHomeScreen()
|
openQuickQuestionFromHomeScreen()
|
||||||
|
|
||||||
@@ -47,8 +47,12 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
|||||||
prompt.typeText("retained draft")
|
prompt.typeText("retained draft")
|
||||||
XCTAssertEqual(prompt.value as? String, "retained draft")
|
XCTAssertEqual(prompt.value as? String, "retained draft")
|
||||||
|
|
||||||
// A second real home-screen Quick Question action advances the existing
|
dismissQuickQuestion()
|
||||||
// focus request. The original TextSelection binding selects the draft.
|
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()
|
openQuickQuestionFromHomeScreen()
|
||||||
|
|
||||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||||
@@ -62,6 +66,14 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
|||||||
app.textFields["Ask anything..."]
|
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() {
|
private func openQuickQuestionFromHomeScreen() {
|
||||||
XCUIDevice.shared.press(.home)
|
XCUIDevice.shared.press(.home)
|
||||||
let sybilIcon = springboard.icons.matching(identifier: "Sybil").firstMatch
|
let sybilIcon = springboard.icons.matching(identifier: "Sybil").firstMatch
|
||||||
|
|||||||
Reference in New Issue
Block a user