-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Is your feature request related to a problem? Please describe.
Currently, react-native-enriched does not support inserting images or GIFs directly from the keyboard (like Gboard on Android or the native keyboard on iOS 14+). When users try to insert an image from their keyboard, nothing happens. This is frustrating because:
- Modern keyboards (Gboard, SwiftKey, iOS native keyboard) provide built-in image/GIF pickers
- Users expect this functionality to work in rich text inputs
- It's a standard feature in most modern messaging and social apps
- Copy-pasting images from the clipboard also doesn't work
Describe the solution you'd like
I would like react-native-enriched to support the Commit Content API (Android) and UIPasteboard image handling (iOS) to allow users to:
- Insert images from keyboard: When users select an image/GIF from their keyboard (Gboard, iOS keyboard, etc.), the component should receive the image data
- Paste images from clipboard: When users copy an image and paste it into the input, it should be captured
- Provide a callback: Add an
onImageInsertedoronRichContentInsertedcallback that provides:- The image URI/path
- MIME type (image/png, image/jpeg, image/gif, etc.)
- Metadata if available
Example API:
<EnrichedTextInput
onRichContentInserted={(content) => {
console.log('URI:', content.uri);
console.log('Type:', content.mimeType);
// Handle image upload
}}
/>Describe alternatives you've considered
-
Custom patch (current workaround): I've created a patch that implements this for Android using
InputConnectionCompat.OnCommitContentListenerand iOS usingUIPasteboard, but it would be better to have official support. -
Separate image picker button: While we can add a button to open the image picker, this doesn't provide the seamless UX that keyboard-based image insertion offers.
-
Using a different library: Other libraries don't provide the rich HTML formatting features that
react-native-enrichedoffers.
Technical Implementation Suggestions
Android (API 25+):
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
val ic = super.onCreateInputConnection(outAttrs)
EditorInfoCompat.setContentMimeTypes(outAttrs, arrayOf("image/*"))
return InputConnectionCompat.createWrapper(ic, outAttrs) { inputContentInfo, flags, _ ->
// Handle the image content
val uri = inputContentInfo.contentUri.toString()
val mimeType = inputContentInfo.description.getMimeType(0)
// Emit event to React Native
true
}
}iOS (14.0+):
- (void)paste:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if (pasteboard.image != nil) {
// Save image to temp directory
// Emit event to React Native
return;
}
// Fall back to text paste
[super paste:sender];
}Related Issues/Discussions
- React Native's TextInput doesn't support this natively: [Android] Add support to TextInput for Image Keyboards facebook/react-native#26088
- Many users expect this in modern rich text editors
Use Cases
- Messaging apps
- Social media post creation
- Comment systems
- Note-taking apps
- Any app with rich text input
Platform Support
- Android: API 25+ (Commit Content API)
- iOS: iOS 14+ (improved keyboard with image picker)
This feature would significantly improve the UX and make react-native-enriched more competitive with other rich text solutions. I'm happy to contribute to the implementation if you're open to this feature!