From 46f21243b5a3b29aedb7416703a994fd0bef7773 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Tue, 5 Nov 2024 18:33:00 +0100 Subject: [PATCH 1/2] Improve removing spans on Android --- .../java/com/expensify/livemarkdown/MarkdownUtils.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java b/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java index e51aa4b4c..406fa046e 100644 --- a/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java +++ b/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Objects; public class MarkdownUtils { @@ -62,6 +63,8 @@ public MarkdownUtils(@NonNull AssetManager assetManager) { private MarkdownStyle mMarkdownStyle; + private final ArrayList mMarkdownSpans = new ArrayList<>(); + public void setMarkdownStyle(@NonNull MarkdownStyle markdownStyle) { mMarkdownStyle = markdownStyle; } @@ -170,13 +173,14 @@ private void applyRange(SpannableStringBuilder ssb, String type, int start, int private void setSpan(SpannableStringBuilder ssb, MarkdownSpan span, int start, int end) { ssb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + mMarkdownSpans.add(span); } private void removeSpans(SpannableStringBuilder ssb) { - // We shouldn't use `removeSpans()` because it also removes SpellcheckSpan, SuggestionSpan etc. - MarkdownSpan[] spans = ssb.getSpans(0, ssb.length(), MarkdownSpan.class); - for (MarkdownSpan span : spans) { + // We shouldn't use `ssb.removeSpans()` because it also removes SpellcheckSpan, SuggestionSpan etc. + for (MarkdownSpan span : mMarkdownSpans) { ssb.removeSpan(span); } + mMarkdownSpans.clear(); } } From 42c7588f3190d45d9ef22c4fa14bf919da872af9 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Sat, 7 Dec 2024 12:50:28 +0100 Subject: [PATCH 2/2] Remove unused import --- .../src/main/java/com/expensify/livemarkdown/MarkdownUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java b/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java index 492ca1b90..6877e46f9 100644 --- a/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java +++ b/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java @@ -4,7 +4,6 @@ import androidx.annotation.NonNull; -import com.expensify.livemarkdown.spans.MarkdownSpan; import com.facebook.react.bridge.ReactContext; import com.facebook.systrace.Systrace;