Skip to content

Commit 66d391d

Browse files
committed
chore(rich-text): fix empty spans error
1 parent 8d4dd2a commit 66d391d

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ const handleGetSelection = () => {
102102
console.log(ref.current?.getSelection());
103103
};
104104

105+
// arg0 - position of link in text
106+
const handleGetLink = () => {
107+
console.log(ref.current?.getLink(1));
108+
};
109+
105110
<RichTextInput
106111
ref={ref}
107112
placeholder="I am the angry placeholder"

android/src/main/java/com/richtextinput/RichTextInputViewManager.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ class RichTextInputViewManager : SimpleViewManager<EditText>() {
8383
@ReactMethod(isBlockingSynchronousMethod = true)
8484
fun getLink(position: Int): String {
8585
if (editText != null) {
86-
val span = editText!!.text.getSpans(position, position, URLSpan::class.java)[0]
86+
val spans = editText!!.text.getSpans(position, position, URLSpan::class.java)
8787

88-
if (span != null) {
89-
return span.url
88+
if (spans.size > 0) {
89+
return spans[0].url
9090
}
91+
92+
return ""
9193
}
9294

9395
return INPUT_NOT_INITIALIZED_ERROR

0 commit comments

Comments
 (0)