Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions patches/react-native+0.77.1+011+Add-onPaste-to-TextInput.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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_PLAIN type

+ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}

Expand Down
Loading