Hi folks, I'm trying to create a delegate function...
# compose
s
Hi folks, I'm trying to create a delegate function that is a
@Composable
no problem problem building it. but I'm having runtime exception:
java.lang.NoSuchMethodError: No virtual method getValue-0d7_KjU(Ljava/lang/Object;Lkotlin/reflect/KProperty;)J
Does
@Composable
support delegate property? Example:
Copy code
@Composable
public operator fun getValue(thisRef: Any?, property: KProperty<*>): Color {
    return animateColorAsState(targetValue = state).value
}
r
Good morning @SrSouza! Although I cannot say why that exception is being thrown, I was wondering where you are using this delegate. Are you calling it from within another
@Composable
? I have not seen composable functions that return values, although I at the same time don't see why they couldn't, but just curious about your use case.
s
Yes, I'm calling from inside a Compostable
z
I'm guessing this isn't possible because Kotlin has very strict requirements for how the property delegate functions look. Composable functions have some extra parameters added to them by the compiler, so when it does that for these functions they no longer match the signature required for property delegate accessors.
🥲 1
The compose compiler should probably just complain upfront if you try doing this since that error message is a little opaque. Mind filing a bug?