fix(mobile): accept Android clipboard images in composer - #4833
fix(mobile): accept Android clipboard images in composer#4833adityavardhansharma wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
| ViewCompat.setOnReceiveContentListener(this, SUPPORTED_IMAGE_MIME_TYPES) { _, payload -> | ||
| val cachedImageUris = cacheReceivedImages(payload) | ||
| if (cachedImageUris.isEmpty()) { | ||
| payload | ||
| } else { | ||
| pasteImagesListener?.invoke(cachedImageUris) | ||
| null | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 Medium t3composereditor/T3ComposerEditorView.kt:463
The receive-content listener returns null as soon as it caches at least one image, marking the entire payload as consumed. When a payload contains an image alongside text, unsupported items, or additional images that failed to cache, those remaining items are silently discarded instead of being returned to the platform for default handling. Consider partitioning the payload via payload.partition(...) and returning the unconsumed portion instead of null.
- val cachedImageUris = cacheReceivedImages(payload)
- if (cachedImageUris.isEmpty()) {
- payload
- } else {
- pasteImagesListener?.invoke(cachedImageUris)
- null
- }
+ val (imagePayload, remainder) = payload.partition { item ->
+ val uri = item.uri
+ if (uri == null) return@partition false
+ val mimeType = context.contentResolver.getType(uri)?.lowercase()
+ mimeType != null && fileExtensionForImageMimeType(mimeType) != null
+ }
+ val cachedImageUris = cacheReceivedImages(imagePayload)
+ if (cachedImageUris.isNotEmpty()) {
+ pasteImagesListener?.invoke(cachedImageUris)
+ }
+ remainder🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt around lines 463-471:
The receive-content listener returns `null` as soon as it caches at least one image, marking the entire payload as consumed. When a payload contains an image alongside text, unsupported items, or additional images that failed to cache, those remaining items are silently discarded instead of being returned to the platform for default handling. Consider partitioning the payload via `payload.partition(...)` and returning the unconsumed portion instead of `null`.
|
Closing this draft to replace it with a corrected PR from current main. |
What Changed
Add Android rich-content handling to the native composer editor so images selected from the keyboard's clipboard history are attached to the draft.
Received images are copied into the composer's owned temporary directory and then passed through the existing attachment conversion, size validation, and cleanup path. Existing text paste behavior and the
+image picker flow are unchanged.Why
The Android editor already handled image URIs from the long-press Paste action, but keyboard clipboard-history images arrive through the IME
commitContent/receive-content API instead ofonTextContextMenuItem. Because the editor did not advertise or receive rich image content, Android reported those clipboard images as unsupported.Using AndroidX receive-content support covers the IME path while keeping all attachment processing in the established composer pipeline.
Checklist
Validation
node scripts/mobile-native-static-check.tsvp run typecheckfromapps/mobilegit diff --checkNote
Accept Android clipboard images in the mobile composer editor
ViewCompat.setOnReceiveContentListenertoSelectionAwareEditTextin T3ComposerEditorView.kt that intercepts image content (JPEG, PNG, GIF, WebP) pasted from IMEs or drag-and-drop.t3-composer-paste) with UUID-based filenames, then passed topasteImagesListeneras file URIs.InputConnectionwithInputConnectionCompat.createWrapperinonCreateInputConnectionto enable rich content input compatibility on older Android versions.📊 Macroscope summarized e86f3bf. 1 file reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.