Skip to content

Commit

Permalink
Fix styledColorSL regression
Browse files Browse the repository at this point in the history
It wasn't handling references to color resources that have no selector.

Now it is.
  • Loading branch information
LouisCAD committed Aug 6, 2021
1 parent e0f5a8a commit 2fc30fb
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,12 @@ inline fun View.styledColor(@AttrRes attr: Int) = context.styledColor(attr)
inline fun appStyledColor(@AttrRes attr: Int) = appCtx.styledColor(attr)

fun Context.styledColorSL(@AttrRes attr: Int): ColorStateList = withResolvedThemeAttribute(attr) {
when (resourceId) {
0 -> {
require(type in TypedValue.TYPE_FIRST_COLOR_INT..TypedValue.TYPE_LAST_COLOR_INT) {
unexpectedThemeAttributeTypeErrorMessage(expectedKind = "color")
}
ColorStateList.valueOf(data)
}
else -> {
require(type == TypedValue.TYPE_STRING && string.startsWith("res/color/")) {
unexpectedThemeAttributeTypeErrorMessage(expectedKind = "color")
}
colorSL(resourceId)
}
if (type in TypedValue.TYPE_FIRST_COLOR_INT..TypedValue.TYPE_LAST_COLOR_INT) {
ColorStateList.valueOf(data)
} else if (type == TypedValue.TYPE_STRING && string.startsWith("res/color/")) {
colorSL(resourceId)
} else {
illegalArg(errorMessage = unexpectedThemeAttributeTypeErrorMessage(expectedKind = "color"))
}
}

Expand Down

0 comments on commit 2fc30fb

Please sign in to comment.