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

Abstract ViewEnvironment to shared framework #185

Merged
merged 7 commits into from
Feb 2, 2023

Conversation

n8chur
Copy link
Collaborator

@n8chur n8chur commented Jan 31, 2023

Overview

Environment value objects and corresponding propagation systems have become a useful tool in application architecture. Implementations of this tool can be found in SwiftUI, Blueprint, WorkflowUI, and the Market Design System's MarketEnvironment/MarketEnvironmentUI.

In building out Market, we've found that there is great utility in consolidating these environments, particularly when their conceptual domain for propagation directly overlaps. Workflow's ViewEnvironment and Market's MarketEnvironment is a great example of this—both define an environment value bucket which is propagated through UIViewController hierarchies.

Needing to manage two types that attempt to solve an extremely similar goal leads to a few ares of complexity:

Bridging

Bridging between the two propagation systems is more tedious than it need be since we're forced to acknowledge all properties we would like to bridge from one environment to the other at their boundaries (e.g. a vanilla UIViewController hierarchy that uses an environment propagation system which contains a child WorkflowHostingController that needs that environment information for theming).

It'd be much more convenient if we could just pass the entire environment along and avoid the need to build protocol abstractions over their shared API.

We could even eventually provide official support for automatically bridging between UIViewController and Workflow propagation of the environment within WorkflowUI (e.g. in WorkflowHostingController or a similar type), which would reduce a huge pain point and common mistake found in the ios-register codebase.

Generics

We use protocols to abstract similar concepts which are shared amongst our environments (e.g. the presence of a theme property, the ability to resolve a modal presentation style from an Environment, etc.). This leads to the use of generics upstream of these APIs, which adds unnecessary clutter when building features which intersect with these concerns.

There is a particular use-case with our Modals framework which would be drastically simplified and cleaned up if we could share an environment type for all use cases which a Modal presentation style could be resolved.

Code duplication

We currently duplicate all of our ViewEnvironment key conformances and extensions for use in MarketEnvironment. It'd be nice not to have to maintain both.

Why is abstracting ViewEnvironment to a separate framework important? Why not just import WorkflowUI and use it where this reuse would be convenient?

While Workflow/WorkflowUI is a fairly lightweight framework, we've had requests not to depend on all of Workflow/WorkflowUI in some contexts. We'd prefer the reliance on a dependency like Workflow/WorkflowUI not to be the blocking factor in adopting the Market design system. This abstracted ViewEnvironment framework will completely replace our existing MarketEnvironment framework, so binary size etc. should not be increased as a result of this change in those use cases.

Should we consider pulling ViewEnvironment out into a separate repository?

Probably! Just pulling this dependency out in Workflow was the easiest way to achieve our immediate needs for simplification so we decided to start here, but there may be utility in sharing ViewEnvironment in other contexts.

Checklist

  • Unit Tests
  • UI Tests
  • Snapshot Tests (iOS only)
  • I have made corresponding changes to the documentation

@@ -15,6 +15,7 @@ Pod::Spec.new do |s|
s.dependency 'WorkflowRxSwift'
# s.dependency 'WorkflowCombine' # TODO: Disabled because app specs cannot increase the deployment target of the root
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated, but I bet we can turn these on globally now cc @jamieQ

Copy link
Collaborator Author

@n8chur n8chur Jan 31, 2023

Choose a reason for hiding this comment

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

I don't believe we can if this is to work around a bug in pod gen unless we're bumping all podspecs to iOS 13.

The project attempts to generate with an iOS 11 deployment target and fails to resolve all targets as a result (since these commented ones require iOS 14). I just reported the bug in #cocoapods here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I figured we could bump stuff in the whole repo to 14 as well. Anyway, not important for this PR!

Copy link
Collaborator Author

@n8chur n8chur Jan 31, 2023

Choose a reason for hiding this comment

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

I'd expect that you'd be able generate a project with pod gen which ends up just using the highest deployment target found in your development podspecs, but it doesn't appear to work this way (it's either an order thing or choosing the lowest version I think).

Copy link
Contributor

Choose a reason for hiding this comment

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

looking into bumping the versions here. can do that after this is merged though & will update the values in the new podspec.

@@ -0,0 +1,22 @@
require_relative('version')

Pod::Spec.new do |s|
Copy link
Contributor

Choose a reason for hiding this comment

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

Any tests to move too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't see any but I thought about adding a simple .empty initialization test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not necessary here, but there is logical surface area to cover in the subscript and setting methods.

@n8chur
Copy link
Collaborator Author

n8chur commented Jan 31, 2023

I didn't realize a draft would tag folks for review—I'll be updating this PR with a description of what and why this change is desirable and open it for full review soon!

The TL;DR Is that we'd get some pretty huge benefit from being able to share the ViewEnvironment type in our vanilla, Workflow-less UIViewController propagation system we use to propagate theming information outside of Workflow in Market.

@@ -0,0 +1,22 @@
require_relative('version')

Pod::Spec.new do |s|
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not necessary here, but there is logical surface area to cover in the subscript and setting methods.

@@ -0,0 +1 @@
@_exported import ViewEnvironment
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a compatibility gesture, right? Assuming that Foo refers to the same module, can two modules call export Foo without conflict?

My hunch is that it's fine, and that there's probably a lot of @_exported Foundation lurking around, for example, but I figured it worth asking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a compatibility gesture, right?

Yup!

can two modules call export Foo without conflict?

I believe so

@n8chur n8chur changed the title [WIP][DNR][DNM] Abstract ViewEnvironment to shared framework Abstract ViewEnvironment to shared framework Feb 1, 2023
@n8chur n8chur marked this pull request as ready for review February 1, 2023 23:54
@n8chur n8chur requested a review from a team as a code owner February 1, 2023 23:54
# 1.7 is needed for `swift_versions` support
s.cocoapods_version = '>= 1.7.0'

s.swift_versions = ['5.0']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: move these things into version.rb ?

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 reasonable to me—but I'm going to leave it as for this PR to avoid conflating that change here.

RELEASING.md Outdated
@@ -47,6 +47,7 @@ For Squares, membership is managed through the `Workflow Swift Owners` registry
bundle exec pod trunk push WorkflowSwiftUI.podspec --synchronous
bundle exec pod trunk push WorkflowCombine.podspec --synchronous
bundle exec pod trunk push WorkflowCombineTesting.podspec --synchronous
bundle exec pod trunk push ViewEnvironment.podspec --synchronous
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are ordered by dependency — you'll have to push this one first (or at least before WorkflowUI).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, done!

@@ -15,6 +15,7 @@ Pod::Spec.new do |s|
s.dependency 'WorkflowRxSwift'
# s.dependency 'WorkflowCombine' # TODO: Disabled because app specs cannot increase the deployment target of the root
Copy link
Contributor

Choose a reason for hiding this comment

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

looking into bumping the versions here. can do that after this is merged though & will update the values in the new podspec.

@n8chur n8chur enabled auto-merge (squash) February 2, 2023 20:53
@n8chur n8chur disabled auto-merge February 2, 2023 20:53
@n8chur n8chur enabled auto-merge (squash) February 2, 2023 20:53
@n8chur n8chur merged commit f924e81 into main Feb 2, 2023
@n8chur n8chur deleted the westin/abstract-view-environment branch February 2, 2023 20:58
jamieQ added a commit that referenced this pull request Feb 6, 2023
* main:
  [fix]: use weak reference to internal sinks when vending to clients (#189)
  [feat]: add primary associated types to more protocols (#188)
  [chore]: pre major version bump cleanup (#187)
  [chore]: bump minimum deployment & swift versions (#186)
  Abstract ViewEnvironment to shared framework (#185)
  Bump activesupport from 6.1.4.4 to 6.1.7.1 (#183)
  [feat]: add primary associated types to `Workflow` protocol (#181)
  [chore]: update swiftformat ifdef indent rule to no-indent (#182)
jamieQ added a commit that referenced this pull request Feb 25, 2023
…ow-workflow-conformance

* origin/main:
  Expose AnyScreen.wrappedScreen for inspection (#193)
  Improve introspection for SignalProducerWorkflow actions (#192)
  [release]: bump version to 2.2.0 & remove separate concurrency version (#191)
  [feat]: add runtime observation API (#168)
  [chore]: refactor some internal actions to use existential any (#190)
  [fix]: use weak reference to internal sinks when vending to clients (#189)
  [feat]: add primary associated types to more protocols (#188)
  [chore]: pre major version bump cleanup (#187)
  [chore]: bump minimum deployment & swift versions (#186)
  Abstract ViewEnvironment to shared framework (#185)
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