mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-08 17:22:05 +08:00
Fix text input spans
Differential Revision: D2626072 fb-gh-sync-id: 35087d65b8f4a52e44fedc229058c3f88827e539
This commit is contained in:
committed by
facebook-github-bot-9
parent
7b2cd03d6a
commit
de586bfa18
@@ -20,12 +20,17 @@ import android.text.InputType;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.AbsoluteSizeSpan;
|
||||
import android.text.style.BackgroundColorSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.views.text.CustomStyleSpan;
|
||||
import com.facebook.react.views.text.ReactTagSpan;
|
||||
|
||||
/**
|
||||
* A wrapper around the EditText that lets us better control what happens when an EditText gets
|
||||
@@ -204,6 +209,15 @@ public class ReactEditText extends EditText {
|
||||
private void manageSpans(SpannableStringBuilder spannableStringBuilder) {
|
||||
Object[] spans = getText().getSpans(0, length(), Object.class);
|
||||
for (int spanIdx = 0; spanIdx < spans.length; spanIdx++) {
|
||||
// Remove all styling spans we might have previously set
|
||||
if (ForegroundColorSpan.class.isInstance(spans[spanIdx]) ||
|
||||
BackgroundColorSpan.class.isInstance(spans[spanIdx]) ||
|
||||
AbsoluteSizeSpan.class.isInstance(spans[spanIdx]) ||
|
||||
CustomStyleSpan.class.isInstance(spans[spanIdx]) ||
|
||||
ReactTagSpan.class.isInstance(spans[spanIdx])) {
|
||||
getText().removeSpan(spans[spanIdx]);
|
||||
}
|
||||
|
||||
if ((getText().getSpanFlags(spans[spanIdx]) & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) !=
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) {
|
||||
continue;
|
||||
|
||||
@@ -16,8 +16,9 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
|
||||
/**
|
||||
* Event emitted by EditText native view when text changes.
|
||||
* VisibleForTesting from {@link TextInputEventsTestCase}.
|
||||
*/
|
||||
/* package */ class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {
|
||||
public class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {
|
||||
|
||||
public static final String EVENT_NAME = "topChange";
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
|
||||
/**
|
||||
* Event emitted by EditText native view when text changes.
|
||||
* VisibleForTesting from {@link TextInputEventsTestCase}.
|
||||
*/
|
||||
/* package */ class ReactTextInputEvent extends Event<ReactTextInputEvent> {
|
||||
public class ReactTextInputEvent extends Event<ReactTextInputEvent> {
|
||||
|
||||
public static final String EVENT_NAME = "topTextInput";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user