Skip to content

Commit d629de0

Browse files
authored
Merge pull request #60501 from rohit9625/fix/android-onpaste-behavior
fix: binary content appears in composer when pasting image
2 parents 6291404 + a80110a commit d629de0

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

patches/react-native+0.77.1+011+Add-onPaste-to-TextInput.patch

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ index 0000000..bfb5819
445445
+ public void onPaste(String type, String data);
446446
+}
447447
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
448-
index 56a1069..272ea7d 100644
448+
index 56a1069..9f14425 100644
449449
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java
450450
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java
451451
@@ -9,6 +9,10 @@ package com.facebook.react.views.textinput;
@@ -483,38 +483,47 @@ index 56a1069..272ea7d 100644
483483
mTextAttributes = new TextAttributes();
484484

485485
applyTextAttributes();
486-
@@ -332,8 +339,29 @@ public class ReactEditText extends AppCompatEditText {
486+
@@ -332,8 +339,38 @@ public class ReactEditText extends AppCompatEditText {
487487
*/
488488
@Override
489489
public boolean onTextContextMenuItem(int id) {
490490
- if (id == android.R.id.paste) {
491491
+ if (id == android.R.id.paste || id == android.R.id.pasteAsPlainText) {
492492
id = android.R.id.pasteAsPlainText;
493-
+ if (mPasteWatcher != null) {
494-
+ ClipboardManager clipboardManager =
493+
+
494+
+ ClipboardManager clipboardManager =
495495
+ (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
496-
+ ClipData clipData = clipboardManager.getPrimaryClip();
496+
+ ClipData clipData = clipboardManager.getPrimaryClip();
497+
+ if (clipData != null) {
498+
+ ClipData.Item item = clipData.getItemAt(0);
499+
+ Uri itemUri = item.getUri();
497500
+ String type = null;
498501
+ String data = null;
502+
+
503+
+ if (itemUri != null) {
504+
+ ContentResolver cr = getReactContext(this).getContentResolver();
505+
+ type = cr.getType(itemUri);
506+
+ data = itemUri.toString();
507+
+ if (mPasteWatcher != null) {
508+
+ mPasteWatcher.onPaste(type, data);
509+
+ }
510+
+ // Prevents default behavior to avoid inserting raw binary data into the text field
511+
+ return true;
512+
+ }
513+
+
499514
+ if (clipData.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
500515
+ type = ClipDescription.MIMETYPE_TEXT_PLAIN;
501-
+ data = clipData.getItemAt(0).getText().toString();
502-
+ } else {
503-
+ Uri itemUri = clipData.getItemAt(0).getUri();
504-
+ if (itemUri != null) {
505-
+ ContentResolver cr = getReactContext(this).getContentResolver();
506-
+ type = cr.getType(itemUri);
507-
+ data = itemUri.toString();
516+
+ data = item.getText().toString();
517+
+ if (mPasteWatcher != null) {
518+
+ mPasteWatcher.onPaste(type, data);
508519
+ }
509-
+ }
510-
+ if (type != null && data != null) {
511-
+ mPasteWatcher.onPaste(type, data);
520+
+ // Don't return - let the system proceed with default text pasting behavior
512521
+ }
513522
+ }
514523
}
515524
return super.onTextContextMenuItem(id);
516525
}
517-
@@ -395,6 +423,10 @@ public class ReactEditText extends AppCompatEditText {
526+
@@ -395,6 +432,10 @@ public class ReactEditText extends AppCompatEditText {
518527
mScrollWatcher = scrollWatcher;
519528
}
520529

0 commit comments

Comments
 (0)