diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 34ad7c4e9af..3b10c2c7d1c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -28,6 +28,7 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableNativeMap; import com.facebook.react.bridge.WritableArray; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ReactAccessibilityDelegate; @@ -44,9 +45,9 @@ import java.util.concurrent.ConcurrentHashMap; public class TextLayoutManager { // TODO T67606397: Refactor configuration of fabric logs - private static final boolean ENABLE_MEASURE_LOGGING = false; + private static final boolean ENABLE_MEASURE_LOGGING = ReactBuildConfig.DEBUG && false; - private static final String TAG = "TextLayoutManager"; + private static final String TAG = TextLayoutManager.class.getSimpleName(); // It's important to pass the ANTI_ALIAS_FLAG flag to the constructor rather than setting it // later by calling setFlags. This is because the latter approach triggers a bug on Android 4.4.2. @@ -82,10 +83,16 @@ public class TextLayoutManager { } public static void setCachedSpannabledForTag(int reactTag, @NonNull Spannable sp) { + if (ENABLE_MEASURE_LOGGING) { + FLog.e(TAG, "Set cached spannable for tag[" + reactTag + "]: " + sp.toString()); + } sTagToSpannableCache.put(reactTag, sp); } public static void deleteCachedSpannableForTag(int reactTag) { + if (ENABLE_MEASURE_LOGGING) { + FLog.e(TAG, "Delete cached spannable for tag[" + reactTag + "]"); + } sTagToSpannableCache.remove(reactTag); } @@ -360,9 +367,18 @@ public class TextLayoutManager { Spannable text; if (attributedString.hasKey("cacheId")) { int cacheId = attributedString.getInt("cacheId"); + if (ENABLE_MEASURE_LOGGING) { + FLog.e(TAG, "Get cached spannable for cacheId[" + cacheId + "]"); + } if (sTagToSpannableCache.containsKey(cacheId)) { text = sTagToSpannableCache.get(cacheId); + if (ENABLE_MEASURE_LOGGING) { + FLog.e(TAG, "Text for spannable found for cacheId[" + cacheId + "]: " + text.toString()); + } } else { + if (ENABLE_MEASURE_LOGGING) { + FLog.e(TAG, "No cached spannable found for cacheId[" + cacheId + "]"); + } return 0; } } else { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index f11daf378fc..4d4147215d8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -38,8 +38,10 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatEditText; import androidx.core.view.AccessibilityDelegateCompat; import androidx.core.view.ViewCompat; +import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.views.text.CustomLetterSpacingSpan; @@ -70,8 +72,10 @@ import java.util.List; */ public class ReactEditText extends AppCompatEditText implements FabricViewStateManager.HasFabricViewStateManager { - private final InputMethodManager mInputMethodManager; + private final String TAG = ReactEditText.class.getSimpleName(); + public static final boolean DEBUG_MODE = ReactBuildConfig.DEBUG && false; + // This flag is set to true when we set the text of the EditText explicitly. In that case, no // *TextChanged events should be triggered. This is less expensive than removing the text // listeners and adding them back again after the text change is completed. @@ -169,6 +173,9 @@ public class ReactEditText extends AppCompatEditText @Override protected void finalize() { + if (DEBUG_MODE) { + FLog.e(TAG, "finalize[" + getId() + "] delete cached spannable"); + } TextLayoutManager.deleteCachedSpannableForTag(getId()); } @@ -326,11 +333,18 @@ public class ReactEditText extends AppCompatEditText @Override public void setSelection(int start, int end) { + if (DEBUG_MODE) { + FLog.e(TAG, "setSelection[" + getId() + "]: " + start + " " + end); + } super.setSelection(start, end); } @Override protected void onSelectionChanged(int selStart, int selEnd) { + if (DEBUG_MODE) { + FLog.e(TAG, "onSelectionChanged[" + getId() + "]: " + selStart + " " + selEnd); + } + super.onSelectionChanged(selStart, selEnd); if (!mIsSettingTextFromCacheUpdate && mSelectionWatcher != null && hasFocus()) { mSelectionWatcher.onSelectionChanged(selStart, selEnd); @@ -502,6 +516,17 @@ public class ReactEditText extends AppCompatEditText return; } + if (DEBUG_MODE) { + FLog.e( + TAG, + "maybeSetText[" + + getId() + + "]: current text: " + + getText() + + " update: " + + reactTextUpdate.getText()); + } + // The current text gets replaced with the text received from JS. However, the spans on the // current text need to be adapted to the new text. Since TextView#setText() will remove or // reset some of these spans even if they are set directly, SpannableStringBuilder#replace() is @@ -1004,6 +1029,11 @@ public class ReactEditText extends AppCompatEditText @Override public void onTextChanged(CharSequence s, int start, int before, int count) { + if (DEBUG_MODE) { + FLog.e( + TAG, "onTextChanged[" + getId() + "]: " + s + " " + start + " " + before + " " + count); + } + if (!mIsSettingTextFromCacheUpdate) { if (!mIsSettingTextFromJS && mListeners != null) { for (TextWatcher listener : mListeners) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index a8894676574..6d9ab0d39b6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -1183,6 +1183,10 @@ public class ReactTextInputManager extends BaseViewManager