Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Conversation

@zach-klippenstein
Copy link
Collaborator

@zach-klippenstein zach-klippenstein commented May 12, 2020

This is the Compose analog to WorkflowViewStub, and delegates to
WorkflowViewStub except when the child ViewFactory was also created
with bindCompose. In that case, it just invokes that factory's
Composable function directly to avoid jumping back out into legacy
View land.

The API is really simple:

data class CardRendering(val content: Any)

val CardRenderingFactory = bindCompose<CardRendering> { rendering, env ->
  Card(modifier = Modifier.padding(8.dp)) {
    env.showRendering(rendering.content)
  }
}

Includes a sample that demonstrates drawing recursive composable bindings:
image

@zach-klippenstein zach-klippenstein force-pushed the zachklipp/compose-nesting branch 4 times, most recently from 94f16de to 7b16503 Compare May 12, 2020 22:06
*
* See [this slack message](https://kotlinlang.slack.com/archives/CJLTWPH7S/p1576264533012000?thread_ts=1576262311.008800&cid=CJLTWPH7S).
*/
private class ComposableViewStubWrapper(context: Context) : FrameLayout(context) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Might be a simpler way to do this using a WVS directly with a Ref, so we could get rid of this class altogether. Will probably explore as a follow up though, right now hosting legacy views in Composables is not fully supported by compose anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this, didn't work. I think it has something to do with LayoutParams not getting set correctly.

@zach-klippenstein zach-klippenstein force-pushed the zachklipp/compose-nesting branch from 7b16503 to 62ce98e Compare May 13, 2020 02:30
@zach-klippenstein
Copy link
Collaborator Author

Made the sample demonstrate dipping back into legacy views as well, and fixed a layout issue with legacy views.

Comment on lines +61 to +70
* Workflows can render other workflows, and renderings from one workflow can contain renderings
* from other workflows. These renderings may all be bound to their own [ViewFactory]s. Regular
* [ViewFactory]s and `LayoutRunner`s use
* [WorkflowViewStub][com.squareup.workflow.ui.WorkflowViewStub] to recursively show nested
* renderings using the [ViewRegistry][com.squareup.workflow.ui.ViewRegistry].
*
* View factories defined using this function may also show nested renderings. Doing so is as simple
* as calling [ViewEnvironment.showRendering] and passing in the nested rendering. See the kdoc on
* that function for an example.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rjrjr How's this?

This is the Compose analog to `WorkflowViewStub`, and delegates to
`WorkflowViewStub` except when the child `ViewFactory` was also created
with `bindCompose`. In that case, it just invokes that factory's
Composable function directly to avoid jumping back out into legacy
View land.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants