@@ -14,6 +14,7 @@ import android.widget.FrameLayout
1414import androidx.core.content.ContextCompat
1515import kotlinx.coroutines.CoroutineScope
1616import kotlinx.coroutines.launch
17+ import kotlinx.coroutines.runBlocking
1718import org.wordpress.aztec.AztecAttributes
1819import org.wordpress.aztec.AztecContentChangeWatcher
1920import org.wordpress.aztec.AztecText
@@ -100,7 +101,7 @@ class PlaceholderManager(
100101 aztecText.refreshText(false )
101102 }
102103
103- private fun buildPlaceholderDrawable (adapter : PlaceholderAdapter , attrs : AztecAttributes ): Drawable {
104+ private suspend fun buildPlaceholderDrawable (adapter : PlaceholderAdapter , attrs : AztecAttributes ): Drawable {
104105 val drawable = ContextCompat .getDrawable(aztecText.context, android.R .color.transparent)!!
105106 updateDrawableBounds(adapter, attrs, drawable)
106107 return drawable
@@ -247,7 +248,7 @@ class PlaceholderManager(
247248 val adapter = adapters[type] ? : return false
248249 val aztecAttributes = AztecAttributes (attributes)
249250 aztecAttributes.setValue(UUID_ATTRIBUTE , UUID .randomUUID().toString())
250- val drawable = buildPlaceholderDrawable(adapter, aztecAttributes)
251+ val drawable = runBlocking { buildPlaceholderDrawable(adapter, aztecAttributes) }
251252 val span = AztecPlaceholderSpan (
252253 context = aztecText.context,
253254 drawable = drawable,
@@ -283,8 +284,8 @@ class PlaceholderManager(
283284 spans.forEach {
284285 val type = it.attributes.getValue(TYPE_ATTRIBUTE )
285286 val adapter = adapters[type] ? : return
286- updateDrawableBounds(adapter, it.attributes, it.drawable)
287287 coroutineScope.launch {
288+ updateDrawableBounds(adapter, it.attributes, it.drawable)
288289 aztecText.refreshText(false )
289290 insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
290291 }
@@ -293,7 +294,7 @@ class PlaceholderManager(
293294 })
294295 }
295296
296- private fun updateDrawableBounds (adapter : PlaceholderAdapter , attrs : AztecAttributes , drawable : Drawable ? ) {
297+ private suspend fun updateDrawableBounds (adapter : PlaceholderAdapter , attrs : AztecAttributes , drawable : Drawable ? ) {
297298 val editorWidth = if (aztecText.width > 0 ) aztecText.width else aztecText.maxImagesWidth
298299 if (drawable?.bounds?.right != editorWidth) {
299300 drawable?.setBounds(0 , 0 , adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
@@ -366,18 +367,18 @@ class PlaceholderManager(
366367 * Returns width of the view based on the HTML attributes. Use this method to either set fixed width or to
367368 * calculate width based on the view.
368369 */
369- fun getWidth (attrs : AztecAttributes ): Proportion = Proportion .Ratio (1.0f )
370+ suspend fun getWidth (attrs : AztecAttributes ): Proportion = Proportion .Ratio (1.0f )
370371
371372 /* *
372373 * Returns height of the view based on the HTML attributes. Use this method to either set fixed height or to
373374 * calculate width based on the view.
374375 */
375- fun getHeight (attrs : AztecAttributes ): Proportion
376+ suspend fun getHeight (attrs : AztecAttributes ): Proportion
376377
377378 /* *
378379 * Returns height of the view based on the width and the placeholder height.
379380 */
380- fun calculateHeight (attrs : AztecAttributes , windowWidth : Int ): Int {
381+ suspend fun calculateHeight (attrs : AztecAttributes , windowWidth : Int ): Int {
381382 return getHeight(attrs).let { height ->
382383 when (height) {
383384 is Proportion .Fixed -> height.value
@@ -396,7 +397,7 @@ class PlaceholderManager(
396397 /* *
397398 * Returns height of the view based on the width and the placeholder height.
398399 */
399- fun calculateWidth (attrs : AztecAttributes , windowWidth : Int ): Int {
400+ suspend fun calculateWidth (attrs : AztecAttributes , windowWidth : Int ): Int {
400401 return getWidth(attrs).let { width ->
401402 when (width) {
402403 is Proportion .Fixed -> min(windowWidth, width.value)
0 commit comments