Skip to content

Commit c2b8db7

Browse files
committed
The slide back behind a switch (OpenBotSlideBack, off): a swipe goes back when it ends until the slide has been seen working; with it on, an edge drag belongs to the swipe before WebKit's text selection
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xYtaUjbkB1hwLtK4TEzhq
1 parent 54d4349 commit c2b8db7

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎.github/workflows/ios-shell.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ jobs:
284284
fi
285285
echo "the store build reads nothing from its launch environment"
286286
app="$(ls -d DerivedDataRelease/Build/Products/Release-iphonesimulator/OpenBotShell.app)"
287-
found="$(strings -a "$app/OpenBotShell" | grep -E 'OPENBOT_SHELL_(TEST_SESSION_COOKIE|TEST_PLAIN_SESSION_COOKIE|TEST_STALE_SESSION|FORCE_OFFLINE|FORCE_DARK|DELAY_FIRST_LOAD|TEST_KILL_CONTENT|TEST_ENTER_PROBE|TEST_LATE_SESSION|HANDOFF_AUTO|DEBUG_SHEET_URL|PLAIN_WEBVIEW|RESET)|debug-state' || true)"
287+
found="$(strings -a "$app/OpenBotShell" | grep -E 'OPENBOT_SHELL_(TEST_SESSION_COOKIE|TEST_PLAIN_SESSION_COOKIE|TEST_STALE_SESSION|FORCE_OFFLINE|FORCE_DARK|DELAY_FIRST_LOAD|TEST_KILL_CONTENT|TEST_ENTER_PROBE|TEST_LATE_SESSION|SLIDE_BACK|HANDOFF_AUTO|DEBUG_SHEET_URL|PLAIN_WEBVIEW|RESET)|debug-state' || true)"
288288
if [ -n "$found" ]; then
289289
echo "::error::DEBUG-only hooks are in the Release binary:"
290290
echo "$found"

‎ios-shell/OpenBotShell/WebController.swift‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ final class WebController: NSObject, WKNavigationDelegate, WKUIDelegate, WKScrip
342342

343343
// MARK: - Back
344344

345+
/// The slide back (BackTransition.swift) is off unless Info.plist's `OpenBotSlideBack` is true (or
346+
/// a DEBUG build's OPENBOT_SHELL_SLIDE_BACK=1): until it has been seen working end to end, a swipe
347+
/// past a third of the width simply goes back when it ends.
348+
static let slideBack: Bool = {
349+
#if DEBUG
350+
if ProcessInfo.processInfo.environment["OPENBOT_SHELL_SLIDE_BACK"] == "1" { return true }
351+
#endif
352+
return (Bundle.main.object(forInfoDictionaryKey: "OpenBotSlideBack") as? Bool) ?? false
353+
}()
354+
345355
/// What the left-edge swipe does now (from the page's last `route`: `ShellBack`).
346356
private(set) var backMode: ShellBack = .webHistory
347357
private var backSwipe: UIScreenEdgePanGestureRecognizer?
@@ -390,7 +400,7 @@ final class WebController: NSObject, WKNavigationDelegate, WKUIDelegate, WKScrip
390400
let width = max(webView.bounds.width, 1)
391401
switch edge.state {
392402
case .began:
393-
swipeSlides = backMode == .sendToPage && transition.canSlide
403+
swipeSlides = WebController.slideBack && backMode == .sendToPage && transition.canSlide
394404
if swipeSlides { transition.begin() }
395405
case .changed:
396406
if swipeSlides { transition.update(progress: move.x / width) }
@@ -423,7 +433,7 @@ final class WebController: NSObject, WKNavigationDelegate, WKUIDelegate, WKScrip
423433
}
424434
switch direction {
425435
case "push": transition.willPush(tab: tab, completion: ok)
426-
case "back": transition.playBack(back: ok)
436+
case "back": if WebController.slideBack { transition.playBack(back: ok) } else { ok() }
427437
default: ok()
428438
}
429439
}
@@ -1000,6 +1010,15 @@ extension WebController: UIGestureRecognizerDelegate {
10001010
shouldRecognizeSimultaneouslyWith other: UIGestureRecognizer) -> Bool {
10011011
true
10021012
}
1013+
1014+
/// A drag from the left edge belongs to the swipe back: WebKit's own recognizers (text selection
1015+
/// took a slow edge drag in take 5) wait until the edge recognizer has failed, which it does at
1016+
/// once for a touch away from the edge.
1017+
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
1018+
shouldBeRequiredToFailBy other: UIGestureRecognizer) -> Bool {
1019+
guard gestureRecognizer === backSwipe, gestureRecognizer.isEnabled else { return false }
1020+
return !(other is TouchDownRecognizer) && !(other is UIPanGestureRecognizer && other.view === webView)
1021+
}
10031022
}
10041023

10051024
extension WebController: WKDownloadDelegate {

‎ios-shell/OpenBotShellUITests/ShellFlowUITests.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ final class ShellFlowUITests: ShellTestCase {
796796
// conversation away over the list's picture and lands on the list at its scroll position, with no
797797
// blank web view on the way (the frames are checked in the video workflow's recording).
798798
func testSwipeBackSlidesToTheList() throws {
799-
let app = launchSignedIn()
799+
let app = launchSignedIn(extra: ["OPENBOT_SHELL_SLIDE_BACK": "1"])
800800
XCTAssertTrue(webText(app, "Start a conversation").waitForExistence(timeout: 30))
801801
tapTab(app, .conversations)
802802
XCTAssertTrue(chatsList(app).waitForExistence(timeout: 15))

‎ios-shell/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ What is native:
5656
the page decides (another tab: back where it was left; the current tab: its root). Without
5757
`canGoBack` (production today) the web view's own back gesture works as before, with the guards
5858
above.
59-
- **The slide back** (`BackTransition.swift`; 1 live web view, the web app still owning the stacks):
59+
- **The slide back** (`BackTransition.swift`; 1 live web view, the web app still owning the stacks).
60+
Off by default (Info.plist `OpenBotSlideBack`, a DEBUG build's `OPENBOT_SHELL_SLIDE_BACK=1`):
61+
in 5 recorded takes it was never seen working end to end (the wrong direction, a stale picture,
62+
no picture, and a slow edge drag taken by WebKit's text selection), so a swipe past a third of
63+
the width goes back when it ends, which works and is tested. With it on:
6064
- For each tab the app keeps a picture of every page under the current one. The picture is taken
6165
when a finger comes down on the page and again after each route settles, and is filed under the
6266
page when it says `will-navigate` (direction "push"); a picture taken when `will-navigate`

‎ios-shell/project.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ targets:
4747
# false brings back the keyboard's form-assistant bar (KeyboardAccessory.swift swaps a private
4848
# WebKit class to hide it; turn this off if App Review objects).
4949
OpenBotHideKeyboardAccessory: true
50+
# true turns on the slide back over a picture of the previous page (BackTransition.swift).
51+
OpenBotSlideBack: false
5052
NSMicrophoneUsageDescription: OpenBot uses the microphone when you talk to a Bot.
5153
NSCameraUsageDescription: OpenBot uses the camera when you share a photo or video with a Bot.
5254
postBuildScripts:

0 commit comments

Comments
 (0)