File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
media-placeholders/src/main/java/org/wordpress/aztec/placeholders Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import androidx.core.content.ContextCompat
1515import kotlinx.coroutines.CoroutineScope
1616import kotlinx.coroutines.Dispatchers
1717import kotlinx.coroutines.Job
18+ import kotlinx.coroutines.delay
1819import kotlinx.coroutines.launch
1920import kotlinx.coroutines.runBlocking
2021import org.wordpress.aztec.AztecAttributes
@@ -143,7 +144,14 @@ class PlaceholderManager(
143144 }
144145 val uuid = attrs.getValue(UUID_ATTRIBUTE )
145146 val type = attrs.getValue(TYPE_ATTRIBUTE )
146- val textViewLayout: Layout = aztecText.layout
147+ // At this point we can get to a race condition where the aztec text layout is not yet initialized.
148+ // We want to wait a bit and make sure it's properly loaded.
149+ var counter = 0
150+ while (aztecText.layout == null && counter < 10 ) {
151+ delay(50 )
152+ counter + = 1
153+ }
154+ val textViewLayout: Layout = aztecText.layout ? : return
147155 val parentTextViewRect = Rect ()
148156 val targetLineOffset = textViewLayout.getLineForOffset(targetPosition)
149157 textViewLayout.getLineBounds(targetLineOffset, parentTextViewRect)
You can’t perform that action at this time.
0 commit comments