Skip to content

Commit 9161e57

Browse files
committed
Placeholder doesn't have correct proportions when drawing the first time
1 parent 3aa28e0 commit 9161e57

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class PlaceholderManager(
161161
val parentTextViewTopAndBottomOffset = aztecText.scrollY + aztecText.compoundPaddingTop
162162

163163
val adapter = adapters[type]!!
164-
val windowWidth = parentTextViewRect.right - parentTextViewRect.left - 20
164+
val windowWidth = parentTextViewRect.right - parentTextViewRect.left - EDITOR_INNER_PADDING
165165
val height = adapter.calculateHeight(attrs, windowWidth)
166166
parentTextViewRect.top += parentTextViewTopAndBottomOffset
167167
parentTextViewRect.bottom = parentTextViewRect.top + height
@@ -176,8 +176,8 @@ class PlaceholderManager(
176176
box = adapter.createView(container.context, uuid, attrs)
177177
}
178178
val params = FrameLayout.LayoutParams(
179-
adapter.calculateWidth(attrs, windowWidth) - 20,
180-
height - 20
179+
adapter.calculateWidth(attrs, windowWidth) - EDITOR_INNER_PADDING,
180+
height - EDITOR_INNER_PADDING
181181
)
182182
val padding = 10
183183
params.setMargins(
@@ -326,7 +326,9 @@ class PlaceholderManager(
326326
}
327327

328328
private suspend fun updateDrawableBounds(adapter: PlaceholderAdapter, attrs: AztecAttributes, drawable: Drawable?) {
329-
val editorWidth = if (aztecText.width > 0) aztecText.width else aztecText.maxImagesWidth
329+
val editorWidth = if (aztecText.width > 0) {
330+
aztecText.width - aztecText.paddingStart - aztecText.paddingEnd - EDITOR_INNER_PADDING
331+
} else aztecText.maxImagesWidth
330332
if (drawable?.bounds?.right != editorWidth) {
331333
drawable?.setBounds(0, 0, adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
332334
}
@@ -466,5 +468,6 @@ class PlaceholderManager(
466468
private const val DEFAULT_HTML_TAG = "placeholder"
467469
private const val UUID_ATTRIBUTE = "uuid"
468470
private const val TYPE_ATTRIBUTE = "type"
471+
private const val EDITOR_INNER_PADDING = 20
469472
}
470473
}

0 commit comments

Comments
 (0)