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

[WIP] SwiftUIScreen with action sink #225

Closed
wants to merge 9 commits into from
Closed

Conversation

square-tomb
Copy link
Contributor

@square-tomb square-tomb commented Jun 22, 2023

This PR demonstrates rewriting some Workflow-backed screens from UIKit to SwiftUI, significantly simplifying their implementations:

  • LoginScreen from the TicTacToe example
  • TodoEditScreen from Tutorial 5

It does so by:

  1. Following the approach described in the Binding SwiftUI Views to Workflow Renderings design doc, replacing the Renderings' Screen conformances with SwiftUIScreen conformances.
  2. Altering the Renderings themselves to hold a single, Equatable action sink rather than multiple callback functions, allowing the Rendering itself to derive Equatable.

Commits

The PR is designed to be read commit-by-commit:

c7d51b6: Introduce WorkflowSwiftUI types

Pastes in some types from previous Workflow SwiftUI experiments, nearly unchanged, that are discussed in the Binding SwiftUI Views to Workflow Renderings design doc. Most importantly:

  • SwiftUIScreen, the protocol that a Screen may conform to if it wishes to provide a SwiftUI View in lieu of a ViewControllerDescription
  • ObservableValue, which exposes Renderings from the Workflow to the SwiftUI View

2fbfc5e: Make LoginScreen a SwiftUIScreen

Replaces LoginScreen's Screen conformance with a SwiftUIScreen conformance. This already simplifies the implementation significantly, but the next few commits simplify it further.

0340049: Replace callbacks with action sink

Replaces the callback functions in LoginScreen with a single ScreenActionSink, allowing LoginScreen to derive Equatable. The also simplifies LoginWorkflow and its tests a bit.

f039b47, 7a9164a: Syntactic sugar

Introduces extensions on ObservableValue that make data bindings in the View more concise.

53fc65b: Make TodoEditScreen a SwiftUIScreen

Rewrite another screen to SwiftUI, taking advantage again of all types and extensions described above.

Further reading

#228 adds additional syntactic sugar for exposing two-way bindings to properties on the State.

@square-tomb square-tomb force-pushed the tomb/swiftui-2023 branch 2 times, most recently from f2bf603 to c26ca84 Compare June 22, 2023 21:19
@square-tomb square-tomb changed the title [WIP] 2023 SwiftUI experiments 2023 SwiftUI experiments Jun 22, 2023
@square-tomb square-tomb force-pushed the tomb/swiftui-2023 branch 3 times, most recently from d348077 to 3039076 Compare June 22, 2023 22:21
@square-tomb square-tomb changed the title 2023 SwiftUI experiments [WIP] SwiftUIScreen with action sink Jun 23, 2023
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.

1 participant