workflow-swift icon indicating copy to clipboard operation
workflow-swift copied to clipboard

[WIP] SwiftUIScreen with action sink

Open square-tomb opened this issue 2 years ago • 0 comments

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:

c7d51b623518a1bd219d302ff0f8ebb70ff4dc79: 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

2fbfc5e2e91ab316a17d178a315c156f0ca4a12d: 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.

0340049e1e80261193db11dfe2fe27782470c8f3: 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.

f039b474084fbf76c85c98f2cc9ede36e9a18b1e, 7a9164a4f3a5e37e443b1fb3b1a6c223b4dd83d6: Syntactic sugar

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

53fc65b53fc9d77a73bc532ac7dfb9ae6e41cd9a: 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 avatar Jun 22 '23 20:06 square-tomb