Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Compose overhaul makes ViewEnvironment less in your face. #1207

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented Jun 25, 2024

  • Introduces LocalWorkflowEnvironment and eliminates explicit ViewEnvironment parameters from ScreenComposableFactory.Content, ComposeScreen.Content, etc. It is put in place automatically by the default implementation of ScreenComposableFactoryFinder.

  • Adds optional CompositionRoot argument to ViewEnvironment.withComposeInteropSupport(). CompositionRoot is our existing hook to ensure CompositionLocals (e.g. for UI themes) are put in play above the @Composable Content() function invoked for any Screen.

  • Replaces ViewEnvironment.withCompositionRoot with @Composable fun ViewEnvironment.RootScreen, as our preferred Compose-friendly alternative to WorkflowLayout

An Activity that uses setContent {} instead of setContentView() can now kick things off like so:

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val environment : ViewEnvironment = ViewEnvironment.EMPTY +
      // ...
      .withComposeInteropSupport()

    val rootScreen by RootWorkflow.renderAsState(
      props = Unit,
      onOutput = {},
    )

    setContent {
      environment.RootScreen(rootScreen)
    }
  }

@rjrjr rjrjr force-pushed the ray/compose-local-view-env branch from 605b33b to 6f57480 Compare June 25, 2024 21:30
@rjrjr rjrjr changed the title BREAKING: Introduces LocalWorkflowEnvironment BREAKING: Compose overhaul makes ViewEnvironment less in your face. Jun 25, 2024
@rjrjr rjrjr force-pushed the ray/compose-local-view-env branch 2 times, most recently from b3f43e1 to 059b5e7 Compare June 25, 2024 21:35
@rjrjr rjrjr marked this pull request as ready for review June 28, 2024 15:32
@rjrjr rjrjr requested review from a team as code owners June 28, 2024 15:32
Copy link
Contributor

@ekeitho ekeitho left a comment

Choose a reason for hiding this comment

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

really awesome stuff!

Copy link
Collaborator

@wardellbagby wardellbagby left a comment

Choose a reason for hiding this comment

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

Everything tracks and makes sense to me at a high-level but I'm realizing that I need to take more of a deep-dive into the Workflow Compose integration. I've been taking it for granted.

@rjrjr
Copy link
Contributor Author

rjrjr commented Jun 28, 2024

Everything tracks and makes sense to me at a high-level but I'm realizing that I need to take more of a deep-dive into the Workflow Compose integration. I've been taking it for granted.

@wardellbagby I've kept this README up to date.

* Introduces `LocalWorkflowEnvironment` and eliminates explicit `ViewEnvironment` parameters from `ScreenComposableFactory.Content`, `ComposeScreen.Content`, etc. It is put in place automatically by the default implementation of `ScreenComposableFactoryFinder`.

* Adds optional `CompositionRoot` argument to `ViewEnvironment.withComposeInteropSupport()`. `CompositionRoot` is our existing hook to ensure `CompositionLocal`s (e.g. for UI themes) are put in play above the `@Composable Content()` function invoked for any `Screen`.

* Replaces `ViewEnvironment.withCompositionRoot` with `@Composable fun ViewEnvironment.RootScreen`, as our preferred Compose-friendly alternative to `WorkflowLayout`

An `Activity` that uses `setContent {}` instead of `setContentView()` can now kick things off like so:

```kotlin
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val environment : ViewEnvironment = ViewEnvironment.EMPTY +
      // ...
      .withComposeInteropSupport()

    val rootScreen by RootWorkflow.renderAsState(
      props = Unit,
      onOutput = {},
    )

    setContent {
      environment.RootScreen(rootScreen)
    }
  }
```
@rjrjr
Copy link
Contributor Author

rjrjr commented Jun 28, 2024

@RBusarow any guesses as to why the checks aren't running on this PR?

@rjrjr rjrjr closed this Jun 28, 2024
@rjrjr rjrjr reopened this Jun 28, 2024
@rjrjr
Copy link
Contributor Author

rjrjr commented Jun 28, 2024

@RBusarow any guesses as to why the checks aren't running on this PR?

Maybe lingering effects from the earlier outage. Closed and opened to try again.

@rjrjr rjrjr merged commit e34149f into main Jun 28, 2024
31 of 32 checks passed
@rjrjr rjrjr deleted the ray/compose-local-view-env branch June 28, 2024 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants