Zach Klippenstein (he/him) [MOD]
08/15/2020, 5:39 AMApplier
. Since composable functions carry no compile-time information about which “type of composition” they can be used in, it seems like it would be a real headache, in a large codebase, to try and keep functions for each different composition type separate. And the penalty for getting that wrong could only be, AFAIK, a runtime crash.
It seems like it would be very useful for composable functions to effectively include the type of composition they can be used with in their actual type. This would both serve as documentation (“ah, foo()
is a UI function, and bar()
is a function for managing a 3D scene graph”), and for the compiler to actually do type checking.
I’d be really curious to know what thoughts the Compose team has about this potential issue, and how to mitigate it.Zach Klippenstein (he/him) [MOD]
08/15/2020, 5:41 AMKClass
parameter on the @Composable
annotation that the compose compiler plugin could validate, so that a function annotated as, e.g., @Composable(UiApplier::class)
could only call other composable functions which have the UiApplier::class
annotation argument. Alias annotations could be defined well, so e.g. Compose’s UI framework could define something like @Composable(UiApplier::class) annotation class UiComposable
.Zach Klippenstein (he/him) [MOD]
08/15/2020, 5:49 AMromainguy
08/15/2020, 5:53 AMZach Klippenstein (he/him) [MOD]
08/15/2020, 5:59 AMZach Klippenstein (he/him) [MOD]
08/15/2020, 6:02 AMLeland Richardson [G]
08/15/2020, 6:30 AMLeland Richardson [G]
08/15/2020, 6:31 AMemit
is made partially to make this inferencing a little bit easierZach Klippenstein (he/him) [MOD]
08/15/2020, 6:38 AMshikasd
08/15/2020, 11:39 AMone completely separate Compose-based UI system to anotherTbh, even one compose-based UI system is not ready yet 😄 I completely agree and even imagine accidentally messing up non view related (text or vector) composables in
UiApplier
based calls. I guess the most important thing here is to design the API of such components in a way that prevents that.
On the other hand, you could imagine these things having a bit different direction with multiplatform, where Composable functions go through `expect`/`actual` substitution and end up with different Applier
types in the end.Albert Chang
08/03/2022, 1:40 AMfengdai
08/03/2022, 1:44 AMfengdai
08/03/2022, 2:28 AM@Retention(AnnotationRetention.BINARY)
@ComposableTargetMarker("V Composable")
@Target(
AnnotationTarget.FILE,
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.TYPE,
AnnotationTarget.TYPE_PARAMETER,
)
annotation class VComposable
Then marked my custom composable functions which call ComposeNode
directly with it. But build can still pass.
I even tried out mixing only UiComposable
functions with VectorComposable
functions. Also, no compile error occurred… 🤔Leland Richardson [G]
08/03/2022, 2:30 AMChuck Jazdzewski [G]
08/03/2022, 4:10 PMZach Klippenstein (he/him) [MOD]
08/03/2022, 6:54 PMfengdai
08/04/2022, 12:59 AM...
... Calling a V Composable composable function where a UI Composable composable was expected
...