feat(mobile): all-native SwiftUI attachments sheet

Merged
SA
3mo ago
+820-585

Stacked on #6660 — the diff here is one commit; review after (or alongside) that PR. GitHub will retarget to main when it merges.

Summary

  • Replaces the attachments formSheet route with a local expo module (modules/attachments-sheet): a system UISheetPresentationController at medium/large detents hosting all-SwiftUI content — recent-photos carousel, Photos/Screenshots/Camera/Files rows, an in-sheet screenshots grid, ordered multi-select, and native JPEG export.
  • Deletes the route, its screens/stores, useAfterTransitionEnd, and the expo-media-library + expo-image-manipulator dependencies.

Why / Context

The attachments sheet was our glitchiest surface: expo-image views painting at corrupted native frames during presentation (SUPER-1199), flex children collapsing to zero height on cold mount, and a hand-tuned GRID_HEIGHT_FRACTION + collapsable={false} + single locked [0.5] detent to keep it all hidden. The root cause is structural — a native sheet container resizing while a different layout engine (Yoga) lays out its content. Putting the content on the same side of the seam as the container removes the whole bug class: the sheet now drags half↔full with system physics and scroll-to-expand handoff, which the RN-content version could never allow.

How It Works

  • AttachmentsSheetModule.present() presents a UIHostingController as a page sheet (.medium()/.large(), grabber) from the current view controller. Theme colors cross as processColor ints; overrideUserInterfaceStyle follows the app theme.
  • Every presentation ends in exactly one event back to JS: onAddAssets (selection exported), onAction (photos/camera/files), or onDismiss (swipe). JS listeners tear down on whichever fires.
  • Row actions are sent in the native dismiss completion, replacing the transitionEnd dance (which #6660 found broken — Fabric drops events from unmounted screens). Pickers present after the sheet is fully gone.
  • The screenshots grid fetches by .smartAlbumScreenshots subtype — the old album.title === "Screenshots" match only worked on English-language devices.
  • Export re-encodes through UIImage → jpegData(0.8), which both fixes the agent API's HEIC rejection and strips EXIF/GPS — same privacy behavior #6660 established for the picker paths.
  • The composer hook (useAttachmentsSheet under GlassComposer) routes onAction to the existing picker flows, including #6660's transcode-failure filtering on the camera path.
  • Stale dev clients (requireOptionalNativeModule → null) no-op with a console warning instead of crashing.

Manual QA Checklist

Verified on simulators (fresh device + the shared 16e, dev sign-in):

  • Sheet presents at medium detent with grabber, inline title, close button; cold mount renders fully
  • Permission card → request → carousel populates (pre-granted and prompt paths)
  • Ordered selection badges; Add bar appears and persists across the in-sheet push
  • Screenshots push with back chevron; empty state when the library has no screenshots
  • Medium→large detent expansion with content intact
  • Add → JPEG export → sheet dismisses → attachment lands in the composer with remove button
  • Photos row → sheet dismisses → system picker presents (with #6660's accent theming)
  • Camera row on simulator → "Camera is not available" alert (no camera to test further)

Needs a real device (simulators can't produce screenshot-subtype assets or camera captures):

  • Screenshots grid populated with real screenshots; scroll-to-expand feel
  • Camera capture attaches
  • Opening the sheet mid-typing (automation can't reach the + while the composer is expanded — no mechanism for a finger tap to differ, but unconfirmed)

Testing

  • bun run typecheck — clean on all touched files (remaining errors match the pre-existing baseline without turbo-built workspace types)
  • biome check on all changed files
  • xcodebuild — module pod and full app target build for simulator; module registered in ExpoModulesProvider for both targets

Design Decisions

  • All-native content, not a JS-driven sheet: a JS sheet approximates detent physics, scroll-to-expand handoff, and presenting-view pushback; the system container gets them exactly, and it is the same container every other sheet in the app already uses, so chrome consistency is automatic. Mixed engines (native container + RN content) is the one combination with the documented bug class.
  • Not the stock filtered photo picker: an in-app sheet with carousel + rows + inline grid was the product bar; PHPickerViewController caps at stock-picker UX.
  • requireOptionalNativeModule so a stale dev client degrades to a warning rather than a launch crash.

Known Limitations

  • Requires a dev-client rebuild (two new native modules across this stack).
  • The expo-modules-core 56.0.23 NativeModule TS type alias is broken upstream (constructor type, generic dropped), so the module's event surface is typed by hand in src/index.ts.

Follow-ups

  • If this holds up, the sessions sheet is the next candidate for the same treatment.

Summary by cubic

Replaces the RN attachments formSheet with a native SwiftUI sheet (UISheetPresentationController, medium/large) via @superset/attachments-sheet to fix layout corruption and match system sheet physics. Assets export as JPEG to avoid HEIC rejections and strip EXIF/GPS.

  • Emits exactly one event per presentation: onAddAssets, onAction (photos/camera/files), or onDismiss; row actions fire after native dismiss so follow-up pickers present reliably.
  • Screenshots grid loads by .smartAlbumScreenshots subtype.
  • GlassComposer opens the sheet via useAttachmentsSheet; removes the attachments route, screens, and selection store.
  • Adds a local module at apps/mobile/modules/attachments-sheet; wires @superset/attachments-sheet in Metro and TS config.
  • Removes expo-media-library and its plugin config; stale dev clients no-op with a console warning — rebuild the dev client.

Summary by CodeRabbit

  • New Features

    • Added a native attachments sheet for selecting recent photos and screenshots.
    • Added options for camera capture and file selection.
    • Added support for light and dark themes, permission prompts, asset previews, and multi-item selection.
    • Selected images are added directly to the message composer.
  • Improvements

    • Replaced the previous attachments navigation flow with an integrated sheet experience.
    • Removed the separate attachments and screenshots screens.