oficina / base Public

Attaching on the iPhone: the + menu, pasted images, numbered photos

Task 18 of the native slice 2 part 1 plan.

- AttachSources (platform-neutral, tested): the + menu offers Photos,
  Camera only where there is one, Files, and Paste only when the
  pasteboard says it holds images or files (asking doesn't read it, so no
  prompt); photos may fill the places left of five; a paste attaches when
  it holds an image and no text (D8).
- PhoneAttachmentPicker (Equipo's, Task 12) takes Base's rules: Photos
  matching .images (a Live Photo gives its still), each loaded as a file
  through a FileRepresentation, staged inside its importing closure into a
  directory the draft owns, then prepared from the staged URL behind the
  gate; Camera; Files with P10's types; Paste as Equipo's.
- Camera and Photos items are named Photo 1.jpg, Photo 2.jpg… in the order
  chosen (DRAFT "Photo {n}"), counted afresh for each message.
- The field takes a pasted image: Ask's composer adds public.image to the
  UITextView's pasteConfiguration, and ComposerPaste hands an image-only
  paste to the draft (setNoResult) and leaves text as before.
- The + sits left of the field while can_attach; the chips are one line
  that scrolls sideways, wrapping at the accessibility sizes so a chip is
  never cut off. A chip shows the prepared file's name (IMG_4021.HEIC
  becomes IMG_4021.jpg).
