oficina / docs Public

native: F5 measured: UIKit keeps an offset change made mid-drag and mid-fling

Fable's delta review on #180, F5: `keep()` sets contentOffset inside
layoutSubviews, possibly during a drag or a fling; does UIKit undo it on
the next frame (a one-frame jump)?

There is no way here to have a peer type during a person's gesture, so
the review app gets a probe (DOCS_REVIEW_DRAG_PROBE=1, review target
only): it fills the document, and while NativeUITests.testDragProbe drags
slowly and then flings, moves the offset 40pt once in each, as keep()
does, sampling the offset every frame (CADisplayLink). On a simulator of
its own (iPhone 18 Pro, iOS 27.0, created, booted and deleted for it):

  drag:  kept. Frame deltas ~3.3pt before; after the +40 frame 3.3, 7.3,
         0.0, 4.0, 7.7, 4.0, 0.0 (the finger's pace, no snap back)
  fling: kept. Deltas ~25.7pt before; after 23.0, 22.0, 21.7, 20.7, 20.0,
         19.7, 18.7 (the deceleration carries on; it neither stops nor
         reverses)

So no deferral while tracking or decelerating: in the editor the change
lands in the same layout pass as the content's shift it makes up for.
The test prints its finding (PROBE F5) and gates nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev dee1ecff9976e0ef93b24733e97dc417dfaeffb3 parent 134c492
2 files changed, +111 −0
  • native/ios/Review/DocsReviewPhone.swift +85 −0
  • native/ios/UITests/NativeUITests.swift +26 −0
diff --git a/native/ios/Review/DocsReviewPhone.swift b/native/ios/Review/DocsReviewPhone.swift
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
+ }
+}
+
diff --git a/native/ios/UITests/NativeUITests.swift b/native/ios/UITests/NativeUITests.swift
index 57dd39b..cd3647c 100644
--- a/native/ios/UITests/NativeUITests.swift
+++ b/native/ios/UITests/NativeUITests.swift
@@ -392,6 +392,32 @@ final class NativeUITests: XCTestCase {
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5), "the keyboard comes, not an empty input view")
}
+ /// F5 (Fable's delta review on #180), a measurement, not a gate: does
+ /// UIKit keep a contentOffset change made during a drag and during a
+ /// fling? The review app's drag probe makes one in each; this drives
+ /// the drag and the fling and prints what the probe saw.
+ @MainActor func testDragProbe() throws {
+ try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .phone, "the iPhone editor")
+ let app = XCUIApplication()
+ app.launchEnvironment["DOCS_REVIEW_DRAG_PROBE"] = "1"
+ app.launch()
+ defer { app.terminate() }
+ let editor = try openPhoneDocument(app, "Second review document")
+ let probe = app.staticTexts["review.drag.probe"]
+ XCTAssertTrue(probe.waitForExistence(timeout: 10))
+ let ready = NSPredicate(format: "label == %@", "Drag probe ready")
+ XCTAssertEqual(XCTWaiter().wait(for: [expectation(for: ready, evaluatedWith: probe)], timeout: 30), .completed, probe.label)
+ // A slow drag up, held at the end so it does not fling.
+ let from = editor.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.85))
+ let to = editor.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.25))
+ from.press(forDuration: 0.05, thenDragTo: to, withVelocity: .slow, thenHoldForDuration: 0.5)
+ // Then a fling up.
+ editor.swipeUp(velocity: XCUIGestureVelocity(1500))
+ let finished = NSPredicate(format: "label BEGINSWITH %@", "Drag probe: ")
+ _ = XCTWaiter().wait(for: [expectation(for: finished, evaluatedWith: probe)], timeout: 15)
+ print("PROBE F5 " + probe.label)
+ }
+
/// A reader: back and ••• only, ••• without Share, Rename or Delete,
/// and no keyboard bar (the text cannot take typing).
@MainActor func testPhoneDocumentForAReader() throws {