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

Inline WorkflowViewStub logic in ViewFactory.showRendering to avoid unnecessary intermediate Views. #29

Merged
merged 1 commit into from
May 19, 2020

Conversation

zach-klippenstein
Copy link
Collaborator

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

This is effectively the logic of WorkflowViewStub, but translated into Compose idioms. This approach has a few advantages:

  • Avoids extra custom views required to host WorkflowViewStub inside a Composition. Its trick
    of replacing itself in its parent doesn't play nice with Compose.
  • Allows us to pass the correct parent view for inflation (the root of the composition).
  • Avoids WorkflowViewStub having to do its own lookup to find the correct [ViewFactory], since
    we already have the correct one.

Like WorkflowViewStub, this function uses the ViewFactory to create and memoize a View to
display the rendering, keeps it updated with the latest RenderingT and ViewEnvironment, and
adds it to the composition.

@zach-klippenstein zach-klippenstein requested a review from rjrjr May 18, 2020 19:17
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/inline-viewstub branch from c93cda7 to 92dfd83 Compare May 18, 2020 19:18
// Somewhere above us in the workflow rendering tree, there's another bindCompose factory.
// We need to link to its composition reference so we inherit its ambients.
setContent(recomposer, compositionReference, content)
setContent(Recomposer.current(), parentComposition, content)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Everything is just using the main thread Recomposer, no need to pass it around ourselves.

Comment on lines +126 to +128
FrameManager.framed {
renderState.value = Pair(rendering, environment)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems more idiomatic to wrap the update itself in a framed, the Compose code does this internally a bunch.

@zach-klippenstein zach-klippenstein force-pushed the zachklipp/inline-viewstub branch 2 times, most recently from ea6b394 to fd59782 Compare May 18, 2020 19:34
@zach-klippenstein zach-klippenstein changed the base branch from weekend-features to zachklipp/better-root May 18, 2020 19:35
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/inline-viewstub branch from fd59782 to bf2a993 Compare May 18, 2020 22:54
@zach-klippenstein zach-klippenstein changed the base branch from zachklipp/better-root to master May 18, 2020 23:12
@zach-klippenstein zach-klippenstein changed the title [DNM] Inline WorkflowViewStub logic in ViewFactory.showRendering to avoid unnecessary intermediate Views. Inline WorkflowViewStub logic in ViewFactory.showRendering to avoid unnecessary intermediate Views. May 18, 2020
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/inline-viewstub branch 2 times, most recently from 0a41c35 to ecb5dee Compare May 18, 2020 23:13
…nnecessary intermediate Views.

This is effectively the logic of `WorkflowViewStub`, but translated into Compose idioms.
This approach has a few advantages:

 - Avoids extra custom views required to host `WorkflowViewStub` inside a Composition. Its trick
   of replacing itself in its parent doesn't play nice with Compose.
 - Allows us to pass the correct parent view for inflation (the root of the composition).
 - Avoids `WorkflowViewStub` having to do its own lookup to find the correct [ViewFactory], since
   we already have the correct one.

Like `WorkflowViewStub`, this function uses the `ViewFactory` to create and memoize a `View` to
display the rendering, keeps it updated with the latest `RenderingT` and `ViewEnvironment`, and
adds it to the composition.
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/inline-viewstub branch from ecb5dee to da4527c Compare May 19, 2020 23:23
@zach-klippenstein
Copy link
Collaborator Author

UI test for nested renderings was failing on SDK 24 device because the ordering of the semantics nodes returned by findAllByText was different, so the wrong Reset button was getting clicked. This order was never guaranteed anyway, so I made the test more deterministic.

@zach-klippenstein zach-klippenstein merged commit dc194c3 into master May 19, 2020
@zach-klippenstein zach-klippenstein deleted the zachklipp/inline-viewstub branch May 19, 2020 23:41
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.

2 participants