Manuel Unterhofer
11/16/2023, 10:20 AMButtonColors
, TextFieldColors
, etc.? It’ll limit user-space options nowCasey Brooks
11/16/2023, 4:02 PMButtonDefaults.buttonColors()
shikasd
11/16/2023, 5:57 PM@Composable
functions and state objects. Using a class to store those values is much better for performance, as 95% of cases can be handled by providing the color as parameter.
What's the use-case that it restricted for you?Manuel Unterhofer
11/17/2023, 7:20 AMinterface
though, with a non-@Composable
alternative to ButtonDefaults.buttonColors()
, couldn’t it? That should yield the same performance?
I’m currently designing a custom theme system and we’re trying to decide between the interface
and class
approach for us. The scenario we have in mind would be to set up custom animated transitions between the colors for arbitrary states or even to add additional states on any Interaction
which are more complex than what `Indication`s can offer. For example, changing the border color on hover. For that purpose, we’d be passing an InteractionSource
into all color state factories, like it is already done in most of TextFieldColors
, even if not used by default.
With a class, this option isn’t there anymore.shikasd
11/17/2023, 12:17 PMManuel Unterhofer
11/17/2023, 12:19 PMinterface
as wellshikasd
11/17/2023, 12:22 PMManuel Unterhofer
11/17/2023, 12:23 PMshikasd
11/17/2023, 12:28 PMManuel Unterhofer
11/17/2023, 12:29 PMshikasd
11/17/2023, 12:33 PMButtonColors
, as Material already handles many interactions internally. I assume that you are not really interested in some material aspects, so for you it might be easier to just customize Surface
+ text or even Box
+ text.
Ideally, you'd avoid creating and memoizing intermediate states and just have state for color that is later used to invalidate draw passManuel Unterhofer
11/17/2023, 1:15 PMyou collect and update interactions at composition time, while creating extra states.I’m trying to understand this all the way. Am I right that the actual issue is that the color state will be read during composition, while passing it to the corresponding modifier as a parameter? Because setting up some state on initial composition is the only way to do that, isn’t it? And such a problem could be avoided with a draw modifier that takes a lambda for determining its inputs, including the color?
shikasd
11/17/2023, 1:18 PMdrawRect
in a draw modifier instead of invalidating composition with modifier background
. If you are switching between discrete values, it should be fine though.Manuel Unterhofer
11/17/2023, 1:31 PM