The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): pasted GIFs on iOS keep their animation (#37143)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 15, 2026 at 12:07 UTC
0afd8c0295d6dafce602bc808ec123baf37c6dc1
4 files changed
+53
-16
apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift
+25
-11
@@ -1,5 +1,6 @@
1
import ExpoModulesCore
2
import UIKit
3
+import UniformTypeIdentifiers
4
5
private struct ComposerTokenPayload: Decodable, Equatable {
6
let type: String
@@ -309,18 +310,28 @@ private final class ComposerTextView: UITextView {
310
func loadImages(from providers: [NSItemProvider]) {
311
let group = DispatchGroup()
312
let lock = NSLock()
312
- var images = [UIImage?](repeating: nil, count: providers.count)
313
+ var images = [(data: Data, fileExtension: String)?](repeating: nil, count: providers.count)
314
315
for (index, provider) in providers.enumerated() {
316
group.enter()
316
- provider.loadObject(ofClass: UIImage.self) { object, _ in
317
- defer { group.leave() }
318
- guard let image = object as? UIImage else {
319
- return
320
- }
317
+ let store = { (image: (data: Data, fileExtension: String)?) in
318
lock.lock()
319
images[index] = image
320
lock.unlock()
321
+ group.leave()
322
+ }
323
+ let loadPNG = {
324
+ _ = provider.loadObject(ofClass: UIImage.self) { object, _ in
325
+ store((object as? UIImage)?.pngData().map { ($0, "png") })
326
+ }
327
+ }
328
+ // Decoding a GIF to UIImage keeps only its first frame, so pass its bytes through.
329
+ if provider.hasItemConformingToTypeIdentifier(UTType.gif.identifier) {
330
+ _ = provider.loadDataRepresentation(forTypeIdentifier: UTType.gif.identifier) { data, _ in
331
+ if let data { store((data, "gif")) } else { loadPNG() }
332
+ }
333
+ } else {
334
+ loadPNG()
335
}
336
}
337
@@ -328,7 +339,9 @@ private final class ComposerTextView: UITextView {
339
guard let self, !self.isReadOnly else {
340
return
341
}
331
- let urls = images.compactMap { $0 }.compactMap(Self.writeTemporaryImage)
342
+ let urls = images.compactMap { $0 }.compactMap {
343
+ Self.writeTemporaryImage($0.data, fileExtension: $0.fileExtension)
344
+ }
345
if !urls.isEmpty {
346
self.onPasteImages?(urls)
347
}
@@ -408,9 +421,10 @@ private final class ComposerTextView: UITextView {
421
}
422
423
private static func writeTemporaryImage(_ image: UIImage) -> String? {
411
- guard let data = image.pngData() else {
412
- return nil
413
- }
424
+ image.pngData().flatMap { writeTemporaryImage($0, fileExtension: "png") }
425
+ }
426
+
427
+ private static func writeTemporaryImage(_ data: Data, fileExtension: String) -> String? {
428
let directory = FileManager.default.temporaryDirectory
429
.appendingPathComponent(pastedImageDirectoryName, isDirectory: true)
430
do {
@@ -419,7 +433,7 @@ private final class ComposerTextView: UITextView {
433
withIntermediateDirectories: true
434
)
435
removeStaleTemporaryImages(in: directory)
422
- let url = directory.appendingPathComponent("\(UUID().uuidString).png")
436
+ let url = directory.appendingPathComponent("\(UUID().uuidString).\(fileExtension)")
437
try data.write(to: url, options: .atomic)
438
return url.absoluteString
439
} catch {
apps/mobile/modules/t3-composer-editor/tests/ios/main.swift
+21
-1
@@ -212,6 +212,25 @@ for readOnly in [true, false] {
212
check(provider.loadCount == 0, "Locked inputs must not load pasted image providers")
213
}
214
215
+// Two-frame animated GIF: a mixed paste keeps the GIF's original bytes and the still image's PNG, in order.
216
+private let gifBytes = Data(base64Encoded: "R0lGODlhAQABAIEAAP8AAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQACgAAACwAAAAAAQABAAAIBAABBAQAIfkEAAoAAAAsAAAAAAEAAQCBAP8AAAAAAAAAAAAACAQAAQQEADs=")!
217
+private let gifProvider = NSItemProvider()
218
+gifProvider.registerDataRepresentation(forTypeIdentifier: UTType.gif.identifier, visibility: .all) { completion in
219
+ completion(gifBytes, nil)
220
+ return nil
221
+}
222
+private let gifEditor = ComposerTextView()
223
+gifEditor.onPasteImages = { urls in
224
+ let files = urls.compactMap(URL.init(string:))
225
+ let contents = files.compactMap { try? Data(contentsOf: $0) }
226
+ files.forEach { try? FileManager.default.removeItem(at: $0) }
227
+ check(files.map(\.pathExtension) == ["gif", "png"], "A mixed paste must keep each image's format, in order: \(urls)")
228
+ check(contents.first == gifBytes, "A pasted animated GIF must keep its original bytes")
229
+ check(contents.count == 2 && contents[1] == image.pngData(), "The still image beside a GIF must still attach as PNG")
230
+ print("Composer GIF-paste checks passed")
231
+ exit(0)
232
+}
233
+
234
// Inline provider completion places the attachment callback before this main-queue check.
235
DispatchQueue.main.async {
236
check(pastedImages.count == 1, "An accepted provider-based paste must emit exactly one attachment batch")
@@ -228,6 +247,7 @@ DispatchQueue.main.async {
247
"The attachment must contain the pasted image's pixels")
248
check(pasteEditor.text == "Keep this draft", "Image paste must preserve the draft text")
249
print("Composer provider-paste checks passed")
231
- exit(0)
250
+ check(gifProvider.canLoadObject(ofClass: UIImage.self), "A GIF provider must take the image paste path")
251
+ gifEditor.paste(itemProviders: [gifProvider, ImmediateImageProvider(image: image)])
252
}
253
dispatchMain()
apps/mobile/src/lib/composerImages.test.ts
+6
-1
@@ -199,10 +199,13 @@ describe("native pasted image cleanup", () => {
199
it("converts owned files to data-backed previews and deletes the source", async () => {
200
const uri =
201
"file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/id.png";
202
+ const gif =
203
+ "file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/anim.gif";
204
files.set(uri, { base64: "aGVsbG8=", deleted: false });
205
+ files.set(gif, { base64: "R0lGODlh", deleted: false });
206
207
const { attachments } = await convertPastedImagesToAttachments({
205
- uris: [uri],
208
+ uris: [uri, gif],
209
existingCount: 0,
210
});
211
@@ -211,8 +214,10 @@ describe("native pasted image cleanup", () => {
214
dataUrl: "data:image/png;base64,aGVsbG8=",
215
previewUri: "data:image/png;base64,aGVsbG8=",
216
}),
217
+ expect.objectContaining({ mimeType: "image/gif", dataUrl: "data:image/gif;base64,R0lGODlh" }),
218
]);
219
expect(files.get(uri)?.deleted).toBe(true);
220
+ expect(files.get(gif)?.deleted).toBe(true);
221
});
222
223
it("deletes rejected and overflow owned files without deleting user-owned files", async () => {
apps/mobile/src/lib/composerImages.ts
+1
-3
@@ -561,9 +561,7 @@ function isOwnedPastedImageUri(uri: string): boolean {
561
return false;
562
}
563
const segments = url.pathname.split("/").filter(Boolean);
564
- return (
565
- segments.at(-2) === OWNED_PASTED_IMAGE_DIRECTORY && segments.at(-1)?.endsWith(".png") === true
566
- );
564
+ return segments.at(-2) === OWNED_PASTED_IMAGE_DIRECTORY;
565
} catch {
566
return false;
567
}