mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

textColorRes and descriptionTextColorRes aren't work correctly #2744

Closed CheK539 closed 3 years ago

CheK539 commented 3 years ago

About this issue

Hi, I am trying to create a PrimaryDrawerItem with color changing textColor and desctiptionTextColor using textColorRes and desctiptionTextColorRes, but it doesn't work as I expected. Instead of changing the textColor, the selectedColor is changed. Note that changing the textColor field manually works correctly. Then I went through the source code and saw that textColorRes and descriptionTextColorRes are a SelectableColor extension instead of a NameableColor in NameableColor.kt:

var SelectableColor.textColorRes: Int
    @Deprecated(level = DeprecationLevel.ERROR, message = "Not readable")
    get() = throw UnsupportedOperationException("Please use the direct property")
    set(@ColorRes value) {
        selectedColor = ColorHolder.fromColorRes(value)
}

Sample code for this:

binding.slider.addItems(
    PrimaryDrawerItem().apply {
        nameText = "Test item"
        descriptionText = "Test description"
        textColorRes = R.color.teal_700
        descriptionTextColorRes = R.color.teal_200
    }
)

image

image

Details

Checklist

mikepenz commented 3 years ago

@CheK539 thank you very much for the detailed report. Looking into it.

davidhowe commented 2 years ago

@mikepenz FYI This issue seems to also be present for ProfileDrawerItem

mikepenz commented 2 years ago

@davidhowe it should be the same extension function. due to it not having access to the context, the res variant is no-op and it's suggested to use textColor directly