[WIP] SwiftUIScreen with action sink #225
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR demonstrates rewriting some Workflow-backed screens from UIKit to SwiftUI, significantly simplifying their implementations:
LoginScreen
from the TicTacToe exampleTodoEditScreen
from Tutorial 5It does so by:
Rendering
s'Screen
conformances withSwiftUIScreen
conformances.Rendering
s themselves to hold a single,Equatable
action sink rather than multiple callback functions, allowing theRendering
itself to deriveEquatable
.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 aScreen
may conform to if it wishes to provide a SwiftUIView
in lieu of aViewControllerDescription
ObservableValue
, which exposesRendering
s from theWorkflow
to the SwiftUIView
2fbfc5e: Make
LoginScreen
aSwiftUIScreen
Replaces
LoginScreen
'sScreen
conformance with aSwiftUIScreen
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 singleScreenActionSink
, allowingLoginScreen
to deriveEquatable
. The also simplifiesLoginWorkflow
and its tests a bit.f039b47, 7a9164a: Syntactic sugar
Introduces extensions on
ObservableValue
that make data bindings in theView
more concise.53fc65b: Make
TodoEditScreen
aSwiftUIScreen
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
.