@@ -110,7 +110,10 @@ class PlaceholderManager(
110110
111111 private suspend fun buildPlaceholderDrawable (adapter : PlaceholderAdapter , attrs : AztecAttributes ): Drawable {
112112 val drawable = ContextCompat .getDrawable(aztecText.context, android.R .color.transparent)!!
113- updateDrawableBounds(adapter, attrs, drawable)
113+ val editorWidth = if (aztecText.width > 0 ) {
114+ aztecText.width - aztecText.paddingStart - aztecText.paddingEnd
115+ } else aztecText.maxImagesWidth
116+ drawable.setBounds(0 , 0 , adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
114117 return drawable
115118 }
116119
@@ -169,7 +172,7 @@ class PlaceholderManager(
169172 val parentTextViewTopAndBottomOffset = aztecText.scrollY + aztecText.compoundPaddingTop
170173
171174 val adapter = adapters[type]!!
172- val windowWidth = parentTextViewRect.right - parentTextViewRect.left - 20
175+ val windowWidth = parentTextViewRect.right - parentTextViewRect.left - EDITOR_INNER_PADDING
173176 val height = adapter.calculateHeight(attrs, windowWidth)
174177 parentTextViewRect.top + = parentTextViewTopAndBottomOffset
175178 parentTextViewRect.bottom = parentTextViewRect.top + height
@@ -184,8 +187,8 @@ class PlaceholderManager(
184187 box = adapter.createView(container.context, uuid, attrs)
185188 }
186189 val params = FrameLayout .LayoutParams (
187- adapter.calculateWidth(attrs, windowWidth) - 20 ,
188- height - 20
190+ adapter.calculateWidth(attrs, windowWidth) - EDITOR_INNER_PADDING ,
191+ height - EDITOR_INNER_PADDING
189192 )
190193 val padding = 10
191194 params.setMargins(
@@ -325,21 +328,14 @@ class PlaceholderManager(
325328 spans.forEach {
326329 val type = it.attributes.getValue(TYPE_ATTRIBUTE )
327330 val adapter = adapters[type] ? : return @forEach
328- updateDrawableBounds (adapter, it.attributes, it.drawable )
331+ it.drawable = buildPlaceholderDrawable (adapter, it.attributes)
329332 aztecText.refreshText(false )
330333 insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
331334 }
332335 }
333336 }
334337 }
335338
336- private suspend fun updateDrawableBounds (adapter : PlaceholderAdapter , attrs : AztecAttributes , drawable : Drawable ? ) {
337- val editorWidth = if (aztecText.width > 0 ) aztecText.width else aztecText.maxImagesWidth
338- if (drawable?.bounds?.right != editorWidth) {
339- drawable?.setBounds(0 , 0 , adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
340- }
341- }
342-
343339 private fun clearAllViews () {
344340 for (placeholder in positionToId) {
345341 container.findViewWithTag<View >(placeholder.uuid)?.let {
@@ -471,8 +467,10 @@ class PlaceholderManager(
471467 data class Placeholder (val elementPosition : Int , val uuid : String )
472468
473469 companion object {
470+ private const val TAG = " PlaceholderManager"
474471 private const val DEFAULT_HTML_TAG = " placeholder"
475472 private const val UUID_ATTRIBUTE = " uuid"
476473 private const val TYPE_ATTRIBUTE = " type"
474+ private const val EDITOR_INNER_PADDING = 20
477475 }
478476}
0 commit comments