-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: binary content appears in composer when pasting image #60501
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
Merged
Beamanator
merged 6 commits into
Expensify:main
from
rohit9625:fix/android-onpaste-behavior
Apr 24, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fac5b14
fix: binary content appears in composer when pasting image
rohit9625 8b29a7a
Merge branch 'Expensify:main' into fix/android-onpaste-behavior
rohit9625 277110d
Revert "fix: binary content appears in composer when pasting image"
rohit9625 8e45337
refactor: update onPaste patch to return early when pasting file
rohit9625 2c89910
refactor: remove unwanted changes from the onPaste patch fix
rohit9625 a80110a
refactor: rewrite to return early regardless of the paste watcher
rohit9625 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -445,7 +445,7 @@ index 0000000..bfb5819 | |
| + public void onPaste(String type, String data); | ||
| +} | ||
| diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java | ||
| index 56a1069..272ea7d 100644 | ||
| index 56a1069..9f14425 100644 | ||
| --- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java | ||
| +++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java | ||
| @@ -9,6 +9,10 @@ package com.facebook.react.views.textinput; | ||
|
|
@@ -483,38 +483,47 @@ index 56a1069..272ea7d 100644 | |
| mTextAttributes = new TextAttributes(); | ||
|
|
||
| applyTextAttributes(); | ||
| @@ -332,8 +339,29 @@ public class ReactEditText extends AppCompatEditText { | ||
| @@ -332,8 +339,38 @@ public class ReactEditText extends AppCompatEditText { | ||
| */ | ||
| @Override | ||
| public boolean onTextContextMenuItem(int id) { | ||
| - if (id == android.R.id.paste) { | ||
| + if (id == android.R.id.paste || id == android.R.id.pasteAsPlainText) { | ||
| id = android.R.id.pasteAsPlainText; | ||
| + if (mPasteWatcher != null) { | ||
| + ClipboardManager clipboardManager = | ||
| + | ||
| + ClipboardManager clipboardManager = | ||
| + (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); | ||
| + ClipData clipData = clipboardManager.getPrimaryClip(); | ||
| + ClipData clipData = clipboardManager.getPrimaryClip(); | ||
| + if (clipData != null) { | ||
| + ClipData.Item item = clipData.getItemAt(0); | ||
| + Uri itemUri = item.getUri(); | ||
| + String type = null; | ||
| + String data = null; | ||
| + | ||
| + if (itemUri != null) { | ||
| + ContentResolver cr = getReactContext(this).getContentResolver(); | ||
| + type = cr.getType(itemUri); | ||
| + data = itemUri.toString(); | ||
| + if (mPasteWatcher != null) { | ||
| + mPasteWatcher.onPaste(type, data); | ||
| + } | ||
| + // Prevents default behavior to avoid inserting raw binary data into the text field | ||
| + return true; | ||
| + } | ||
| + | ||
| + if (clipData.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { | ||
| + type = ClipDescription.MIMETYPE_TEXT_PLAIN; | ||
| + data = clipData.getItemAt(0).getText().toString(); | ||
| + } else { | ||
| + Uri itemUri = clipData.getItemAt(0).getUri(); | ||
| + if (itemUri != null) { | ||
| + ContentResolver cr = getReactContext(this).getContentResolver(); | ||
| + type = cr.getType(itemUri); | ||
| + data = itemUri.toString(); | ||
| + data = item.getText().toString(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from #66749 checklist: we missed checking if item.getText() is null, so we need to add a null check before retrieving the string. |
||
| + if (mPasteWatcher != null) { | ||
| + mPasteWatcher.onPaste(type, data); | ||
| + } | ||
| + } | ||
| + if (type != null && data != null) { | ||
| + mPasteWatcher.onPaste(type, data); | ||
| + // Don't return - let the system proceed with default text pasting behavior | ||
| + } | ||
| + } | ||
| } | ||
| return super.onTextContextMenuItem(id); | ||
| } | ||
| @@ -395,6 +423,10 @@ public class ReactEditText extends AppCompatEditText { | ||
| @@ -395,6 +432,10 @@ public class ReactEditText extends AppCompatEditText { | ||
| mScrollWatcher = scrollWatcher; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming from this issue #63191, after adding this check
if (itemUri != null), images copied from WPS Office stopped working on paste. This is because a non-null URI can also represent data when copying text from google docs and images from WPS Office.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right @jayeshmangwani, so there could be any other value that is included when copying from WPS Office. If yes then we modify the null check here for other cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WPS cases we handled here on this PR #64457 and handled the
MIMETYPE_TEXT_PLAINtype