Skip to content

Commit ae17045

Browse files
committed
fix(android): dont check urlspan if not needed
1 parent cae900f commit ae17045

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Diff for: src/label.android.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,21 @@ export class Label extends LabelBase {
585585
this.autoFontSize,
586586
1
587587
) as android.text.SpannableStringBuilder;
588-
const urlSpan = result.getSpans(0, result.length(), android.text.style.URLSpan.class);
589-
if (urlSpan.length > 0) {
590-
this._setTappableState(true);
591-
initializeURLClickableSpan();
592-
for (let index = 0; index < urlSpan.length; index++) {
593-
const span = urlSpan[index];
594-
const text = span.getURL();
595-
const start = result.getSpanStart(span);
596-
const end = result.getSpanEnd(span);
597-
result.removeSpan(span);
598-
result.setSpan(new URLClickableSpan(text, this), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
588+
// no need to check for urlspan if we dont have a listener
589+
// the only issue might happen if the listener is set afterward. Is that really an issue?
590+
if (this.hasListeners(Span.linkTapEvent)) {
591+
const urlSpan = result.getSpans(0, result.length(), android.text.style.URLSpan.class);
592+
if (urlSpan.length > 0) {
593+
this._setTappableState(true);
594+
initializeURLClickableSpan();
595+
for (let index = 0; index < urlSpan.length; index++) {
596+
const span = urlSpan[index];
597+
const text = span.getURL();
598+
const start = result.getSpanStart(span);
599+
const end = result.getSpanEnd(span);
600+
result.removeSpan(span);
601+
result.setSpan(new URLClickableSpan(text, this), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
602+
}
599603
}
600604
}
601605
return result;

0 commit comments

Comments
 (0)