| index 8f15564..fe04bc3 100644 |
| --- a/native/ios/Review/DocsReviewPhone.swift |
| +++ b/native/ios/Review/DocsReviewPhone.swift |
| @@ -23,6 +23,9 @@ import SwiftUI |
| if ProcessInfo.processInfo.environment["DOCS_REVIEW_COMMAND_PROBE"] == "1" { |
| ReviewCommandProbe() |
| } |
| + if ProcessInfo.processInfo.environment["DOCS_REVIEW_DRAG_PROBE"] == "1" { |
| + ReviewDragProbe() |
| + } |
| } |
| } |
| else { Text("Review fixture unavailable").accessibilityIdentifier("fixture.missing") } |
| @@ -69,3 +72,85 @@ private struct ReviewCommandProbe: View { |
| return view.subviews.lazy.compactMap { focusedEditor(in: $0) }.first |
| } |
| } |
| + |
| +// Review-only probe (Fable's delta review on #180, F5): does UIKit keep a |
| +// contentOffset change made during a drag and during a fling, as the editor |
| +// makes when a peer's edit lands above the screen? It fills the document, |
| +// then while the test drags and flings, moves the offset 40pt once in each, |
| +// and reports from the offsets it samples every frame whether the change |
| +// was kept or undone on the next frame (a one-frame jump). |
| +private struct ReviewDragProbe: View { |
| + @State private var status = "Drag probe waiting for the editor" |
| + var body: some View { |
| + Text(status).font(.caption).accessibilityIdentifier("review.drag.probe") |
| + .task { |
| + var editor: UITextView? |
| + for _ in 0..<300 where editor == nil { |
| + editor = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.flatMap(\.windows).lazy |
| + .compactMap { Self.editor(in: $0) }.first |
| + if editor == nil { try? await Task.sleep(for: .milliseconds(100)) } |
| + } |
| + guard let editor else { status = "Drag probe found no editor"; return } |
| + editor.selectedRange = NSRange(location: editor.textStorage.length, length: 0) |
| + _ = editor.becomeFirstResponder() |
| + editor.insertText(String(repeating: "\nA line of filler text for the scroll probe, long enough to wrap once on a phone.", count: 500)) |
| + _ = editor.resignFirstResponder() |
| + try? await Task.sleep(for: .milliseconds(300)) |
| + editor.setContentOffset(CGPoint(x: 0, y: -editor.adjustedContentInset.top), animated: false) |
| + try? await Task.sleep(for: .milliseconds(500)) |
| + let sampler = ReviewDragSampler(editor) |
| + status = "Drag probe ready" |
| + while !sampler.done { try? await Task.sleep(for: .milliseconds(50)) } |
| + status = "Drag probe: " + sampler.results.joined(separator: "; ") |
| + + String(format: " [text %d characters, content %.0fpt]", editor.textStorage.length, editor.contentSize.height) |
| + } |
| + } |
| + static func editor(in view: UIView) -> UITextView? { |
| + if let editor = view as? UITextView, editor.accessibilityIdentifier == "docs.editor" { return editor } |
| + return view.subviews.lazy.compactMap { editor(in: $0) }.first |
| + } |
| +} |
| + |
| +@MainActor private final class ReviewDragSampler: NSObject { |
| + private weak var view: UIScrollView? |
| + private var link: CADisplayLink? |
| + private var offsets: [CGFloat] = [] |
| + private var phase = "drag" |
| + private var injected: Int? |
| + private var decelerationStopped = false |
| + var results: [String] = [] |
| + var done: Bool { results.count == 2 } |
| + init(_ view: UIScrollView) { |
| + self.view = view |
| + super.init() |
| + link = CADisplayLink(target: self, selector: #selector(tick)) |
| + link?.add(to: .main, forMode: .common) |
| + } |
| + @objc private func tick() { |
| + guard let view, !done else { link?.invalidate(); return } |
| + let active = phase == "drag" ? view.isTracking && !view.isDecelerating : view.isDecelerating |
| + if injected == nil { |
| + if active { offsets.append(view.contentOffset.y) } else if !offsets.isEmpty, phase == "drag", !view.isTracking { offsets = [] } |
| + // Twelve frames into a drag, six into a fling: the edit lands. |
| + if offsets.count == (phase == "drag" ? 12 : 6) { |
| + injected = offsets.count |
| + view.contentOffset.y += 40 |
| + offsets.append(view.contentOffset.y) |
| + } |
| + return |
| + } |
| + offsets.append(view.contentOffset.y) |
| + if phase == "fling", !view.isDecelerating, offsets.count < (injected ?? 0) + 4 { decelerationStopped = true } |
| + guard let at = injected, offsets.count >= at + 9 else { return } |
| + let deltas = zip(offsets.dropFirst(), offsets).map { $0 - $1 } |
| + let before = deltas[max(0, at - 5)..<(at - 1)] |
| + let usual = before.sorted()[before.count / 2] |
| + let after = Array(deltas[at...].prefix(7)) |
| + let undone = after.contains { $0 < usual - 20 } |
| + let list = after.map { String(format: "%.1f", $0) }.joined(separator: ",") |
| + let room = view.contentSize.height - view.bounds.height + view.adjustedContentInset.bottom - offsets[at] |
| + results.append("\(phase): \(undone ? "undone" : "kept")\(decelerationStopped ? ", deceleration stopped" : "") (deltas before ~\(String(format: "%.1f", usual)), after the +40 frame \(list); \(String(format: "%.0f", room))pt of scroll left below at the +40)") |
| + phase = "fling"; injected = nil; offsets = []; decelerationStopped = false |
| + } |
| +} |
| + |