- NSCameraUsageDescription in ios/project.yml (DRAFT: "Base uses the
  camera to take a photo for Ask.", in copy-review/slice2-part1.json).

Snapshots: base-phone ask-attach (mockup phone-attach: a photo from HEIC,
one uploading, a CSV), light and dark, default and AX3. The + menu is the
system's and isn't drawn. base-mac window-attach re-recorded (chip names).

Not done here: the device checks on TestFlight 0.1.3 (4) (five 48 MP
photos, a Live Photo, ProRAW, Camera, Files, a pasted screenshot,
background during an upload). They need Paul's iPhone; the build is not
uploaded (asked at stop 4).

Gate: swift test -j 4 --filter 'AttachSourcesTests|AttachmentDraftTests': 16
passed; build-iphone.sh simulator succeeded; snapshots.sh record iphone
PhoneSnapshots (reviewed), then compare mac and compare iphone: passed.
check-strings.py ok.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Summary

Task 18: attaching on the iPhone
claude agent, operated by paul@keymail.dev 3367a35c4ed68f7c92d0d8771ca2558e883189a3 parent ddff54d
17 files changed, +208 −28
  • native/apple/Sources/BaseKit/Ask/Composer.swift +34 −5
  • native/apple/Sources/BaseKit/Attachments/AttachSources.swift +20 −0
  • native/apple/Sources/BaseKit/Attachments/AttachmentDraft.swift +20 −3
  • native/apple/Sources/BaseKit/Attachments/AttachmentViews.swift +5 −2
  • native/apple/Sources/BaseKit/Attachments/PhoneAttachmentPicker.swift +41 −15
  • native/apple/Sources/BaseKit/Phone/PhoneAskScreen.swift +1 −1
  • native/apple/Sources/BaseKit/Resources/Localizable.xcstrings +12 −0
  • native/apple/Tests/BaseKitTests/AttachSourcesTests.swift +38 −0
  • native/apple/Tests/BaseSnapshots/AttachmentFixtures.swift +27 −2
  • native/apple/Tests/BaseSnapshots/MacSnapshots.swift +7 −0
  • native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-dark-default.png binary
  • native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-light-default.png binary
  • native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-ax3.png binary
  • native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-default.png binary
  • native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-ax3.png binary
  • native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-default.png binary
  • native/ios/project.yml +3 −0

CI passed — run details

CI log
=== build ===
CGO_ENABLED=0 go build ./...
=== vet ===
go vet ./...
=== fmt-check ===
=== staticcheck ===
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...
=== govulncheck ===
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
No vulnerabilities found.
=== gitleaks ===
10:15PM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
10:15PM INF 1 commits scanned.
10:15PM INF scanned ~3118629 bytes (3.12 MB) in 283ms
10:15PM INF no leaks found
=== budget ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 22 directories within budget
=== script-test ===
scripts/prepare-apps_test.sh
ok   releases lookup failure stops before ship
ok   app owned elsewhere stops the script
ok   apps listing failure stops before create
ok   ambiguous release dir is refused
ok   explicit version resolves the ambiguity
ok   releases match is exact, not substring
ok   shipped version is only promoted, existing app not created
ok   fresh account creates, ships, promotes to edge, enables
ok   failing promote stops the script
ok   ship is retried while uploads are rate limited
all passed
hack/fonts_test.sh
fonts_test: ok
=== test ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -count=1 ./...

receipt: test step 9.069s against a 60s target (the gate's other steps are not in this figure)
receipt: 16 packages ran, 0 cached, 6 without tests, 0 failed
receipt: slow package 8.294s amadan.net/oficina/base/internal/webtest
receipt: slow package 1.031s amadan.net/oficina/base/internal/issuer
receipt: slow package 625ms amadan.net/oficina/base/internal/equipo
receipt: slow package 585ms amadan.net/oficina/base/internal/operations
receipt: slow package 179ms amadan.net/oficina/base/internal/web
receipt: slow test 1.51s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.08s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 790ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
receipt: slow test 610ms amadan.net/oficina/base/internal/webtest TestAskUploadStalledBodyFreesItsSlot
receipt: slow test 510ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
=== native ===
strings: copy review's strings.json is not here (git-ignored); its comparison skipped
strings: 176 in the catalog, 173 used
worktree-lib_test: ok
diff --git a/native/apple/Sources/BaseKit/Ask/Composer.swift b/native/apple/Sources/BaseKit/Ask/Composer.swift
index d3b4024..77afa0e 100644
--- a/native/apple/Sources/BaseKit/Ask/Composer.swift
+++ b/native/apple/Sources/BaseKit/Ask/Composer.swift
@@ -54,6 +54,13 @@ public struct Composer: View {
let p = Palette(scheme)
let shape = RoundedRectangle(cornerRadius: 10, style: .continuous)
return HStack(alignment: .bottom, spacing: 0) {
+ #if os(iOS)
+ // The +, left of the field, only while Ask takes files: Photos,
+ // Camera, Files and Paste (Task 18).
+ if attaching, model.canAttach {
+ PhoneAttachmentPicker(draft: model.attachments).padding(.leading, 2)
+ }
+ #endif
TextField(text: $model.text, prompt: Text(BaseText.text("ask.placeholder")).foregroundStyle(p[.placeholder]), axis: .vertical) {
Text(BaseText.text("ask.message_label"))
}
@@ -257,14 +264,22 @@ enum ComposerReturn: Equatable {
weak var anchor: UIView?
var editor: (UIView & UITextInput)? { anchor?.window.flatMap(Self.firstResponder) }
private let paste = ComposerPaste()
+ /// Ask's composer: what takes an image pasted into the field (Task 18).
+ var attach: ((NSItemProvider) -> Void)? { didSet { paste.attach = attach } }
/// Whether the field has the keyboard; once it has, its text view
- /// takes rich pastes as Markdown (ComposerPaste).
+ /// takes rich pastes as Markdown (ComposerPaste), and in Ask's composer
+ /// pasted images too.
var focused = false {
didSet {
guard focused else { return }
Task { @MainActor [weak self] in
- guard let self, let view = self.editor as? UITextView, view.pasteDelegate !== self.paste else { return }
- view.pasteDelegate = self.paste
+ guard let self, let view = self.editor as? UITextView else { return }
+ if view.pasteDelegate !== self.paste { view.pasteDelegate = self.paste }
+ if self.attach != nil {
+ var types = view.pasteConfiguration?.acceptableTypeIdentifiers ?? UIPasteConfiguration(forAccepting: NSString.self).acceptableTypeIdentifiers
+ if !types.contains(UTType.image.identifier) { types.append(UTType.image.identifier) }
+ view.pasteConfiguration = UIPasteConfiguration(acceptableTypeIdentifiers: types)
+ }
}
}
}
@@ -290,9 +305,16 @@ enum ComposerReturn: Equatable {
/// The iPhone and iPad field's paste: HTML or RTF becomes Markdown, in
/// place of the selection as any paste; anything else is pasted as is.
final class ComposerPaste: NSObject, UITextPasteDelegate {
+ /// Ask's composer's: an image alone attaches, and the field gets nothing.
+ var attach: ((NSItemProvider) -> Void)?
func textPasteConfigurationSupporting(_ textPasteConfigurationSupporting: any UITextPasteConfigurationSupporting, transform item: UITextPasteItem) {
let provider = item.itemProvider
nonisolated(unsafe) let item = item
+ if let attach, AttachSources.pasteAttaches(provider.registeredTypeIdentifiers) {
+ attach(provider)
+ item.setNoResult()
+ return
+ }
for (type, convert) in [(UTType.html, { (data: Data) in PasteMarkdown.html(data).flatMap(PasteMarkdown.fromHTML) }),
(UTType.rtf, PasteMarkdown.fromRTF)] where provider.hasItemConformingToTypeIdentifier(type.identifier) {
provider.loadDataRepresentation(forTypeIdentifier: type.identifier) { data, _ in
@@ -329,9 +351,16 @@ struct ComposerAnchor: UIViewRepresentable {
let model: AskModel
let attaching: Bool
func makeUIView(context: Context) -> UIView {
- let view = UIView(); view.isUserInteractionEnabled = false; input.anchor = view; input.model = model; return view
+ let view = UIView(); view.isUserInteractionEnabled = false; wire(view); return view
+ }
+ func updateUIView(_ view: UIView, context: Context) { wire(view) }
+ private func wire(_ view: UIView) {
+ input.anchor = view; input.model = model
+ input.attach = attaching ? { [weak model] provider in
+ guard let model, model.canAttach else { return }
+ AttachDrop.receive([provider], into: model.attachments)
+ } : nil
}
- func updateUIView(_ view: UIView, context: Context) { input.anchor = view; input.model = model }
}
#endif
diff --git a/native/apple/Sources/BaseKit/Attachments/AttachSources.swift b/native/apple/Sources/BaseKit/Attachments/AttachSources.swift
index 7d49b15..ebf0968 100644
--- a/native/apple/Sources/BaseKit/Attachments/AttachSources.swift
+++ b/native/apple/Sources/BaseKit/Attachments/AttachSources.swift
@@ -4,6 +4,26 @@ import UniformTypeIdentifiers
/// Where files come from (P10). The logic is here, platform-neutral, so it
/// can be tested; the views only call it.
public enum AttachSources {
+ /// The iPhone's + menu, Equipo's four.
+ public enum Source: Equatable, Sendable { case photos, camera, files, paste }
+
+ /// Photos and Files always; Camera where there is one; Paste only when
+ /// the pasteboard says it holds images or files (asking doesn't read
+ /// it, so iOS shows no prompt until Paste is chosen).
+ public static func menu(cameraAvailable: Bool, pasteboardHasFiles: Bool) -> [Source] {
+ [.photos] + (cameraAvailable ? [.camera] : []) + [.files] + (pasteboardHasFiles ? [.paste] : [])
+ }
+
+ /// How many more photos may be chosen: the places left of five.
+ public static func photosLeft(chips: Int) -> Int { max(0, AttachmentLimits.maxCount - chips) }
+
+ /// A paste through the field attaches when it holds an image and no
+ /// text (D8); otherwise it is pasted as text, as now.
+ public static func pasteAttaches(_ typeIdentifiers: [String]) -> Bool {
+ let types = typeIdentifiers.compactMap(UTType.init)
+ return types.contains { $0.conforms(to: .image) } && !types.contains { $0.conforms(to: .text) }
+ }
+
/// The nine types Equipo takes, and HEIC, HEIF and TIFF, which become
/// JPEG on the device. The Mac's file chooser offers these.
public static let macTypes: [UTType] = [.png, .jpeg, .webP, .gif, .pdf, .plainText,
diff --git a/native/apple/Sources/BaseKit/Attachments/AttachmentDraft.swift b/native/apple/Sources/BaseKit/Attachments/AttachmentDraft.swift
index e95680e..b587062 100644
--- a/native/apple/Sources/BaseKit/Attachments/AttachmentDraft.swift
+++ b/native/apple/Sources/BaseKit/Attachments/AttachmentDraft.swift
@@ -9,7 +9,9 @@ import Observation
public struct Item: Identifiable, Sendable {
public enum State: Sendable { case uploading(Double), ready(AskAttachment), failed(String) }
public let id: UUID
- public let name: String
+ /// As added, then the prepared file's (IMG_4021.HEIC becomes
+ /// IMG_4021.jpg): what the chip, Remove and VoiceOver say.
+ public var name: String
public var state: State
public var file: AttachmentFile?
/// A line under the chip that isn't a failure: a PDF's.
@@ -53,6 +55,20 @@ import Observation
self.sleep = sleep
}
+ /// Camera and Photos items' names, in the order chosen (P10): "Photo
+ /// 1.jpg", "Photo 2.jpg"…, so "Remove Photo 2.jpg" says which.
+ @ObservationIgnored private var photos = 0
+ public func nextPhotoName() -> String {
+ photos += 1
+ return BaseText.format("native.attach.photo", ["n": String(photos)]) + ".jpg"
+ }
+
+ /// A file staged into `directory` (which the draft then owns, and
+ /// removes), prepared from its URL behind the gate (P10, Photos).
+ public func add(stagedURL url: URL, name: String, directory: URL) async {
+ await add(.file(url), name: name, ownedDirectory: directory)
+ }
+
/// The uploads not sent yet, for the discard when the session ends.
public var unsentIDs: [String] { readyAttachments.map(\.id) }
/// The app went to the background: files still queued wait (P8.5).
@@ -102,7 +118,7 @@ import Observation
Task { try? await client.delete(uploaded.id) }
}
}
- public func clear() { for upload in uploads.values { upload.task.cancel() }; uploads = [:]; items = []; for id in Array(stagedDirectories.keys) { cleanStaged(id) }; notice = nil; settle() }
+ public func clear() { for upload in uploads.values { upload.task.cancel() }; uploads = [:]; items = []; for id in Array(stagedDirectories.keys) { cleanStaged(id) }; notice = nil; photos = 0; settle() }
private func cleanStaged(_ id: UUID) { if let directory = stagedDirectories.removeValue(forKey: id) { try? FileManager.default.removeItem(at: directory) } }
public func retry(_ id: UUID) async {
guard let i = items.firstIndex(where: { $0.id == id }), items[i].failure != nil else { return }
@@ -161,6 +177,7 @@ import Observation
try Task.checkCancellation()
guard let i = index(id, item.generation) else { return }
items[i].file = file
+ items[i].name = file.name
if file.mediaType == "application/pdf" { items[i].note = BaseText.text("native.attach.pdf") }
let backoff: [Duration] = [.seconds(2), .seconds(4), .seconds(8)]
var retries = 0
@@ -174,7 +191,7 @@ import Observation
}
guard let i = index(id, item.generation) else { return }
items[i].state = .ready(attachment)
- announce(BaseText.format("native.attach.attached", ["name": item.name]))
+ announce(BaseText.format("native.attach.attached", ["name": file.name]))
return
} catch let refusal as AttachmentRefusal where refusal.code == "busy" && retries < backoff.count {
// A busy Base: wait, then a fresh try, its ring from 0.
diff --git a/native/apple/Sources/BaseKit/Attachments/AttachmentViews.swift b/native/apple/Sources/BaseKit/Attachments/AttachmentViews.swift
index ebc3004..d886bc3 100644
--- a/native/apple/Sources/BaseKit/Attachments/AttachmentViews.swift
+++ b/native/apple/Sources/BaseKit/Attachments/AttachmentViews.swift
@@ -19,12 +19,14 @@ public struct AttachmentDraftStrip: View {
let layout: Layout
@State private var height: CGFloat = 0
@Environment(\.colorScheme) private var scheme
+ @Environment(\.dynamicTypeSize) private var typeSize
private var p: Palette { Palette(scheme) }
public init(draft: AttachmentDraft, layout: Layout) { self.draft = draft; self.layout = layout }
public var body: some View {
VStack(alignment: .leading, spacing: 6) {
if !draft.items.isEmpty {
- switch layout {
+ // At the accessibility sizes the iPhone's chips wrap too.
+ switch typeSize.isAccessibilitySize ? .wrap : layout {
case .wrap:
ScrollView {
FlowLayout(spacing: 8) { chips }
@@ -33,7 +35,7 @@ public struct AttachmentDraftStrip: View {
.frame(height: min(height, 196))
.scrollBounceBehavior(.basedOnSize)
case .line:
- ScrollView(.horizontal) { HStack(spacing: 8) { chips } }
+ ScrollView(.horizontal) { HStack(alignment: .top, spacing: 8) { chips } }
.scrollIndicators(.never)
}
}
@@ -79,6 +81,7 @@ struct AttachmentChip: View {
Text(verbatim: item.name).font(BaseFont.body(13.5, .semibold, relativeTo: .footnote)).lineLimit(1).truncationMode(.middle)
Text(verbatim: line).font(BaseFont.body(12, relativeTo: .caption))
.foregroundStyle(item.failure != nil ? p[.frost] : p[.haze])
+ .lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
}
.frame(maxWidth: 160, alignment: .leading)
diff --git a/native/apple/Sources/BaseKit/Attachments/PhoneAttachmentPicker.swift b/native/apple/Sources/BaseKit/Attachments/PhoneAttachmentPicker.swift
index c9fe9cd..0133407 100644
--- a/native/apple/Sources/BaseKit/Attachments/PhoneAttachmentPicker.swift
+++ b/native/apple/Sources/BaseKit/Attachments/PhoneAttachmentPicker.swift
@@ -1,6 +1,8 @@
// Copied from Equipo origin/main 8bd40ed1: native/apple/Sources/EquipoKit/Attachments/PhoneAttachmentPicker.swift
// (R5), without the recent-screenshot rows (RecentScreenshot needs Photos
-// permission, spec 7.6). Task 18 brings Base's sources and names.
+// permission, spec 7.6). Task 18: Base's sources (AttachSources), photos
+// loaded as files and staged inside the importing closure, and numbered
+// names.
#if os(iOS)
import SwiftUI
import PhotosUI
@@ -17,24 +19,27 @@ struct PhoneAttachmentPicker: View {
sources
.buttonStyle(.plain)
.accessibilityLabel(BaseText.text("native.attach.add"))
- .photosPicker(isPresented: $choosingPhotos, selection: $photos, maxSelectionCount: max(1, AttachmentLimits.maxCount - draft.items.count), matching: .images)
- .fileImporter(isPresented: $files, allowedContentTypes: [.item], allowsMultipleSelection: true) { result in
+ // matching .images: a Live Photo gives its still.
+ .photosPicker(isPresented: $choosingPhotos, selection: $photos, maxSelectionCount: max(1, AttachSources.photosLeft(chips: draft.items.count)), matching: .images)
+ .fileImporter(isPresented: $files, allowedContentTypes: AttachSources.macTypes, allowsMultipleSelection: true) { result in
if case .success(let urls) = result { for url in urls { Task { await draft.add(url: url) } } }
}
.fullScreenCover(isPresented: $camera) {
CameraAttachment { data in
camera = false
- if let data { Task { await draft.add(data: data, name: "photo.jpg") } }
+ if let data { let name = draft.nextPhotoName(); Task { await draft.add(data: data, name: name) } }
}.ignoresSafeArea()
}
.onChange(of: photos) { _, selected in
photos = []
+ // Named in the order chosen, then each loaded as a file (never
+ // as Data), staged while its URL is valid, and prepared from
+ // the staged copy behind the draft's gate.
for photo in selected {
+ let name = draft.nextPhotoName()
Task {
- await draft.add(name: "photo") {
- guard let data = try await photo.loadTransferable(type: Data.self) else { throw AttachmentFailure.type }
- return data
- }
+ guard let staged = try? await photo.loadTransferable(type: StagedPhoto.self) else { draft.refuseFile(); return }
+ await draft.add(stagedURL: staged.url, name: name, directory: staged.directory)
}
}
}
@@ -49,14 +54,16 @@ struct PhoneAttachmentPicker: View {
private var sources: some View {
Menu {
// Equipo's approved labels (Luna, 2026-11-25), drafts for Base's review.
- Button { choosingPhotos = true } label: {
- Label(BaseText.text("native.attach.photos"), systemImage: "photo")
- }
- if UIImagePickerController.isSourceTypeAvailable(.camera) {
- Button { camera = true } label: { Label(BaseText.text("native.attach.camera"), systemImage: "camera") }
+ let board = UIPasteboard.general
+ ForEach(AttachSources.menu(cameraAvailable: UIImagePickerController.isSourceTypeAvailable(.camera),
+ pasteboardHasFiles: board.hasImages || board.hasURLs), id: \.self) { source in
+ switch source {
+ case .photos: Button { choosingPhotos = true } label: { Label(BaseText.text("native.attach.photos"), systemImage: "photo") }
+ case .camera: Button { camera = true } label: { Label(BaseText.text("native.attach.camera"), systemImage: "camera") }
+ case .files: Button { files = true } label: { Label(BaseText.text("native.attach.files"), systemImage: "folder") }
+ case .paste: Button { paste() } label: { Label(BaseText.text("native.attach.paste"), systemImage: "document.on.clipboard") }
+ }
}
- Button { files = true } label: { Label(BaseText.text("native.attach.files"), systemImage: "folder") }
- Button { paste() } label: { Label(BaseText.text("native.attach.paste"), systemImage: "document.on.clipboard") }
} label: { plus }
}
private func paste() {
@@ -70,6 +77,25 @@ struct PhoneAttachmentPicker: View {
}
}
+/// A photo from the library, as a file: FileRepresentation's URL is valid
+/// only inside the importing closure, so it is staged there, into a
+/// private directory the draft then owns (P10).
+struct StagedPhoto: Transferable {
+ let url: URL
+ let directory: URL
+ static var transferRepresentation: some TransferRepresentation {
+ FileRepresentation(importedContentType: .image) { received in
+ let directory = FileManager.default.temporaryDirectory.appendingPathComponent("base-photo-" + UUID().uuidString, isDirectory: true)
+ do {
+ return StagedPhoto(url: try AttachmentFile.stage(received.file, directory: directory), directory: directory)
+ } catch {
+ try? FileManager.default.removeItem(at: directory)
+ throw error
+ }
+ }
+ }
+}
+
private struct CameraAttachment: UIViewControllerRepresentable {
let completed: (Data?) -> Void
func makeCoordinator() -> Coordinator { Coordinator(completed: completed) }
diff --git a/native/apple/Sources/BaseKit/Phone/PhoneAskScreen.swift b/native/apple/Sources/BaseKit/Phone/PhoneAskScreen.swift
index 89d8ff0..500685b 100644
--- a/native/apple/Sources/BaseKit/Phone/PhoneAskScreen.swift
+++ b/native/apple/Sources/BaseKit/Phone/PhoneAskScreen.swift
@@ -34,7 +34,7 @@ public struct PhoneAskScreen: View {
Group {
if let ask {
AskView(model: ask, layout: .phone, timeZone: me?.base.timeZone,
- actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb))
+ actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb), attaching: true)
} else {
Color.clear
}
diff --git a/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings b/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings
index 3d29cd5..1f5f114 100644
--- a/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings
+++ b/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings
@@ -721,6 +721,18 @@
}
}
},
+ "native.attach.photo": {
+ "comment": "DRAFT 2026-11-28 (slice 2 part 1, for Luna). The name given to a photo from Camera or Photos, before .jpg: Photo 1, Photo 2… in the order chosen.",
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Photo {n}"
+ }
+ }
+ }
+ },
"native.attach.photos": {
"comment": "DRAFT 2026-11-28 (slice 2 part 1, for Luna). The iPhone's + menu in Ask: choose from Photos. Equipo's approved label.",
"extractionState": "manual",
diff --git a/native/apple/Tests/BaseKitTests/AttachSourcesTests.swift b/native/apple/Tests/BaseKitTests/AttachSourcesTests.swift
new file mode 100644
index 0000000..7263c1e
--- /dev/null
+++ b/native/apple/Tests/BaseKitTests/AttachSourcesTests.swift
@@ -0,0 +1,38 @@
+@testable import BaseKit
+import Foundation
+import UniformTypeIdentifiers
+import XCTest
+
+/// Task 18: where the iPhone's files come from (P10). The logic is here;
+/// the iOS views only call it.
+@MainActor final class AttachSourcesTests: XCTestCase {
+ func testTheMenuOffersCameraAndPasteOnlyWhenThereIsOne() {
+ XCTAssertEqual(AttachSources.menu(cameraAvailable: true, pasteboardHasFiles: true), [.photos, .camera, .files, .paste])
+ XCTAssertEqual(AttachSources.menu(cameraAvailable: false, pasteboardHasFiles: true), [.photos, .files, .paste])
+ XCTAssertEqual(AttachSources.menu(cameraAvailable: true, pasteboardHasFiles: false), [.photos, .camera, .files])
+ }
+
+ func testPhotosMayFillTheRemainingPlaces() {
+ XCTAssertEqual(AttachSources.photosLeft(chips: 0), 5)
+ XCTAssertEqual(AttachSources.photosLeft(chips: 3), 2)
+ XCTAssertEqual(AttachSources.photosLeft(chips: 5), 0)
+ }
+
+ /// Numbered in the order chosen, so "Remove Photo 2.jpg" says which.
+ func testCameraAndPhotosItemsAreNumbered() {
+ let draft = AttachmentDraft(client: AttachmentServer(), announce: { _ in })
+ XCTAssertEqual((1...3).map { _ in draft.nextPhotoName() }, ["Photo 1.jpg", "Photo 2.jpg", "Photo 3.jpg"])
+ draft.clear()
+ XCTAssertEqual(draft.nextPhotoName(), "Photo 1.jpg", "a fresh message counts afresh")
+ }
+
+ /// A pasted image attaches and the field gets nothing; anything with
+ /// text is pasted as text (D8).
+ func testAPasteOfAnImageAttaches() {
+ XCTAssertTrue(AttachSources.pasteAttaches([UTType.png.identifier]))
+ XCTAssertTrue(AttachSources.pasteAttaches([UTType.jpeg.identifier, UTType.heic.identifier]))
+ XCTAssertFalse(AttachSources.pasteAttaches([UTType.png.identifier, UTType.utf8PlainText.identifier]))
+ XCTAssertFalse(AttachSources.pasteAttaches([UTType.html.identifier]))
+ XCTAssertFalse(AttachSources.pasteAttaches([]))
+ }
+}
diff --git a/native/apple/Tests/BaseSnapshots/AttachmentFixtures.swift b/native/apple/Tests/BaseSnapshots/AttachmentFixtures.swift
index ddeeb8c..f9388d6 100644
--- a/native/apple/Tests/BaseSnapshots/AttachmentFixtures.swift
+++ b/native/apple/Tests/BaseSnapshots/AttachmentFixtures.swift
@@ -72,9 +72,34 @@ import UniformTypeIdentifiers
}
/// Prepared before a catalog draws (its draft fills asynchronously).
+ /// Mockup phone-attach's chips: a photo converted from HEIC, one
+ /// uploading, and a CSV.
+ static func phoneDraft() async -> AttachmentDraft {
+ let draft = AttachmentDraft(client: FixtureAttachmentClient(), background: NoBackgroundWork(), announce: { _ in })
+ await draft.add(data: heic, name: "IMG_4021.HEIC")
+ Task { await draft.add(data: landscape, name: "IMG_4022.jpg") }
+ while !draft.items.contains(where: { if case .uploading(let p) = $0.state { return p > 0.3 }; return false }) {
+ try? await Task.sleep(for: .milliseconds(10))
+ }
+ await draft.add(data: Data("day,orders\n2025-12-22,61\n".utf8), name: "Orders.csv")
+ return draft
+ }
+
+ /// The portrait picture as a HEIC, as an iPhone's camera writes it.
+ nonisolated static var heic: Data {
+ let source = CGImageSourceCreateWithData(image as CFData, nil)!
+ let data = NSMutableData()
+ let destination = CGImageDestinationCreateWithData(data, UTType.heic.identifier as CFString, 1, nil)!
+ CGImageDestinationAddImage(destination, CGImageSourceCreateImageAtIndex(source, 0, nil)!, nil)
+ CGImageDestinationFinalize(destination)
+ return data as Data
+ }
+
static var prepared: AskModel?
+ static var preparedPhone: AskModel?
static func prepare() async {
prepared = attachingThread(text: "Use these on the website, and count last December’s orders by day", draft: await mockupDraft())
+ preparedPhone = attachingThread(text: "Use these on the website", draft: await phoneDraft())
}
/// A sent message's files: a portrait PNG and a landscape JPEG.
@@ -87,8 +112,8 @@ import UniformTypeIdentifiers
struct FixtureAttachmentClient: AttachmentClient {
func upload(_ file: AttachmentFile, progress: @escaping @Sendable (Double) -> Void) async throws -> AskAttachment {
if file.name.contains("failed") { throw BaseAPIError.offline }
- if file.name.hasPrefix("Loaves") {
- progress(0.62)
+ if file.name.hasPrefix("Loaves") || file.name.contains("4022") {
+ progress(file.name.contains("4022") ? 0.4 : 0.62)
try await Task.sleep(for: .seconds(3600))
}
return AskAttachment(id: "at_" + file.name, kind: file.mediaType.hasPrefix("image/") ? "image" : "file", name: file.name,
diff --git a/native/apple/Tests/BaseSnapshots/MacSnapshots.swift b/native/apple/Tests/BaseSnapshots/MacSnapshots.swift
index a3e4024..0784e5a 100644
--- a/native/apple/Tests/BaseSnapshots/MacSnapshots.swift
+++ b/native/apple/Tests/BaseSnapshots/MacSnapshots.swift
@@ -115,6 +115,7 @@ final class PhoneSnapshots: XCTestCase {
@MainActor func testPhone() async throws {
try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh")
BaseFonts.register()
+ await AttachmentFixtures.prepare()
await assertSnapshots(of: Self.catalog)
}
@@ -134,6 +135,12 @@ final class PhoneSnapshots: XCTestCase {
AppsSheet(me: HomeFixtures.me, home: HomeFixtures.home, team: TeamFixtures.team(), folds: HomeFixtures.folded(),
transport: nil, actions: .none) {}.skyFrozen()
},
+ // Task 18 (mockup phone-attach): the +, and the chips in one
+ // line, a photo from HEIC and one uploading. The + menu itself
+ // is the system's, which no snapshot can draw.
+ SnapshotScreen("ask-attach", mac: nil, iphone: .fixed(width: 402, height: 874)) {
+ PhoneAskScreen(me: HomeFixtures.me, home: HomeFixtures.home, ask: AttachmentFixtures.preparedPhone, transport: nil, actions: .none).skyFrozen()
+ },
SnapshotScreen("job", mac: nil, iphone: .fixed(width: 402, height: 437)) {
JobView(job: AskFixtures.job, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now)
},
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-dark-default.png
index 31c3439..01e91b4 100644
Binary files a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-dark-default.png and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-dark-default.png differ
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-light-default.png
index 508acb1..81dc832 100644
Binary files a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-light-default.png and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-mac/mac/window-attach-light-default.png differ
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-ax3.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-ax3.png
new file mode 100644
index 0000000..934d210
Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-ax3.png differ
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-default.png
new file mode 100644
index 0000000..2fe213a
Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-dark-default.png differ
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-ax3.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-ax3.png
new file mode 100644
index 0000000..8049d21
Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-ax3.png differ
diff --git a/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-default.png b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-default.png
new file mode 100644
index 0000000..1dfe16f
Binary files /dev/null and b/native/apple/Tests/BaseSnapshots/__Snapshots__/base-phone/iphone/ask-attach-light-default.png differ
diff --git a/native/ios/project.yml b/native/ios/project.yml
index 09bef42..b9ee61b 100644
--- a/native/ios/project.yml
+++ b/native/ios/project.yml
@@ -47,6 +47,9 @@ targets:
INFOPLIST_KEY_UISupportedInterfaceOrientations: UIInterfaceOrientationPortrait
# HTTPS only, through the system: exempt from export documentation.
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption: false
+ # Ask's + menu, Camera (slice 2 Task 18). DRAFT 2026-11-28, for Luna:
+ # copy-review/slice2-part1.json, ios.NSCameraUsageDescription.
+ INFOPLIST_KEY_NSCameraUsageDescription: Base uses the camera to take a photo for Ask.
info:
path: Info.plist
properties: