@@ -7,7 +7,6 @@ import android.graphics.drawable.Drawable
77import android.text.Editable
88import android.text.Layout
99import android.text.Spanned
10- import android.util.Log
1110import android.view.MotionEvent
1211import android.view.View
1312import android.view.ViewTreeObserver
@@ -351,7 +350,7 @@ class PlaceholderManager(
351350 return
352351 }
353352 val propertiesChanged = ! widthSame || ! heightSame
354- recreateView = ! propertiesChanged || ! adapter.animateLayoutChanges()
353+ recreateView = ! propertiesChanged || adapter is StaticPlaceholderAdapter
355354 if (recreateView) {
356355 container.removeView(box)
357356 positionToIdMutex.withLock {
@@ -365,7 +364,6 @@ class PlaceholderManager(
365364 it.uuid == uuid
366365 }?.viewParams ? : MutableStateFlow (Placeholder .ViewParams (newWidth, newHeight, attrs, initial = true ))
367366 if (box == null || recreateView) {
368- Log .d(" vojta" , " Creating new view" )
369367 box = adapter.createView(container.context, uuid, paramsFlow)
370368 box.id = uuid.hashCode()
371369 box.setBackgroundColor(Color .TRANSPARENT )
@@ -376,10 +374,8 @@ class PlaceholderManager(
376374 newHeight
377375 )
378376 } else {
379- Log .d(" vojta" , " Updating params" )
380377 paramsFlow.emit(Placeholder .ViewParams (newWidth, newHeight, attrs, initial = false ))
381378 }
382- Log .d(" vojta" , " Creating view with $newWidth x $newHeight " )
383379
384380 box.updateLayoutParams<FrameLayout .LayoutParams > {
385381 leftMargin = newLeftPadding
@@ -390,7 +386,6 @@ class PlaceholderManager(
390386 positionToId.add(Placeholder (targetPosition, uuid, paramsFlow))
391387 }
392388 if (recreateView) {
393- Log .d(" vojta" , " Adding view with $newWidth x $newHeight " )
394389 container.addView(box)
395390 }
396391 adapter.onViewCreated(box, uuid)
@@ -528,7 +523,6 @@ class PlaceholderManager(
528523 val adapter = adapters[type] ? : return @forEach
529524 it.drawable = buildPlaceholderDrawable(adapter, it.attributes)
530525 aztecText.refreshText(false )
531- Log .d(" vojta" , " Building view on global layout" )
532526 insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
533527 }
534528 }
@@ -558,18 +552,36 @@ class PlaceholderManager(
558552 }
559553
560554 /* *
561- * A adapter for a custom view drawn over the placeholder in the Aztec text .
555+ * Use this method if you want your placeholders to be recreated on each size change .
562556 */
563- interface PlaceholderAdapter : View .OnTouchListener {
557+ interface StaticPlaceholderAdapter : PlaceholderAdapter {
558+ override suspend fun createView (context : Context , placeholderUuid : String , viewParamsUpdate : StateFlow <Placeholder .ViewParams >): View {
559+ return createView(context, placeholderUuid, attrs = viewParamsUpdate.value.attrs)
560+ }
564561 /* *
565562 * Creates the view but it's called before the view is measured. If you need the actual width and height. Use
566563 * the `onViewCreated` method where the view is already present in its correct size.
567564 * @param context necessary to build custom views
568565 * @param placeholderUuid the placeholder UUID
569566 * @param attrs aztec attributes of the view
570567 */
571- suspend fun createView (context : Context , placeholderUuid : String , viewParamsUpdate : StateFlow <Placeholder .ViewParams >): View
568+ suspend fun createView (context : Context , placeholderUuid : String , attrs : AztecAttributes ): View
569+ }
572570
571+ /* *
572+ * A adapter for a custom view drawn over the placeholder in the Aztec text. The default implementation propagates
573+ * media size changes through the flow. If you want your views to be recreated automatically, use
574+ * the StaticPlaceholderAdapter.
575+ */
576+ interface PlaceholderAdapter : View .OnTouchListener {
577+ /* *
578+ * Creates the view but it's called before the view is measured. If you need the actual width and height. Use
579+ * the `onViewCreated` method where the view is already present in its correct size.
580+ * @param context necessary to build custom views
581+ * @param placeholderUuid the placeholder UUID
582+ * @param viewParamsUpdate flow of attribute changes used to update the current view instead of redrawing it
583+ */
584+ suspend fun createView (context : Context , placeholderUuid : String , viewParamsUpdate : StateFlow <Placeholder .ViewParams >): View
573585 /* *
574586 * Called after the view is measured. Use this method if you need the actual width and height of the view to
575587 * draw your media.
@@ -578,8 +590,6 @@ class PlaceholderManager(
578590 */
579591 suspend fun onViewCreated (view : View , placeholderUuid : String ) {}
580592
581- fun animateLayoutChanges () = false
582-
583593 /* *
584594 * Called when the placeholder is deleted by the user. Use this method if you need to clear your data when the
585595 * item is deleted (for example delete an image in your DB).
0 commit comments