Skip to content

Commit

Permalink
Revert "Remove support for Android API < 23 in ReactEditText (#39671)"
Browse files Browse the repository at this point in the history
This reverts commit 1904e80.
  • Loading branch information
huntie committed Jan 2, 2024
1 parent 21fc812 commit cadcf54
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

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;
Expand Down Expand Up @@ -208,7 +210,9 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
public void onDestroyActionMode(ActionMode mode) {}
};
setCustomSelectionActionModeCallback(customActionModeCallback);
setCustomInsertionActionModeCallback(customActionModeCallback);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setCustomInsertionActionModeCallback(customActionModeCallback);
}
}

@Override
Expand Down Expand Up @@ -304,7 +308,26 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
@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);
}
Expand Down Expand Up @@ -679,8 +702,10 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
}
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).
Expand Down

0 comments on commit cadcf54

Please sign in to comment.