-
Notifications
You must be signed in to change notification settings - Fork 0
Colors
Ghimpu Lucian Eduard edited this page May 25, 2022
·
3 revisions
Standalone colors are plain constants that be used anywhere.
All colors are Compose Color accessible via the EverliColors object:
@Composable
fun SomeText() {
Text(
text = "Hello",
color = EverliColors.Black100,
)
}All colors are normal resources stored in colors.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textColor="@color/black_100" />EverliColor is a utility class supposed to be used in your data layer if needed.
It can be helpful when your backend provides it in data objects.
EverliColor.fromString() -> used to handle deserialization.
EverliColor.toColor() -> used to convert to Compose Color.
EverliColor.toResourceId() -> used to convert to XML resource id.
It mainly involves following the usages mentioned above:
- First a new constant in
EverliCollors - Then a new resource in
colors.xml - Then a new enum value in
EverliColor - Finally make sure you also converted
EverliColor.toColor()andEverliColor.toResourceId()and unit tests.
Why not use colorResource(R.color.green_100) in EverliColors to use xml resource as single source of truth?
Because colorResource can only be used from a @Composable scope, limiting the usage of EverliColors