material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.27k stars 3.06k forks source link

[BottomNavigation] Disable item view clipping #1107

Open jarrodrobins opened 4 years ago

jarrodrobins commented 4 years ago

Is your feature request related to a problem? Please describe. Currently, item icons are clipped to 24dp x 24dp. I'd like the flexibility to override this to allow for wider icons.

While it is possible to change the overall size of the icons using itemIconSize, this is not ideal as it will scale smaller image assets up to fit that size - ie, it's not a maximum size, it's the actual size.

Currently, my working solution is to iterate through all the bottom bar item views, disable clipping for children, and changing the scale type to CENTER (I'm guessing the default is FIT_XY?).

        val menuView = bottomNavigation.getChildAt(0) as BottomNavigationMenuView
        for (i in 0 until menuView.childCount) {
            val itemView = menuView.getChildAt(i) as FrameLayout
            val iconView = itemView
                .findViewById<AppCompatImageView>(com.google.android.material.R.id.icon)
            itemView.clipChildren = false
            iconView.scaleType = ImageView.ScaleType.CENTER
        }

This allows me to have a wider icon than 24dp without getting clipped.

Describe the solution you'd like Because I'm really doing two things here, I think it makes sense to expose these two methods on BottomNavigationView via exposing BottomNavigationItemView's clipChildren and the icon view's scaleType. This could be via BottomNavigationView methods -

itemClipChildren and itemIconScaleType

mirroring similar naming of eg itemIconTint and itemTextColor

Describe alternatives you've considered This could be condensed down to one method but that would reduce flexibility that others may need outside my particular use case.

Additional context image

Notice the sport icon here - it's a little wider than the other icons.

If you like the idea, I'm happy to write the pull request myself but wanted to raise it in case other ideas are suggested or changes requested.

pelingcinar commented 3 years ago

++

luangs7 commented 2 years ago

nothing yet?

khsuzan commented 12 months ago

not even now

nothing yet?