Skip to content

[Feature Request] Support keyboard image/GIF insertion (Gboard, iOS keyboard, etc.) #212

@shuo-hiwintech

Description

@shuo-hiwintech

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:

  1. Insert images from keyboard: When users select an image/GIF from their keyboard (Gboard, iOS keyboard, etc.), the component should receive the image data
  2. Paste images from clipboard: When users copy an image and paste it into the input, it should be captured
  3. Provide a callback: Add an onImageInserted or onRichContentInserted callback 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

  1. Custom patch (current workaround): I've created a patch that implements this for Android using InputConnectionCompat.OnCommitContentListener and iOS using UIPasteboard, but it would be better to have official support.

  2. 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.

  3. Using a different library: Other libraries don't provide the rich HTML formatting features that react-native-enriched offers.

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

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions