Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

tray/ios: make the landscape exit actually work

nyblnet5d7072294a1d
diff --git a/tray/README.md b/tray/README.md
index 27365bbb..ba61e267 100644
--- a/tray/README.md
+++ b/tray/README.md
@@ -183,10 +183,11 @@ chevron stands in, pinned to the **safe-area inset** — on a notched iPhone hel
sideways that gutter is dead space no content can occupy, so the exit costs
nothing there.
-UNVERIFIED: the landscape path has not been exercised. `simctl` cannot rotate a
-device, and it captures the display buffer without the rotation transform, so
-its dimensions do not report orientation either. Rotate by hand (⌘← in
-Simulator) to confirm.
+Verified in landscape: the bar is gone, the chevron is present, and tapping it
+returns to the browser. `simctl` cannot rotate a device and its screenshots do
+not report orientation, so this was tested by having the app rotate ITSELF via a
+temporary launch-argument hook (`requestGeometryUpdate`) — worth remembering as
+the way to test orientation-dependent behaviour here.
### Platform notes worth keeping
diff --git a/tray/ios/DocumentBrowserViewController.swift b/tray/ios/DocumentBrowserViewController.swift
index 5402a1ca..c3ec5b69 100644
--- a/tray/ios/DocumentBrowserViewController.swift
+++ b/tray/ios/DocumentBrowserViewController.swift
@@ -98,11 +98,6 @@ final class DocumentBrowserViewController: UIDocumentBrowserViewController,
editor.title = url.deletingPathExtension().deletingPathExtension().lastPathComponent
let nav = UINavigationController(rootViewController: editor)
nav.modalPresentationStyle = .fullScreen
- // Landscape on a phone is SHORT — ~390pt — so a 44pt bar is over a
- // tenth of the height, on the axis a 16:9 canvas needs most. UIKit
- // has this exact case built in; the editor supplies a floating exit
- // for when the bar is away.
- nav.hidesBarsWhenVerticallyCompact = true
editor.onDone = { [weak self, weak nav] in
// close() flushes and relinquishes file coordination; without it
// the document stayed open for the life of the app. The scope is
diff --git a/tray/ios/EditorViewController.swift b/tray/ios/EditorViewController.swift
index 452127dd..e175271a 100644
--- a/tray/ios/EditorViewController.swift
+++ b/tray/ios/EditorViewController.swift
@@ -67,18 +67,25 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
@objc private func doneTapped() { onDone?() }
- /// Fallback exit for when the nav bar is hidden (landscape). Lives in the
- /// SAFE AREA inset — on a notched iPhone held sideways that gutter is dead
- /// space no content can occupy, so this costs nothing at all, unlike the
- /// 44pt the bar spends.
+ /// Fallback exit for when the nav bar is hidden (landscape).
+ ///
+ /// Deliberately DARK, not a light translucent pill: the first attempt used
+ /// 70%-white on Bento's white editor and was invisible on screen.
+ ///
+ /// Bottom-leading, not top-leading. Bento's editor occupies every top edge
+ /// — logo, toolbar, thumbnail rail — so a control up there lands on the
+ /// wordmark. Any host control overlaps SOMETHING while the page's own
+ /// chrome is this dense; the bottom-left corner is the quietest, and it is
+ /// where a thumb rests when a phone is held sideways.
private lazy var floatingExit: UIButton = {
let b = UIButton(type: .system)
var cfg = UIButton.Configuration.filled()
- cfg.image = UIImage(systemName: "chevron.left")
+ cfg.image = UIImage(systemName: "chevron.left",
+ withConfiguration: UIImage.SymbolConfiguration(weight: .semibold))
cfg.cornerStyle = .capsule
- cfg.baseBackgroundColor = UIColor.systemBackground.withAlphaComponent(0.7)
- cfg.baseForegroundColor = .label
- cfg.contentInsets = .init(top: 8, leading: 10, bottom: 8, trailing: 10)
+ cfg.baseBackgroundColor = UIColor.label.withAlphaComponent(0.55)
+ cfg.baseForegroundColor = .systemBackground
+ cfg.contentInsets = .init(top: 10, leading: 12, bottom: 10, trailing: 12)
b.configuration = cfg
b.accessibilityLabel = NSLocalizedString("Documents", comment: "back to the file browser")
b.addTarget(self, action: #selector(doneTapped), for: .touchUpInside)
@@ -86,12 +93,25 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
return b
}()
- /// Keep exactly ONE exit affordance on screen. The bar auto-hides when the
- /// vertical size class is compact (iPhone landscape), and the floating
- /// control stands in for it there.
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- floatingExit.isHidden = !(navigationController?.isNavigationBarHidden ?? false)
+ /// Hide the bar whenever height is scarce, and show the floating exit
+ /// instead. Done EXPLICITLY: `hidesBarsWhenVerticallyCompact` was tried
+ /// first and simply did not fire for a modally-presented navigation
+ /// controller — the bar stayed put in landscape.
+ private func syncChrome() {
+ let short = traitCollection.verticalSizeClass == .compact
+ navigationController?.setNavigationBarHidden(short, animated: false)
+ floatingExit.isHidden = !short
+ view.bringSubviewToFront(floatingExit)
+ }
+
+ override func viewWillAppear(_ animated: Bool) {
+ super.viewWillAppear(animated)
+ syncChrome()
+ }
+
+ override func traitCollectionDidChange(_ previous: UITraitCollection?) {
+ super.traitCollectionDidChange(previous)
+ if traitCollection.verticalSizeClass != previous?.verticalSizeClass { syncChrome() }
}
required init?(coder: NSCoder) { fatalError("not used") }
@@ -121,6 +141,16 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
view.addSubview(webView)
webView.load(URLRequest(url: URL(string: "bento-tray://\(originHost)/index.html")!))
+ view.addSubview(floatingExit)
+ floatingExit.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ floatingExit.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 10),
+ floatingExit.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -10),
+ // Explicit size rather than relying on intrinsic content size.
+ floatingExit.widthAnchor.constraint(equalToConstant: 44),
+ floatingExit.heightAnchor.constraint(equalToConstant: 44),
+ ])
+
// A way BACK. Presented full screen with no chrome, a document was a
// one-way trip: full-screen modals have no interactive dismiss, so the
// only exit was force-quitting the app. The host has to supply this