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

compose: Support images from keyboard for Android #1203

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Dec 24, 2024

Preview error message

image

Fixes: #419
Fixes: #1173

@PIG208 PIG208 force-pushed the pr-keyboard branch 3 times, most recently from 89446ec to af8c5b3 Compare December 24, 2024 21:19
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Exciting! Small question from a quick skim; I know this is still a draft.

Comment on lines 368 to 377
// The data can be empty when the URL is associated with an empty
// resource. See Flutter engine implementation that provides this data:
// https://github.com/flutter/flutter/blob/0ffc4ce00ea7bb912e379adf39354644eab2c17e/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java#L497-L548
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is specifically about the case where data ends up being present as an empty array, right? In the code you linked to, I assume that specifically means readStreamFully came up empty in line 531:

https://github.com/flutter/flutter/blob/0ffc4ce00/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java#L531

final byte[] data = this.readStreamFully(is, 64 * 1024);

(Right?)

How about a different case: what could cause data to be null as opposed to present-but-empty? I noticed KeyboardInsertedContent.data is optional. This would be helpful to document upstream there. 🙂

Also, looking around the whole commitContent function you linked to, it looks like there are various unhappy paths there, where the function can't do something desirable and returns false. Like if the Android version is too old. What's the user-facing behavior in those unhappy paths?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having swept through the Java code, I couldn't find other places where data is null and gets passed via a textInputChannel.commitContent call. The link points to the only current non-test call site. The Dart code constructor doesn't have code paths where data is explicitly null either.

data can be empty if (a) the file is empty or (b) there was an IOException during the read. So data should probably be null if there is an error reading it, so that we can handle it properly.


When returning false, no textInputChannel.commitContent call is made and our handler does not get called at all. But the return value is probably read by some part of the Android SDK code: https://developer.android.com/reference/android/view/inputmethod/BaseInputConnection

Default implementation which invokes View.performReceiveContent on the target view if the view allows content insertion; otherwise returns false without any side effects.

true if this request is accepted by the application, whether the request is already handled or still being handled in background, false otherwise.

I assume the behavior is akin to when we do not provide ContentInsertionConfiguration at all. That also results in this method returning false because the allowedMimeTypes default to an empty list. This gives you an OS-specific error message:
image

@PIG208 PIG208 marked this pull request as ready for review December 26, 2024 22:06
@PIG208 PIG208 added the maintainer review PR ready for review by Zulip maintainers label Dec 26, 2024
PIG208 added 3 commits January 6, 2025 14:26
So the test is more realistic.  A side effect of this is that the
content input text field is focused afterwards.

Signed-off-by: Zixuan James Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paste an image into the compose box, on Android android: Support images from keyboard
2 participants