Proposal: FlowRepresentableView #123
Replies: 3 comments 12 replies
-
I like the aesthetic of this approach more than our current one, but I don't know if the gains are worth some of these disadvantages:
|
Beta Was this translation helpful? Give feedback.
-
I'm not in love with it, but maybe that will change as I ask some questions.
As I continue to process what it is really doing, I start to wonder how this makes your entire view behave with interacting with SwiftCurrent. It really seems like it is the thing that allows you to call proceed and backup and tell the workflow to abandon... which would incline me to sometimes only declare it at the point of use, and other times somewhere in the middle, but really they have to wrap everything in this and then when you want to call proceed, you need to call So to visualize what I'm thinking this ends up being for consumers is: struct FR1: View {
var body: some View {
FlowRepresentableView(output: String.self) { proxy in
Button("Proceed in workflow") { proxy.proceedInWorkflow("Take me forward") }
}
}
}
struct FR2: View {
var body: some View {
FlowRepresentableView<String, Never> { proxy in
Text(proxy.passedArguments)
Button("Proceed in workflow") { proxy.proceedInWorkflow() }
}
}
}
struct Content: View {
var body: some View {
WorkflowLauncher(isLaunched: .constant(true)) {
thenProceed(with: FR1.self) {
thenProceed(with: FR2.self)
}
}
}
} And that's the required path to compile, not what I wanted to do while writing FR1/FR2. |
Beta Was this translation helpful? Give feedback.
-
Things have changed and it makes this conversation worth revisiting. We no longer have compile-time safety on SwiftUI because the compiler simply couldn't handle it (see #112 for more info). Because of that my "second" proposed option is the only valid one anymore. @wwt/workflow-developers With that additional context, how do you feel about this proposal? |
Beta Was this translation helpful? Give feedback.
-
Motivation
I've been toying with this idea for about a month now and am finally ready to put it down on paper and let the discussions happen. I dislike that consumers in SwiftUI have to declare
weak var _workflowPointer: AnyFlowRepresentable?
so that we can tie into the workflow lifecycle. It's true we need space on a struct to be able to give access to theworkflow
property and to makeproceedInWorkflow
function, but it doesn't necessarily have to be on our consumer's view struct.Ultimately the motivation is to get rid of the need for consumers to have to declare that variable.
The FlowRepresentableView
I propose the creation of a
FlowRepresentableView
that exposes aworkflow
property and aproceedInWorkflow
closure. This would act almost exactly likeScrollViewReader
, orGeometryReader
. I could be convinced the name needs to beFlowRepresentableReader
orWorkflowReader
just to really drive the point home. Consumers would be able to specify their input and output types, receive arguments, and proceed in their workflows.With no input or output
With Input of String
With Input of String, Output of Int
Important
If the view body erases the type like the examples above we lose safety on
thenProceed
calls completely. We've already got a discussion that might make that true. If we want to take this proposal but keep all type safety onthenProceed
it'd need to look like this:The drawback here is that
FlowRepresentableView
must be the first thing declared in your body. This is perhaps less invasive than a_workflowPointer
on your struct.Advantages
WorkflowLauncher
can act exactly likeScrollViewReader
when it is not embedded in aScrollView
.FlowRepresentableView
for the relevant parts of your view, not all of it.Disadvantages
@State
variable with some default value (nil, for example).shouldLoad
is not clear.FlowRepresentableView
comes the downside of losing compiler safety and having to change our ideas of whatthenProceed
does.FlowRepresentableView
you're pigeonholing consumers in regards to how they create their views.Beta Was this translation helpful? Give feedback.
All reactions