I have a question about server-driven UI and Jetpack Compose. I've seen what some think are examples of server-driven UI with Compose, but really aren't (UI's not really configurable from the server, just data). So I was thinking, would it be possible to serialize Compose functions from the server, and deserialize them on an Android client? Kotlin closures are serializable, so that includes lambdas and functions. But the Compose compiler plugin needs to work its magic on that Composable function, which it can't do if it's deserializing it at runtime. Is the current way forward with server-driven UI with Compose to create a custom view engine, as current approaches use? Or is there a way to leverage Compose as the engine itself?
Leland Richardson [G]
2 years ago
I think the best answer I have to this without thinking harder about the problem is “not without a bit of work and a pretty solid understanding of the compiler and runtime”. There isn’t an out of the box way to do this right now, no.We might provide a way to invoke a composable function via reflection out of the box (right now it is in the ui-tooling module) which would help a lot for this type of thing. A more sophisticated solution of building a custom composer which serialized the results or something would be a really interesting project but I would have to think about it more