Skip to content

Commit

Permalink
Force-reset drawable paddings when popup background is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Oct 17, 2020
1 parent 5262af6 commit 79ace48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cascade/src/main/java/me/saket/cascade/ForcePaddingsDrawable.kt
@@ -0,0 +1,17 @@
package me.saket.cascade

import android.graphics.Rect
import android.graphics.drawable.Drawable

/**
* Workaround for [https://issuetracker.google.com/u/1/issues/171026918].
*
* The default popup background contains internal paddings, that aren't reset even if the
* background is overridden using a [CascadePopupMenu.Styler].
*/
internal class ForcePaddingsDrawable(delegate: Drawable) : DrawableWrapperCompat(delegate) {
override fun getPadding(padding: Rect): Boolean {
super.getPadding(padding)
return true
}
}
Expand Up @@ -121,7 +121,15 @@ open class HeightAnimatableViewFlipper(context: Context) : ViewFlipper2(context)

@Suppress("DEPRECATION")
override fun setBackgroundDrawable(background: Drawable?) {
super.setBackgroundDrawable(background?.let(::HeightClipDrawable))
if (background == null) {
super.setBackgroundDrawable(null)
} else {
super.setBackgroundDrawable(
HeightClipDrawable(
ForcePaddingsDrawable(background)
)
)
}
}

private fun background(): HeightClipDrawable? {
Expand Down

0 comments on commit 79ace48

Please sign in to comment.