Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add contentInsertionConfiguration to editor and text input service #691

Merged

Conversation

stevenosse
Copy link
Contributor

@stevenosse stevenosse commented Jan 25, 2024

Description

This PR Adds support for contentInsertionConfiguration attribute that allows the usage of Android's image keyboard to Flutter.

See: https://api.flutter.dev/flutter/material/TextField/contentInsertionConfiguration.html

Impact

This will allow the handling of more complex clipboard contents pastes (like images), or insertion of gifs and stickers

Linked issue: #646

@CLAassistant
Copy link

CLAassistant commented Jan 25, 2024

CLA assistant check
All committers have signed the CLA.

@stevenosse stevenosse force-pushed the feature/content-insertion-configuration branch from 1158589 to a0a8ebf Compare January 25, 2024 09:06
@stevenosse stevenosse marked this pull request as ready for review January 25, 2024 09:24
Comment on lines 242 to 244
allowedMimeTypes: widget.contentInsertionConfiguration == null
? const <String>[]
: widget.contentInsertionConfiguration!.allowedMimeTypes,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allowedMimeTypes: widget.contentInsertionConfiguration == null
? const <String>[]
: widget.contentInsertionConfiguration!.allowedMimeTypes,
allowedMimeTypes:
widget.contentInsertionConfiguration?.allowedMimeTypes ?? [],

@@ -43,6 +43,7 @@ dependencies:
highlight: ^0.7.0
http: ^1.1.0
show_fps: ^1.0.6
path: ^1.8.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it because of the "depend_on_referenced_packages" lint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@LucasXu0
Copy link
Collaborator

Hi, @stevenosse. Thanks for contributing. Have you tried using the contentInsertionConfiguration in your application, or could you share a more specific use case?

@stevenosse
Copy link
Contributor Author

Hi, @stevenosse. Thanks for contributing. Have you tried using the contentInsertionConfiguration in your application, or could you share a more specific use case?

Here is how it looks like:

screen-20240128-212248.1.online-video-cutter.com.mp4

On some Xiaomi devices, when a user takes a screenshot, it's added to their clipboard (on WhatsApp, they can select that image from their clipboard and it's sent as an image).
On my app, i want users to be able to add images from their clipboard to a note

@LucasXu0
Copy link
Collaborator

@stevenosse Nice inspiration. Could you also share your code sample for implementing the 'insert image from clipboard' feature here, so that other developers can refer to it?

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3cd5602) 76.46% compared to head (87a7cb7) 76.48%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #691      +/-   ##
==========================================
+ Coverage   76.46%   76.48%   +0.02%     
==========================================
  Files         295      295              
  Lines       13094    13315     +221     
==========================================
+ Hits        10012    10184     +172     
- Misses       3082     3131      +49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LucasXu0 LucasXu0 merged commit 0d8f755 into AppFlowy-IO:main Jan 30, 2024
10 of 11 checks passed
@stevenosse
Copy link
Contributor Author

@stevenosse Nice inspiration. Could you also share your code sample for implementing the 'insert image from clipboard' feature here, so that other developers can refer to it?

Sure !
Here is the sample code:

AppFlowyEditor(
  editorStyle: editorStyle,
  editorState: editorState,
  editorScrollController: editorScrollController,
  blockComponentBuilders: blockComponentBuilders,
  showMagnifier: true,
  // showcase 3: customize the header and footer.
  header: Padding(
    padding: const EdgeInsets.only(bottom: 10.0),
    child: Image.asset(
      'assets/images/header.png',
    ),
  ),
  footer: const SizedBox(
    height: 100,
  ),
  /// Usage of content insertion configuration
  contentInsertionConfiguration: ContentInsertionConfiguration(
    allowedMimeTypes: ['image/gif', 'image/png'],
    onContentInserted: (content) async {
      if (content.data != null) {
        final tmpDir = await getTemporaryDirectory();
        final filename = path.basename(content.uri);
        final file = File('${tmpDir.path}/$filename');

        await file.writeAsBytes(content.data!);
        editorState.insertImageNode(file.path);
      }
    },
  ),
),

@stevenosse stevenosse deleted the feature/content-insertion-configuration branch January 30, 2024 10:32
q200892907 added a commit to q200892907/appflowy-editor that referenced this pull request Jan 31, 2024
* main:
  chore: bump version 2.3.1 (AppFlowy-IO#697)
  feat: add contentInsertionConfiguration to editor and text input service (AppFlowy-IO#691)
  fix: add support for breakline and divider (AppFlowy-IO#690)
  chore: translate commands (AppFlowy-IO#687)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants