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

Desktop: Introduce UI dependency #406

Closed
wants to merge 1 commit into from
Closed

Conversation

ashdavies
Copy link
Contributor

@ashdavies ashdavies commented Jan 21, 2023

Part of using navigation on desktop requires NavDecoration, which has a dependency on compose.ui Modifier. This could also be achieved with another two mechanisms:

  1. Removing Modifier as an argument for DecoratedContent
  2. Providing expect/actuals for Modifier

However, since Modifier is such a fundamental part of Compose UI, I thought it may indeed make sense to introduce it as a core dependency. I would be happy for input.

The changes here also adjust runtime.saveable as an implementation dependency since it's not required as an API dependency, this was just a single line change, but I'd be happy to extract it to a new PR if desired.

@ZacSweers
Copy link
Collaborator

Superseded by #422, but interested in pursuing the navigablecircuitcontent work in a new PR once that's in!

@ZacSweers ZacSweers closed this Feb 1, 2023
ZacSweers added a commit that referenced this pull request Feb 2, 2023
This is a breaking API change to `Ui.Content()` to add a `Modifier`
parameter. There are breaking changes, but if using code gen it's fairly
minimal.

```diff
public interface Ui<UiState : CircuitUiState> {
-  @composable public fun Content(state: UiState)
+  @composable public fun Content(state: UiState, modifier: Modifier)
}
```

We've been getting stuck on this for awhile now when trying to bridge to
UI land and finally pulling the trigger on this to ease a bunch of
things.

At a high level, this replaces the toe-hold `ScreenUi` we've been
keeping around as modifiers give us a means of plumbing down extra UI
metadata, so I've removed it from the API.

We can also offer a default onUnavailableContent API now, so I've made
it non-nullable in `CircuitConfig` using that default. If people want
the previous erroring behavior, they can still achieve this with a
custom function of their own.

One place this hits friction is UI libraries that don't use Modifiers
(i.e. Mosaic), but it's easy enough to just ignore that parameter coming
from `ui { state, _ -> ... }`.

Other things
- Realized our code gen artifact was sorta halfway multiplatform and
resulted in confusing KSP configuration errors. Cleaned that up and made
it just a standard JVM artifact.
- Reworked how we generate UI factories a bit in code gen to make it
simpler to maintain. Put a thorough diagram in for good measure.
- Removed redundant wrapper `Box`es that were shims for this
functionality missing.
- It's not possible in abstract composable functions to add a default
value. i.e. can't write `modifier: Modifier = Modifier` in the
`Ui.Content(...)` signature.

This does _add_ the compose UI dependency to circuit core, but after a
lot of thought I think this is ok. Our android artifact already imposed
it for all intents and purposes, this just drops that facade and
embraces the fact that this is a UI architecture and not just a business
logic layer using compose runtime only.

Supersedes #406.
Helps #50 too.
Eases state sharing via modifiers. It would be easy to build modifiers
that build upon each other with this and we no longer have a missing UI
link.
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.

2 participants