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

Make ViewFactory.showRendering function responsible for applying the ComposeViewFactoryRoot. #24

Merged
merged 1 commit into from
May 18, 2020

Conversation

zach-klippenstein
Copy link
Collaborator

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

This ensures that the root will be applied in all code paths:

  • Entering the Compose world through a WorkflowViewStub/ComposeViewFactory.
  • Already in Compose, showing a rendering from a WorkflowContainer.

This change also ensures that if the ComposeViewFactoryRoot is changed above where it's applied,
the new wrapper will be applied. Adds tests for this and other logic.

Fixes #20.

@zach-klippenstein zach-klippenstein requested a review from rjrjr May 16, 2020 00:51
viewEnvironment: ViewEnvironment,
content: @Composable() () -> Unit
) {
if (HasViewFactoryRootBeenApplied.current) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm missing where this gets set to true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great question, I'll add a comment to the source. It gets "set" to true on line 79 below. This function can appear multiple times, at multiple nesting levels, inside the composition. The ambient has a default value of false, which means if this function is the top-most one in its subtree, it will read the value as false and drop down to the else case. That case will wrap the child Composable with this ambient providing the value true, so any nested occurrences of this function below this point will see that true value and not re-apply the wrapper.

Copy link
Contributor

Choose a reason for hiding this comment

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

God, it was staring me right in the face.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's weird to look at if you're not thinking about recursion. I added a bunch of comments that I hope should clear this up.

Copy link
Contributor

@rjrjr rjrjr left a comment

Choose a reason for hiding this comment

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

I'm just blown away by how testable all this is.

@zach-klippenstein zach-klippenstein changed the base branch from zachklipp/cleanup-packages to master May 18, 2020 19:22
@zach-klippenstein
Copy link
Collaborator Author

I have barely scratched the surface. I've never thought about writing unit tests for UI, but it's so easy. Just wish I could run them without an emulator (might be possible? haven't tried).

@zach-klippenstein
Copy link
Collaborator Author

I don't really like that this root thing requires custom logic in the internals. I have an idea for decoupling these pieces in another branch, but it needs some more work.

…ComposeViewFactoryRoot.

This ensures that the root will be applied in all code paths:
 - Entering the Compose world through a `WorkflowViewStub`/`ComposeViewFactory`.
 - Already in Compose, showing a rendering from a `WorkflowContainer`.

This change also ensures that if the `ComposeViewFactoryRoot` is changed above where it's applied,
the new wrapper will be applied. Adds tests for this and other logic.

Fixes #20.
@@ -97,7 +97,7 @@ jobs:
name: Instrumentation tests
needs: assemble
runs-on: macos-latest
timeout-minutes: 20
timeout-minutes: 30
Copy link
Collaborator Author

@zach-klippenstein zach-klippenstein May 18, 2020

Choose a reason for hiding this comment

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

This PR adds a bunch of UI tests, so we need to increase the CI timeout a bit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Better fix coming in #30.

@zach-klippenstein zach-klippenstein merged commit a58aafe into master May 18, 2020
@zach-klippenstein zach-klippenstein deleted the zachklipp/better-root branch May 18, 2020 23:14
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.

Add tests in core-compose for subcomposition and ComposeViewFactoryRoot
2 participants