mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert "Remove support for Android API < 23 in ReactEditText (#39671)"
This reverts commit 1904e8036a.
This commit is contained in:
+29
-4
@@ -9,6 +9,8 @@ package com.facebook.react.views.textinput;
|
||||
|
||||
import static com.facebook.react.uimanager.UIManagerHelper.getReactContext;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
@@ -208,7 +210,9 @@ public class ReactEditText extends AppCompatEditText {
|
||||
public void onDestroyActionMode(ActionMode mode) {}
|
||||
};
|
||||
setCustomSelectionActionModeCallback(customActionModeCallback);
|
||||
setCustomInsertionActionModeCallback(customActionModeCallback);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
setCustomInsertionActionModeCallback(customActionModeCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,7 +308,26 @@ public class ReactEditText extends AppCompatEditText {
|
||||
@Override
|
||||
public boolean onTextContextMenuItem(int id) {
|
||||
if (id == android.R.id.paste) {
|
||||
id = android.R.id.pasteAsPlainText;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
id = android.R.id.pasteAsPlainText;
|
||||
} else {
|
||||
ClipboardManager clipboard =
|
||||
(ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData previousClipData = clipboard.getPrimaryClip();
|
||||
if (previousClipData != null) {
|
||||
for (int i = 0; i < previousClipData.getItemCount(); i++) {
|
||||
final CharSequence text = previousClipData.getItemAt(i).coerceToText(getContext());
|
||||
final CharSequence paste = (text instanceof Spanned) ? text.toString() : text;
|
||||
if (paste != null) {
|
||||
ClipData clipData = ClipData.newPlainText(null, text);
|
||||
clipboard.setPrimaryClip(clipData);
|
||||
}
|
||||
}
|
||||
boolean actionPerformed = super.onTextContextMenuItem(id);
|
||||
clipboard.setPrimaryClip(previousClipData);
|
||||
return actionPerformed;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onTextContextMenuItem(id);
|
||||
}
|
||||
@@ -679,8 +702,10 @@ public class ReactEditText extends AppCompatEditText {
|
||||
}
|
||||
mDisableTextDiffing = false;
|
||||
|
||||
if (getBreakStrategy() != reactTextUpdate.getTextBreakStrategy()) {
|
||||
setBreakStrategy(reactTextUpdate.getTextBreakStrategy());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (getBreakStrategy() != reactTextUpdate.getTextBreakStrategy()) {
|
||||
setBreakStrategy(reactTextUpdate.getTextBreakStrategy());
|
||||
}
|
||||
}
|
||||
|
||||
// Update cached spans (in Fabric only).
|
||||
|
||||
Reference in New Issue
Block a user