@@ -8,12 +8,12 @@ import com.reactnativenavigation.options.params.DensityPixel
88
99
1010class IconBackgroundDrawable (
11- private val wrapped : Drawable ,
12- private val cornerRadius : DensityPixel ,
13- private val backgroundWidth : Int ,
14- private val backgroundHeight : Int ,
15- private val iconColor : Int? ,
16- val backgroundColor : Int?
11+ private val wrapped : Drawable ,
12+ private val cornerRadius : DensityPixel ,
13+ private val backgroundWidth : Int ,
14+ private val backgroundHeight : Int ,
15+ private val iconColor : Int? ,
16+ val backgroundColor : Int?
1717) : Drawable() {
1818 private val path: Path = Path ()
1919 private val bitmapPaint = Paint ().apply {
@@ -56,28 +56,31 @@ class IconBackgroundDrawable(
5656 canvas.drawBitmap(wrapped.toBitmap(), null , bitmapRect, bitmapPaint)
5757 }
5858
59+ override fun getIntrinsicWidth (): Int = backgroundWidth
60+ override fun getIntrinsicHeight (): Int = backgroundHeight
61+
5962 override fun setBounds (l : Int , t : Int , r : Int , b : Int ) {
60- updatePath(RectF (l.toFloat(), t.toFloat() , backgroundWidth.toFloat(), backgroundHeight.toFloat()))
61- super .setBounds(l, t, backgroundWidth, backgroundHeight)
63+ updatePath(RectF (0f , 0f , backgroundWidth.toFloat(), backgroundHeight.toFloat()))
64+ super .setBounds(l, t, l + backgroundWidth, t + backgroundHeight)
6265 }
6366
6467 override fun setBounds (r : Rect ) {
65- r.right = backgroundWidth
66- r.bottom = backgroundHeight
67- updatePath(RectF (r ))
68+ r.right = r.left + backgroundWidth
69+ r.bottom = r.top + backgroundHeight
70+ updatePath(RectF (0f , 0f , backgroundWidth.toFloat(), backgroundHeight.toFloat() ))
6871 super .setBounds(r)
6972 }
7073
7174 override fun onBoundsChange (bounds : Rect ) {
7275 if (bounds != null ) {
7376 backgroundRect = Rect ((bounds.width() - backgroundWidth) / 2 ,
74- (bounds.height() - backgroundHeight) / 2 ,
75- bounds.width() - (bounds.width() - backgroundWidth) / 2 ,
76- bounds.height() - (bounds.height() - backgroundHeight) / 2 )
77+ (bounds.height() - backgroundHeight) / 2 ,
78+ bounds.width() - (bounds.width() - backgroundWidth) / 2 ,
79+ bounds.height() - (bounds.height() - backgroundHeight) / 2 )
7780 bitmapRect = Rect ((bounds.width() - bitmapWidth) / 2 ,
78- (bounds.height() - bitmapHeight) / 2 ,
79- bounds.width() - (bounds.width() - bitmapWidth) / 2 ,
80- bounds.height() - (bounds.height() - bitmapHeight) / 2 )
81+ (bounds.height() - bitmapHeight) / 2 ,
82+ bounds.width() - (bounds.width() - bitmapWidth) / 2 ,
83+ bounds.height() - (bounds.height() - bitmapHeight) / 2 )
8184 }
8285 super .onBoundsChange(bounds)
8386 }
0 commit comments