Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(swift-ios): paste images from the composer's native menu #7607

Mergedmackinleysmith(GitHub profile, opens in a new tab)merged 7 commits intot3code/rebuild-mobile-app-swift fromrefs/pull/7607/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

What Changed

The composer's text entry is now a UIKit UITextView behind a small UIViewRepresentable (FeatureComposerTextInput) instead of a SwiftUI TextField.

That makes image paste work. The text view advertises image support through UIPasteConfiguration, so an image on the pasteboard gets a real Paste item in the long-press menu. Pasted images run through the same preparation pipeline as the attachment picker, count against the same 8-image cap, and block sending until processing finishes. Text-only pastes stay on the system path. Text that rides along with a copied image (usually its URL) is dropped on purpose, which is what Slack and X do.

The input grows to a 12-line cap and scrolls internally past it instead of growing without limit, matching Messages and Slack.

Focus handling changes with it. SwiftUI drops writes to a FocusState that no .focused() view registers with, and a representable can't register one, so the hosts now hold plain Bool state and the UIKit responder state is the source of truth. The thread view's swipe-to-dismiss-keyboard moves into the text view as an observing pan recognizer, because drags that start inside a UITextView never reach a SwiftUI gesture. Dismissal only fires for a downward drag that begins with the draft scrolled to its top; scrolling back through a long draft never drops the keyboard.

Smaller pieces: command completion (/, @, $) places the caret right after the inserted text using UTF-16 indices, restored drafts put the caret at the end, and the attachment strip gets a little padding before its divider.

This builds on the approach @saphid validated in #5610. It adapts that design onto the current base at about a third of the size, reusing the picker's preparation-state pattern instead of the lifecycle and queue machinery.

Why

SwiftUI text inputs have no paste hook on iOS (onPasteCommand is macOS-only), so the long-press menu can never offer Paste for an image and screenshots can't be attached from the clipboard. Discussed with @t3dotgg on X, who green-lit the refactor ("go nuts - send me the PR when you get it in a good state").

UI Changes

Before: long-press with an image on the pasteboard offers no Paste.

After: Paste appears and the image lands in the attachment strip.

A long draft caps at 12 lines and scrolls inside:

Paste interaction video:

Verification

  • Full native suite (Scripts/ci-test.sh): 291 tests in 32 suites passed, exit 0. Adds 10 focused tests covering UTF-16 caret policies, the sizing cap, paste-menu advertisement, HEIC pasteboard detection through UTType conformance, the drag-dismiss policy, and item-provider loading.
  • Verified live against a disposable backend on an iPhone 17 Pro simulator: paste from the native menu (the image reached the provider, which described the screenshot back), text paste fallback, /model completion and caret placement, draft persistence across an app relaunch and a round-trip with the previous build, collapse and expand in both hosts, the working-state placeholder, cap-then-scroll, and drag-to-dismiss for short drafts and for long drafts from the top.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Built with Claude Fable 5 via Claude Code.


Note

Medium Risk Touches composer focus, keyboard dismiss, and image attachment on the main chat input. UIKit bridging can regress caret, paste, and keyboard behavior if the representable sync is wrong.

Overview Lets iOS users paste images from the composer’s native edit menu by swapping the SwiftUI TextField for a UITextView representable.

Pasted images go through the same attachment pipeline and 8-image cap as the picker. Text-only pastes stay native; accompanying URLs on image copies are dropped. The field grows to 12 lines then scrolls inside.

Focus is now a plain Bool binding (UIKit owns first responder). Keyboard dismiss is an observing pan on the text view that only fires for a downward drag that starts at the top of a scrollable draft. Command completion and restored drafts place the caret with UTF-16-aware policy. Failure alerts refocus after dismiss.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1aef7e8f4cca5c22632e7725272e6405ed5c459e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add native image paste from composer menu in Swift iOS app

  • Replaces the SwiftUI TextField in the chat composer with a UITextView bridge (FeatureComposerTextInput) so the native edit menu can advertise and handle image paste.
  • Routed pasted images through the existing attachment pipeline in loadPastedImages, enforcing a shared 8-image cap via FeatureImageAttachmentLimits.maximumCount and surfacing load or limit errors in an alert.
  • Switches focus control from @FocusState to a plain Bool binding mirrored from UIKit's first responder, and moves keyboard-dismiss drag logic into the text view itself.
  • Adds UTF-16-aware caret placement (FeatureComposerTextSelectionPolicy) and a one-shot FeatureComposerTextSelectionRequest so command completion can position the cursor after inserted text.
  • Composer input grows to at most 12 lines (FeatureComposerTextInputSizing.maximumLines) before scrolling internally.
  • Behavioral Change: ThreadDetailView and NewThreadView now restore focus on the send-failed alert's OK button rather than immediately before the alert; ThreadDetailView no longer uses a local SwiftUI drag gesture for keyboard dismissal.
Macroscope summarized 1aef7e8.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: f997c85b-d1e8-4b97-9566-3256e4f25472

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR introduces a new user-facing feature (image paste from native iOS menu) with a new 382-line UIKit component and changes to focus management architecture. New features introducing user-facing behavior warrant human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ee880999f4ac2fe5509a0fce62c321e15c692763. Configure [here](https://www.cursor.com/dashboard/bugbot).

Sign in to join this conversation.