Skip to content

Commit a80110a

Browse files
committed
refactor: rewrite to return early regardless of the paste watcher
1 parent 2c89910 commit a80110a

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

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

Lines changed: 24 additions & 17 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..b3feb0a 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,40 +483,47 @@ index 56a1069..b3feb0a 100644
483483
mTextAttributes = new TextAttributes();
484484

485485
applyTextAttributes();
486-
@@ -332,8 +339,31 @@ 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) {
508518
+ mPasteWatcher.onPaste(type, data);
509-
+ return true;
510519
+ }
511-
+ }
512-
+ if (type != null && data != null) {
513-
+ mPasteWatcher.onPaste(type, data);
520+
+ // Don't return - let the system proceed with default text pasting behavior
514521
+ }
515522
+ }
516523
}
517524
return super.onTextContextMenuItem(id);
518525
}
519-
@@ -395,6 +425,10 @@ public class ReactEditText extends AppCompatEditText {
526+
@@ -395,6 +432,10 @@ public class ReactEditText extends AppCompatEditText {
520527
mScrollWatcher = scrollWatcher;
521528
}
522529

0 commit comments

Comments
 (0)