diff --git a/.gitignore b/.gitignore index 2d5a961e..802cdd20 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ apps/ios/.expo/ .claude/settings.local.json *.tsbuildinfo coverage/ + +# The share sheet test (apps/ios/scripts/share-sheet.sh) writes its Xcode project and build beside itself. +apps/ios/scripts/share-sheet/ShareSheet.xcodeproj +apps/ios/scripts/share-sheet/build diff --git a/apps/ios/scripts/share-sheet.sh b/apps/ios/scripts/share-sheet.sh new file mode 100755 index 00000000..69ab5acd --- /dev/null +++ b/apps/ios/scripts/share-sheet.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Photographs the share sheet plucking a page from Safari, in the Simulator, with nothing tapped on the Mac: the only +# way to see the share extension as iOS shows it (docs/ios.md, "The share sheet in the Simulator"). +# Usage: apps/ios/scripts/share-sheet.sh [light|dark] [page url] +# Writes /0-share-sheet.png, then 01-….png to 26-….png, about one every third of a second. +set -euo pipefail +udid=$1; app=$2; out=$(mkdir -p "$3" && cd "$3" && pwd); look=${4:-light}; page=${5:-http://127.0.0.1:4180/store/field-notes.html} +here=$(cd "$(dirname "$0")/share-sheet" && pwd) +pods=$(dirname "$(dirname "$(sed -n 's/.*exec "\([^"]*\)".*/\1/p' "$(command -v pod)")")") # CocoaPods' own gems +GEM_HOME=$pods "$(brew --prefix ruby)/bin/ruby" "$here/project.rb" + +xcrun simctl bootstatus "$udid" -b >/dev/null +xcrun simctl install "$udid" "$app" +xcrun simctl launch "$udid" io.getpluck.app >/dev/null; sleep 12 # a demo build signs in on its first launch +xcrun simctl terminate "$udid" io.getpluck.app >/dev/null +xcrun simctl ui "$udid" appearance "$look" +xcrun simctl terminate "$udid" com.apple.mobilesafari >/dev/null 2>&1 || true +xcrun simctl openurl "$udid" "$page"; sleep 5 +# xcodebuild hands the test runner every variable that starts with TEST_RUNNER_, without the prefix. +TEST_RUNNER_SHOTS=$out xcodebuild test -project "$here/ShareSheet.xcodeproj" -scheme ShareSheetTests \ + -destination "platform=iOS Simulator,id=$udid" -derivedDataPath "$here/build" 2>&1 | grep -E "error:|XCTAssert|Test Case .*(passed|failed)" +echo "Pictures in $out" diff --git a/apps/ios/scripts/share-sheet/ShareSheetTests.swift b/apps/ios/scripts/share-sheet/ShareSheetTests.swift new file mode 100644 index 00000000..5a54303e --- /dev/null +++ b/apps/ios/scripts/share-sheet/ShareSheetTests.swift @@ -0,0 +1,37 @@ +import XCTest + +// Opens Safari's share sheet on the page it is showing, picks Pluck, and photographs what follows, every third of a +// second for nine seconds. XCUITest drives the Simulator from inside it: nothing is tapped on the Mac, and the +// Simulator needs no window. Run by scripts/share-sheet.sh, which says where the pictures go (SHOTS). +final class ShareSheetTests: XCTestCase { + private let out = ProcessInfo.processInfo.environment["SHOTS"] ?? NSTemporaryDirectory() + + private func shot(_ name: String) { + try? XCUIScreen.main.screenshot().pngRepresentation.write(to: URL(fileURLWithPath: "\(out)/\(name).png")) + } + + func testPluckFromSafari() { + let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari") + safari.activate() + var share = safari.buttons["ShareButton"] // in the toolbar on iPad and before iOS 26 + if !share.waitForExistence(timeout: 3) { + let more = safari.buttons["MoreMenuButton"] // since iOS 26 an iPhone keeps Share in the page's menu + for _ in 0..<3 { + more.tap() + share = safari.descendants(matching: .any).matching(NSPredicate(format: "label BEGINSWITH 'Share'")).firstMatch + if share.waitForExistence(timeout: 3) { break } + } + } + XCTAssertTrue(share.exists, "Safari shows no Share button") + share.tap() + let pluck = safari.cells["Pluck"].firstMatch + XCTAssertTrue(pluck.waitForExistence(timeout: 8), "Pluck is not in the share sheet's row of apps") + shot("0-share-sheet") + pluck.tap() + let start = Date() + for i in 1...26 { + usleep(250_000) + shot(String(format: "%02d-%.1fs", i, Date().timeIntervalSince(start))) + } + } +} diff --git a/apps/ios/scripts/share-sheet/project.rb b/apps/ios/scripts/share-sheet/project.rb new file mode 100644 index 00000000..c56336d0 --- /dev/null +++ b/apps/ios/scripts/share-sheet/project.rb @@ -0,0 +1,18 @@ +# Writes ShareSheet.xcodeproj beside this file: one UI test bundle with no app of its own (the test drives Safari). +# Run with the Ruby and gems CocoaPods brings, which include xcodeproj (scripts/share-sheet.sh does). +require "fileutils" +require "xcodeproj" + +path = File.join(__dir__, "ShareSheet.xcodeproj") +FileUtils.rm_rf(path) +project = Xcodeproj::Project.new(path) +target = project.new_target(:ui_test_bundle, "ShareSheetTests", :ios, "17.0") +target.add_file_references([project.main_group.new_file("ShareSheetTests.swift")]) +target.build_configurations.each do |c| + c.build_settings.merge!("PRODUCT_BUNDLE_IDENTIFIER" => "io.getpluck.share-sheet-tests", "GENERATE_INFOPLIST_FILE" => "YES", + "SWIFT_VERSION" => "5.0", "CODE_SIGN_IDENTITY" => "-", "CODE_SIGN_STYLE" => "Manual", "TARGETED_DEVICE_FAMILY" => "1,2") +end +project.save +scheme = Xcodeproj::XCScheme.new +scheme.add_test_target(target) +scheme.save_as(path, "ShareSheetTests", true) diff --git a/apps/ios/targets/share/ShareView.swift b/apps/ios/targets/share/ShareView.swift index cc424e7e..2d1a631f 100644 --- a/apps/ios/targets/share/ShareView.swift +++ b/apps/ios/targets/share/ShareView.swift @@ -186,25 +186,36 @@ struct ShareView: View { private var dark: Bool { scheme == .dark } var body: some View { - ZStack(alignment: .bottom) { - Color.black.opacity(0.30).ignoresSafeArea().onTapGesture { model.finish() } + ZStack(alignment: floats ? .center : .bottom) { + scrim.ignoresSafeArea().onTapGesture { model.finish() } VStack(alignment: .leading, spacing: 16) { - Capsule().fill(Palette.handle).frame(width: 36, height: 5).frame(maxWidth: .infinity) + if !floats { Capsule().fill(Palette.handle).frame(width: 36, height: 5).frame(maxWidth: .infinity) } content } - .padding(EdgeInsets(top: 10, leading: 20, bottom: 16, trailing: 20)) + .frame(maxWidth: .infinity, alignment: .leading) + .padding(EdgeInsets(top: floats ? 20 : 10, leading: 20, bottom: floats ? 20 : 16, trailing: 20)) .background { - UnevenRoundedRectangle(topLeadingRadius: 16, topTrailingRadius: 16).fill(Palette.ground(dark)).ignoresSafeArea(.container, edges: .bottom) + if floats { RoundedRectangle(cornerRadius: 16).fill(Palette.ground(dark)) } + else { UnevenRoundedRectangle(topLeadingRadius: 16, topTrailingRadius: 16).fill(Palette.ground(dark)).ignoresSafeArea(.container, edges: .bottom) } } + .animation(reduceMotion ? nil : .easeOut(duration: 0.25), value: formHeight) // the sheet grows into the form, it does not jump } .font(Typeface.body) .foregroundStyle(Palette.ink(dark)) } + // Since iOS 26 the system's own sheet is cleared (ShareViewController.clearCard) and the system dims the app + // behind it, so a dim of ours would only draw that sheet's outline: the scrim is clear, and still takes the tap + // that means Done. On an iPad that sheet was a card in the middle, so Pluck's is one too, with no handle to pull. + private var cleared: Bool { if #available(iOS 26, *) { return true } else { return false } } + private var floats: Bool { cleared && UIDevice.current.userInterfaceIdiom == .pad } + private var scrim: Color { Color.black.opacity(cleared ? 0.001 : 0.30) } + @ViewBuilder private var content: some View { switch model.phase { case .working: - HStack(spacing: 12) { ProgressView(); Text("plucking").foregroundStyle(Palette.ink2(dark)) }.frame(minHeight: 44) + // The same row "Plucked." takes, so nothing moves when it lands: the mark's sparks where the tick will be. + header(String(localized: "plucking"), subtitle: model.title.isEmpty ? nil : model.title, working: true) case .signedOut: Text("signedOutTitle").font(Typeface.heading) Text("signedOutBody").foregroundStyle(Palette.ink2(dark)) @@ -300,9 +311,13 @@ struct ShareView: View { ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 8) { chips() } } } - private func header(_ title: String, subtitle: String?) -> some View { + private func header(_ title: String, subtitle: String?, working: Bool = false) -> some View { HStack(spacing: 12) { - ZStack { Circle().fill(Palette.mint); glyph("M3.5 8.5l3 3 6-7", size: 24, color: Color(hex: 0x151A13), width: 2) }.frame(width: 44, height: 44) + ZStack { + Circle().fill(working ? Palette.brand : Palette.mint) + if working { Sparks(still: reduceMotion) } else { glyph("M3.5 8.5l3 3 6-7", size: 24, color: Color(hex: 0x151A13), width: 2) } + } + .frame(width: 44, height: 44) VStack(alignment: .leading, spacing: 0) { Text(title).font(Typeface.heading).tracking(-0.7) if let subtitle { Text(subtitle).lineLimit(1).truncationMode(.tail).foregroundStyle(Palette.ink2(dark)) } @@ -334,6 +349,27 @@ struct ShareView: View { } } +// The three sparks of the Pluck mark (packages/ui Logo, 1.25 times about their centre on this 16-unit grid), flicking +// out one after another while a pluck is on its way. Still, and whole, with Reduce Motion. +private struct Sparks: View { + let still: Bool + @State private var out = false + private let lines = ["M3.5 6.9375L4.25 2.8125", "M7 9.1875L10.75 5.8125", "M8 13.1875L12.5 12.25"] + + var body: some View { + ZStack { + ForEach(lines.indices, id: \.self) { i in + SVGPath(d: lines[i]).trim(from: 0, to: still || out ? 1 : 0.3) + .stroke(Palette.mint, style: StrokeStyle(lineWidth: 3, lineCap: .round)) + .animation(still ? nil : .easeInOut(duration: 0.45).repeatForever(autoreverses: true).delay(Double(i) * 0.12), value: out) + } + } + .frame(width: 28, height: 28) + .onAppear { out = true } + .accessibilityHidden(true) + } +} + private extension View { // A field on the sheet: the surface, a hairline, 44 points at least. func boxed(_ dark: Bool) -> some View { diff --git a/apps/ios/targets/share/ShareViewController.swift b/apps/ios/targets/share/ShareViewController.swift index f3cc03af..15a2cdf5 100644 --- a/apps/ios/targets/share/ShareViewController.swift +++ b/apps/ios/targets/share/ShareViewController.swift @@ -24,6 +24,25 @@ final class ShareViewController: UIViewController { Task { await model.run(with: Shared.inputs(from: extensionContext)) } } + // Since iOS 26 the sheet a share extension is shown in is made in this process: as tall as an iPhone's screen (a + // card in the middle of an iPad's) and filled with the system background, so the app behind was hidden by an empty + // sheet with Pluck's own at its foot. Clearing what is above this view lets the app show through again, dimmed by + // the system. Before iOS 26 there is nothing of ours above the window to clear. + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated); clearCard() } + override func viewIsAppearing(_ animated: Bool) { super.viewIsAppearing(animated); clearCard() } + override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews(); clearCard() } + + // More than once, as early as there is anything above: the card is on screen from the first frame of its way in. + private func clearCard() { + var below: UIView = view + while let v = below.superview { + // The view that was filled is the system's card: its shadow goes too, or an iPad shows the ghost of a card. + if let filled = v.backgroundColor, filled != .clear { for other in v.subviews where other !== below { other.isHidden = true } } + v.backgroundColor = .clear + below = v + } + } + // Extensions cannot call UIApplication.open; the responder chain reaches the host app's application. private func open(_ url: URL) { var responder: UIResponder? = self diff --git a/docs/ios.md b/docs/ios.md index c996422a..87469370 100644 --- a/docs/ios.md +++ b/docs/ios.md @@ -30,6 +30,12 @@ xcrun simctl io booted screenshot list.png Never set `EXPO_PUBLIC_DEMO_KEY` for a build that leaves your machine. +### The share sheet in the Simulator + +The share extension only shows as iOS shows it when it is opened from another app's share sheet, and no launch argument does that. `apps/ios/scripts/share-sheet.sh [light|dark]` does: it installs a demo build, opens a fixture page in Safari, and runs a small XCUITest (`scripts/share-sheet/`) that opens Share, picks Pluck and takes a picture about every third of a second. The test drives the Simulator from inside, so nothing is tapped on the Mac and the Simulator needs no window. Run it on an iPhone and an iPad, on the oldest and newest iOS you have Simulators for, after any change to `targets/share`. + +Since iOS 26 the system shows a share extension in a sheet of its own, made inside the extension: as tall as an iPhone's screen, a card in the middle of an iPad's, and filled with the system background. Pluck's sheet only fills the foot of it, so `ShareViewController.clearCard` clears what is above its view and the app behind shows through, as it did before iOS 26. If a later iOS builds that sheet differently, the sign is an empty sheet covering the screen with Pluck's at its foot. + ## iPad The same app, universal since the iPad work (`supportsTablet: true`; the share extension builds for iPad too). From 600 wide it shows a split view: the sidebar, the list column and the detail column (`components/split`, sizes in `lib/layout.ts` from the `iPad-Spec` board). Under 600 wide (an iPhone, or an iPad window in Split View or Stage Manager) it is the iPhone layout and tab bar, unchanged. The sidebar is pinned in landscape, and in portrait and on iPad mini it comes over the list from its button or a swipe from the left edge. Rows open beside the list. A link from Safari (`/items/…`, `/lists/…`) still opens full screen. Settings lists its groups in the list column and shows one at a time in the detail column. A hardware keyboard gets the shortcuts in `components/split/Shortcuts.tsx`, which `modules/key-commands` turns into `UIKeyCommand`s so they show when ⌘ is held. Messages that name the device take `{device}`, so an iPad says iPad.